Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Enhancement/1314 allow sizing show sample #1381

Conversation

Nico995
Copy link
Contributor

@Nico995 Nico995 commented Jul 5, 2022

What does this PR do?

Fixes #1314

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests? [not needed for typos/docs]
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

  • Is this pull request ready for review? (if not, please submit in draft mode)

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@codecov
Copy link

codecov bot commented Jul 5, 2022

Codecov Report

Merging #1381 (bbb1307) into master (4f6fe93) will decrease coverage by 0.00%.
The diff coverage is 97.87%.

@@            Coverage Diff             @@
##           master    #1381      +/-   ##
==========================================
- Coverage   92.93%   92.93%   -0.01%     
==========================================
  Files         286      286              
  Lines       12837    12844       +7     
==========================================
+ Hits        11930    11936       +6     
- Misses        907      908       +1     
Flag Coverage Δ
unittests 92.93% <97.87%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
flash/image/segmentation/viz.py 87.93% <90.90%> (-0.96%) ⬇️
flash/core/data/base_viz.py 100.00% <100.00%> (ø)
flash/core/data/data_module.py 95.27% <100.00%> (+0.04%) ⬆️
flash/image/classification/data.py 98.65% <100.00%> (+<0.01%) ⬆️
flash/template/classification/data.py 95.77% <100.00%> (ø)
flash/text/question_answering/model.py 93.87% <0.00%> (ø)

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 4f6fe93...bbb1307. Read the comment docs.

@Nico995
Copy link
Contributor Author

Nico995 commented Jul 7, 2022

It looks like the code is passing all the tests, but Azure pipelines are failing. I think I need help on this one.

@Nico995 Nico995 marked this pull request as ready for review July 16, 2022 13:25
Copy link
Contributor

@krshrimali krshrimali left a comment

Choose a reason for hiding this comment

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

Hi, @Nico995 - Thanks for the fix, this looks good to me! Apologies for the delay in the review, and I appreciate the ping. 😃

I have a one-inline suggestion for you to take a look at, other than that - can you also share the output figure it shows after this PR (and before this PR)? Also, once done, we can also add doc-strings about the arguments limit_nb_samples, figsize that we have added in this PR (they will appear here: https://lightning-flash.readthedocs.io/en/latest/api/generated/flash.core.data.data_module.DataModule.html?highlight=show%20batch#flash.core.data.data_module.DataModule.show_train_batch). Let us know if you would like to pick this up, maybe in a separate PR.

flash/image/segmentation/viz.py Outdated Show resolved Hide resolved
Removed redundant axs.ravel()

Co-authored-by: Kushashwa Ravi Shrimali <kushashwaravishrimali@gmail.com>
@Nico995
Copy link
Contributor Author

Nico995 commented Jul 19, 2022

Hi @krshrimali, thanks for your suggestion, it made perfect sense. I will gladly fix the documentation. As you suggested, I'll open a new separate PR. Should I open an Issue first, or should I just open the PR? (maybe referencing this one)

@krshrimali
Copy link
Contributor

Hi @krshrimali, thanks for your suggestion, it made perfect sense. I will gladly fix the documentation. As you suggested, I'll open a new separate PR. Should I open an Issue first, or should I just open the PR? (maybe referencing this one)

Thank you so much, doc-strings for the arguments will be great! Yep, you can add them in a separate PR. Also, would you like to share a sample output image with us? :)

Feel free to create a PR directly, thanks for your interest and contributions. 🎉

Nicola Occelli added 2 commits July 20, 2022 10:20
…m:Nico995/lightning-flash into enhancement/1314_allow_sizing_show_sample
@Nico995
Copy link
Contributor Author

Nico995 commented Jul 20, 2022

Hi, while producing some sample images I noticed that I missed a line, now everything should work correctly.
I produced some sample images before and after the enhancement:

Classification

import torch
import flash
import matplotlib.pyplot as plt
from flash.core.data.utils import download_data
from flash.image import ImageClassificationData, ImageClassifier

download_data("https://pl-flash-data.s3.amazonaws.com/hymenoptera_data.zip", "./data")

datamodule = ImageClassificationData.from_folders(
    train_folder="data/hymenoptera_data/train/",
    val_folder="data/hymenoptera_data/val/",
    batch_size=8,
    transform_kwargs={"image_size": (196, 196), "mean": (0.485, 0.456, 0.406), "std": (0.229, 0.224, 0.225)},
)

datamodule.show_train_batch()
plt.show()
datamodule.show_train_batch(figsize=(16, 16))
plt.show()

Produces

samples_class_old
samples_class_new

Semantic Segmentation

from flash.image import SemanticSegmentationData

download_data(
    "https://github.com/ongchinkiat/LyftPerceptionChallenge/releases/download/v0.1/carla-capture-20180513A.zip",
    "./data",
)

datamodule = SemanticSegmentationData.from_folders(
    train_folder="data/CameraRGB",
    train_target_folder="data/CameraSeg",
    val_split=0.1,
    transform_kwargs=dict(image_size=(256, 256)),
    num_classes=21,
    batch_size=8,
)

datamodule.show_train_batch()
plt.show()
datamodule.show_train_batch(figsize=(16, 3))
plt.show()

produces

samples_semseg_old
samples_semseg_new

@krshrimali
Copy link
Contributor

Thanks, @Nico995 - this looks great to me! Nice work!

@ethanwharris ethanwharris added the enhancement New feature or request label Jul 21, 2022
@ethanwharris ethanwharris added this to the 0.8.0 milestone Jul 21, 2022
@ethanwharris ethanwharris merged commit 804ca86 into Lightning-Universe:master Jul 21, 2022
@Nico995 Nico995 deleted the enhancement/1314_allow_sizing_show_sample branch July 21, 2022 16:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allow sizing for show sample batch
3 participants