Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCR tutorial using Forte Ontologies to store data #877

Merged
merged 36 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
869ac91
ocr notebook
hepengfe Jul 12, 2022
c207c3c
ocr included in sphinx
hepengfe Jul 13, 2022
fc357b7
change box api
hepengfe Jul 14, 2022
e66c561
pylint
hepengfe Jul 14, 2022
9d16f85
adapt bounding box inheritance of box
hepengfe Jul 14, 2022
fa402e9
change bounding box init method as well
hepengfe Jul 14, 2022
399375e
rewrite bounding box init method and make it clean
hepengfe Jul 14, 2022
d9f5526
add compute_iou method
hepengfe Jul 14, 2022
5971292
remove old compute_iou method
hepengfe Jul 14, 2022
708b004
correct return typing
hepengfe Jul 14, 2022
0d97747
Merge branch 'box_init' into ocr_showcase_3
hepengfe Jul 14, 2022
39bf42a
rewrite ImageAnnotation.image and image shape functions
hepengfe Jul 14, 2022
7e03a7d
add character dataclass
hepengfe Jul 14, 2022
f2ff9bb
edited ocr notebook
hepengfe Jul 14, 2022
35c1ca5
add temporary pylint disable for ImageAnnotation height and width att…
hepengfe Jul 14, 2022
02154ab
remove unused code
hepengfe Jul 14, 2022
c10630f
disable pylint check on attributes
hepengfe Jul 14, 2022
e3a61c1
correct docstring and simplify box_min/max_x/y logitc
hepengfe Jul 15, 2022
e1c8393
add docstring for BoundingBox.init_from_center_n_shape
hepengfe Jul 15, 2022
0bec826
Merge branch 'box_init' into ocr_showcase_3
hepengfe Jul 15, 2022
2d13b0b
made changes based on the code review
hepengfe Jul 15, 2022
b6ce8a1
Merge branch 'box_init' into ocr_showcase_3
hepengfe Jul 18, 2022
978106e
add processor for token and recognize all bounding boxes for a single…
hepengfe Jul 18, 2022
dbac2f2
Merge branch 'master' into ocr_showcase_3
hepengfe Jul 18, 2022
302ba9d
Merge branch 'master' into box_init
hepengfe Jul 18, 2022
8580c16
add spelling: tokenizes
hepengfe Jul 18, 2022
8ab7562
remove useless code
hepengfe Jul 18, 2022
f041f23
remove bounding box
hepengfe Jul 18, 2022
310360e
BoundingBox -> Box for all files
hepengfe Jul 19, 2022
0c9e9d9
remove duplicated import
hepengfe Jul 19, 2022
efe4a78
improve box docstring
hepengfe Jul 19, 2022
6316d8a
Merge branch 'master' into box_init
hepengfe Jul 19, 2022
758d833
merge from box_init
hepengfe Jul 19, 2022
4208693
Merge branch 'master' into ocr_showcase_3
mylibrar Jul 19, 2022
1846960
remove black format in ft/onto/base_ontology.py
hepengfe Jul 21, 2022
ad469d6
add docstring and make minor edit based on code review
hepengfe Jul 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/ch9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Chapter 9. Tasks on Other modalities
toc/audio_processing.md

toc/image_processing.md
notebook_tutorial/ocr.ipynb
438 changes: 438 additions & 0 deletions docs/notebook_tutorial/ocr.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,4 @@ GroupType
PathLike
ElementType
customizable
tokenizes
27 changes: 24 additions & 3 deletions forte/data/ontology/top.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,15 +878,36 @@ def image(self):
"Cannot get image because image annotation is not "
"attached to any data pack."
)
return self.pack.get_image_array(self._image_payload_idx)
return self.pack.get_payload_data_at(
Modality.Image, self._image_payload_idx
)

@property
def max_x(self):
return self.image.shape[1] - 1
return self._image_width - 1

@property
def max_y(self):
return self.image.shape[0] - 1
return self._image_height - 1

@property
def image_shape(self):
return (self._image_height, self._image_width)

def set_image_shape(self, width, height):
mylibrar marked this conversation as resolved.
Show resolved Hide resolved
"""
This function is used to set the shape of the image.

Args:
width: the width of the image. The unit is pixel.
height: the height of the image. The unit is pixel.
"""
self._image_width = ( # pylint: disable=attribute-defined-outside-init
width
)
self._image_height = ( # pylint: disable=attribute-defined-outside-init
height
)

def __eq__(self, other):
if other is None:
Expand Down
5 changes: 5 additions & 0 deletions forte/ontology_specs/base_ontology.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"name": "base_ontology",
"definitions": [
{
"entry_name": "ft.onto.base_ontology.Character",
"parent_entry": "forte.data.ontology.top.Annotation",
"description": "A span based annotation :class:`Character`, used to represent a character."
},
{
"entry_name": "ft.onto.base_ontology.Token",
"parent_entry": "forte.data.ontology.top.Annotation",
Expand Down
11 changes: 11 additions & 0 deletions ft/onto/base_ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from typing import Optional

__all__ = [
"Character",
"Token",
"Subword",
"Classification",
Expand Down Expand Up @@ -60,6 +61,16 @@
]


@dataclass
class Character(Annotation):
"""
A span based annotation :class:`Character`, used to represent a character.
"""

def __init__(self, pack: DataPack, begin: int, end: int):
super().__init__(pack, begin, end)


@dataclass
class Token(Annotation):
"""
Expand Down