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

Add handling of multiclass format in detection dataset loading #4

Open
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

aminemindee
Copy link
Owner

@aminemindee aminemindee commented Sep 1, 2022

Hello,

For testing,

  • dataset, in tests/common/test_datasets.py

  • preditions , in tensorflow and pytorch in test_models_detection and test_models_zoo

  • for training part, you should use the command

python references/detection/train_pytorch.py path/to/train/folder/ /path/to/test/folder/ "db_resnet34" for db model
python references/detection/train_pytorch.py path/to/train/folder/ /path/to/test/folder/ "linknet_resnet34" for linknet model

@aminemindee aminemindee force-pushed the feat/multiclass branch 2 times, most recently from e33889b to 2e2a281 Compare September 22, 2022 15:02
Comment on lines 59 to 60
for k, v in target.items():
img, target[k] = self.sample_transforms(img, v)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you apply self.sample_transforms multiple time on img. Also, img seems to be strongly linked to the latest target in dict because it's the output of self.sample_transforms with v as target, but I'm not sure what is the impact on img.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's more the other way around from what i see the transforms used in training are resizing transform and it's the target changes that is linked to the image

Yes the changes are done multiple time to the img

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't understand. Do you have an example ?
Is it fine to apply multiple times the same transformation on the same image ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you're right ! didn't see it

i tried resolving it this way

img_transformed = img.copy()
for class_name, bboxes in target.items():
      img_transformed, target[class_name] = self.sample_transforms(img, bboxes)
img = img_transformed

what do you think ?

doctr/datasets/datasets/pytorch.py Outdated Show resolved Hide resolved
doctr/datasets/datasets/tensorflow.py Outdated Show resolved Hide resolved
doctr/datasets/detection.py Show resolved Hide resolved
doctr/datasets/detection.py Outdated Show resolved Hide resolved
doctr/models/_utils.py Show resolved Hide resolved
doctr/models/_utils.py Outdated Show resolved Hide resolved
doctr/models/detection/differentiable_binarization/base.py Outdated Show resolved Hide resolved
doctr/models/detection/differentiable_binarization/base.py Outdated Show resolved Hide resolved
val_metric.update(gts=boxes_gt, preds=boxes_pred[:, :4])
for target, loc_pred in zip(targets, loc_preds):
if isinstance(target, np.ndarray):
target = {"words": target}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constant words

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

references/detection/train_tensorflow.py Outdated Show resolved Hide resolved
tests/common/test_models_builder.py Outdated Show resolved Hide resolved
tests/pytorch/test_models_detection_pt.py Outdated Show resolved Hide resolved
tests/tensorflow/test_models_detection_tf.py Outdated Show resolved Hide resolved
doctr/datasets/detection.py Outdated Show resolved Hide resolved
doctr/datasets/utils.py Outdated Show resolved Hide resolved
doctr/datasets/utils.py Show resolved Hide resolved
doctr/models/_utils.py Show resolved Hide resolved
doctr/models/_utils.py Outdated Show resolved Hide resolved
doctr/models/detection/linknet/base.py Outdated Show resolved Hide resolved
doctr/utils/visualization.py Outdated Show resolved Hide resolved
references/detection/train_pytorch.py Outdated Show resolved Hide resolved
tests/common/test_models_builder.py Outdated Show resolved Hide resolved
tests/common/test_models_builder.py Outdated Show resolved Hide resolved
@@ -141,6 +141,24 @@ def create_obj_patch(
raise ValueError("invalid geometry format")


def get_colors(num_colors: int) -> List:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typing on return statement: List[Tuple[int, int, int]]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -56,8 +56,10 @@ def __getitem__(self, index: int) -> Tuple[Any, Any]:

if self.sample_transforms is not None:
if isinstance(target, dict):
img_transformed = img.copy()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.copy() didn't work neither on Tensorflow nor PyTorch. You may need to check if the current backend (TF or PyTorch) and use the good method to clone the tensor

Comment on lines 24 to 25
boxes = {CLASS_NAME: np.random.rand(words_per_page, 6)}
boxes[CLASS_NAME][:2] *= boxes[CLASS_NAME][2:4]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove these statements, otherwise boxes parameter is not used ;-)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

@odulcy-mindee odulcy-mindee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work ! 🚀

aminemindee and others added 23 commits December 5, 2022 17:10
…lements for kie predictor (#6)

* feat: ✨ add load backbone

* feat: change kie predictor out

* fix new elements for kie, dataset when class is empty and fix and add tests

* fix api kie route

* fix evaluate kie script

* fix black

* remove commented code

* update README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants