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

fix some bugs in pytorch based examples #2009

Merged
merged 1 commit into from
Sep 13, 2022

Conversation

siddvenk
Copy link
Contributor

@siddvenk siddvenk commented Sep 12, 2022

Description

While changing to PyTorch as the default engine I noticed some bugs in examples that rely on PyTorch engine related to #1774.

This changes fixes those examples. I guess this also shows that we are skipping some tests in our current CI, since this issue would have been caught before had the tests run automatically.

@@ -40,13 +40,15 @@ public BigGANTranslator(float truncation) {
/** {@inheritDoc} */
@Override
public Image[] processOutput(TranslatorContext ctx, NDList list) {
NDArray output = list.get(0).addi(1).muli(128).clip(0, 255);
Image[] images;
try (NDArray output = list.get(0).duplicate().addi(1).muli(128).clip(0, 255)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

use try for NDArray makes the code looks ugly.
We generally don't use try-with-resource in Translator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it - i'll update

@@ -52,7 +52,10 @@ public static void main(String[] args) throws IOException, ModelException, Trans
Image input = ImageFactory.getInstance().fromFile(Paths.get(imagePath));
Image output = transfer(input, artist);

logger.info("Using PyTorch Engine. " + artist + " painting generated.");
logger.info(
Copy link
Contributor

Choose a reason for hiding this comment

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

logger.info("Using PyTorch Engine. {} painting generated. Image saved in build/output/cyclegan", artist);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@siddvenk siddvenk force-pushed the pytorch-example-bugs branch 2 times, most recently from 2e491b2 to 98bebce Compare September 13, 2022 00:15
@codecov-commenter
Copy link

codecov-commenter commented Sep 13, 2022

Codecov Report

Merging #2009 (2e491b2) into master (bb5073f) will decrease coverage by 2.11%.
The diff coverage is 68.22%.

❗ Current head 2e491b2 differs from pull request most recent head 9191194. Consider uploading reports for the commit 9191194 to get more accurate results

@@             Coverage Diff              @@
##             master    #2009      +/-   ##
============================================
- Coverage     72.08%   69.97%   -2.12%     
- Complexity     5126     5948     +822     
============================================
  Files           473      587     +114     
  Lines         21970    26283    +4313     
  Branches       2351     2860     +509     
============================================
+ Hits          15838    18392    +2554     
- Misses         4925     6509    +1584     
- Partials       1207     1382     +175     
Impacted Files Coverage Δ
api/src/main/java/ai/djl/modality/cv/Image.java 69.23% <ø> (-4.11%) ⬇️
...rc/main/java/ai/djl/modality/cv/MultiBoxPrior.java 76.00% <ø> (ø)
...rc/main/java/ai/djl/modality/cv/output/Joints.java 71.42% <ø> (ø)
.../main/java/ai/djl/modality/cv/output/Landmark.java 100.00% <ø> (ø)
...main/java/ai/djl/modality/cv/output/Rectangle.java 72.41% <0.00%> (ø)
...i/djl/modality/cv/translator/BigGANTranslator.java 21.42% <0.00%> (-5.24%) ⬇️
...odality/cv/translator/BigGANTranslatorFactory.java 33.33% <0.00%> (+8.33%) ⬆️
.../cv/translator/InstanceSegmentationTranslator.java 0.00% <0.00%> (-86.59%) ⬇️
...nslator/InstanceSegmentationTranslatorFactory.java 7.14% <0.00%> (-11.04%) ⬇️
.../cv/translator/SemanticSegmentationTranslator.java 0.00% <0.00%> (ø)
... and 501 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@siddvenk siddvenk merged commit 5073966 into deepjavalibrary:master Sep 13, 2022
@siddvenk siddvenk deleted the pytorch-example-bugs branch September 13, 2022 15:42
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.

3 participants