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

feat: Added plot_samples support to visualize the images along with the targets #704

Merged
merged 9 commits into from
Dec 14, 2021

Conversation

SiddhantBahuguna
Copy link
Contributor

@SiddhantBahuguna SiddhantBahuguna commented Dec 13, 2021

This PR introduces the following modifications:

  1. It adds a plot_sample script to visualize the images along with the targets
    plot_samp

Any feedback is welcome :)

@SiddhantBahuguna SiddhantBahuguna added the topic: object detection Related to the task of object detection label Dec 13, 2021
@SiddhantBahuguna SiddhantBahuguna self-assigned this Dec 13, 2021
@SiddhantBahuguna
Copy link
Contributor Author

When the script is run, I am facing the following error:

Traceback (most recent call last):
  File "/home/siddhant/Mindee/doctr/references/obj_detection/train_pytorch.py", line 289, in <module>
    main(args)
  File "/home/siddhant/Mindee/doctr/references/obj_detection/train_pytorch.py", line 189, in main
    plot_samples(images, targets, 4)
  File "/home/siddhant/Mindee/doctr/references/obj_detection/utils.py", line 31, in plot_samples
    cv2.rectangle(img, (int(box[0]), int(box[1])), (int(box[2]), int(box[3])), color, 1)
cv2.error: OpenCV(4.5.4-dev) :-1: error: (-5:Bad argument) in function 'rectangle'
> Overload resolution failed:
>  - Layout of the output array img is incompatible with cv::Mat
>  - Expected Ptr<cv::UMat> for argument 'img'
>  - Layout of the output array img is incompatible with cv::Mat
>  - Expected Ptr<cv::UMat> for argument 'img'

I am also unable to understand why out images.shape == (1024, 1024, 3) instead of (1024, 800, 3)
Thanks for the feedback !!

Copy link
Contributor

@fg-mindee fg-mindee left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Let's remove the files that aren't related to the PR description :)

references/obj_detection/train_pytorch.py Outdated Show resolved Hide resolved
references/obj_detection/train_pytorch.py Outdated Show resolved Hide resolved
references/obj_detection/train_pytorch.py Outdated Show resolved Hide resolved
references/obj_detection/train_pytorch.py Outdated Show resolved Hide resolved
references/obj_detection/utils.py Outdated Show resolved Hide resolved
references/obj_detection/utils.py Outdated Show resolved Hide resolved
references/obj_detection/utils.py Outdated Show resolved Hide resolved
references/obj_detection/utils.py Outdated Show resolved Hide resolved
scripts/detect_artefacts.py Outdated Show resolved Hide resolved
scripts/utils.py Outdated Show resolved Hide resolved
@fg-mindee fg-mindee added type: enhancement Improvement ext: references Related to references folder labels Dec 13, 2021
@codecov
Copy link

codecov bot commented Dec 13, 2021

Codecov Report

Merging #704 (5f7d978) into main (cf97d9e) will increase coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #704      +/-   ##
==========================================
+ Coverage   96.12%   96.17%   +0.04%     
==========================================
  Files         124      124              
  Lines        4648     4648              
==========================================
+ Hits         4468     4470       +2     
+ Misses        180      178       -2     
Flag Coverage Δ
unittests 96.17% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
doctr/models/detection/linknet/base.py 85.14% <0.00%> (ø)
doctr/models/recognition/predictor/pytorch.py 96.96% <0.00%> (+6.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8af125c...5f7d978. Read the comment docs.

Copy link
Contributor

@fg-mindee fg-mindee left a comment

Choose a reason for hiding this comment

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

A few other things as well in comment

_, axes = plt.subplots(1, nb_samples, figsize=(20, 5))
for idx in range(nb_samples):
img = (255 * images[idx].numpy()).round().clip(0, 255).astype(np.uint8)
target = img.copy()
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move this after the dimension transpose

references/obj_detection/utils.py Outdated Show resolved Hide resolved
references/obj_detection/utils.py Outdated Show resolved Hide resolved
references/obj_detection/utils.py Outdated Show resolved Hide resolved
references/obj_detection/utils.py Outdated Show resolved Hide resolved
references/obj_detection/utils.py Outdated Show resolved Hide resolved
@SiddhantBahuguna SiddhantBahuguna marked this pull request as ready for review December 13, 2021 18:13
Copy link
Contributor

@fg-mindee fg-mindee left a comment

Choose a reason for hiding this comment

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

Looks good to me! Would you mind increasing the line width of the box? It's barely visible when I try on my end 😅 (and perhaps add a screenshot of how it renders in the PR description for future references 👍 )

references/obj_detection/utils.py Outdated Show resolved Hide resolved
@fg-mindee fg-mindee added this to the 0.5.0 milestone Dec 13, 2021
Copy link
Contributor

@fg-mindee fg-mindee left a comment

Choose a reason for hiding this comment

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

Nice!

@fg-mindee fg-mindee changed the title Feat: Added plot_samples support to visualize the images along with the targets feat: Added plot_samples support to visualize the images along with the targets Dec 14, 2021
@SiddhantBahuguna SiddhantBahuguna merged commit 618b0fa into main Dec 14, 2021
@SiddhantBahuguna SiddhantBahuguna deleted the plot_samp_arte branch December 14, 2021 11:10
@fg-mindee fg-mindee added type: new feature New feature and removed type: enhancement Improvement labels Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext: references Related to references folder topic: object detection Related to the task of object detection type: new feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[references] Implement a show_sample option in the object detection training script
2 participants