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

update the SemanticSegmentationTranslator #2032

Conversation

wxm2018
Copy link
Contributor

@wxm2018 wxm2018 commented Sep 21, 2022

Description

Brief description of what this PR is about

update the SemanticSegmentationTranslator to get the original photo pixels

@codecov-commenter
Copy link

codecov-commenter commented Sep 21, 2022

Codecov Report

Base: 72.08% // Head: 70.24% // Decreases project coverage by -1.84% ⚠️

Coverage data is based on head (3501500) compared to base (bb5073f).
Patch coverage: 72.45% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2032      +/-   ##
============================================
- Coverage     72.08%   70.24%   -1.85%     
- Complexity     5126     6075     +949     
============================================
  Files           473      603     +130     
  Lines         21970    26892    +4922     
  Branches       2351     2912     +561     
============================================
+ Hits          15838    18890    +3052     
- Misses         4925     6591    +1666     
- Partials       1207     1411     +204     
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%) ⬇️
.../ai/djl/modality/cv/translator/YoloTranslator.java 27.77% <0.00%> (+18.95%) ⬆️
...modality/cv/translator/wrapper/FileTranslator.java 44.44% <ø> (ø)
...y/cv/translator/wrapper/InputStreamTranslator.java 44.44% <ø> (ø)
.../modality/cv/translator/wrapper/UrlTranslator.java 44.44% <ø> (ø)
... and 525 more

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

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@xyang16 xyang16 force-pushed the update_semanticSegmentationTranslator branch 3 times, most recently from f4030fb to 6c559ef Compare September 29, 2022 01:32
.registerTypeAdapter(Segmentation.class, new SegmentationSerializer())
.create();

private int[][] mask;
Copy link
Contributor

Choose a reason for hiding this comment

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

Segmentation should hold classNames


private final int shortEdge;
private final int maxEdge;

private static final int CHANNEL = 3;
private static final int CLASSNUM = 21;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should comes from model, for deeplabv3, the classes can be found: https://github.com/pytorch/vision/blob/main/torchvision/models/_meta.py#L1128-L1150

double maxnum = -Double.MAX_VALUE;
for (int i = 0; i < CLASSNUM; i++) {
// get score for each i at the h,w pixel of the image
float score = scores[i * (imageSize) + index];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
float score = scores[i * (imageSize) + index];
float score = scores[i * imageSize + index];

public Segmentation(int[][] mask) {
this.mask = mask;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

We need implement the following method:

public void drawMask(Image img, float transparency) {
...
}

public void drawMask(Image img, float transparency, int classId) {
...
}

public void drawMask(Image img, float transparency, int classId, Color color) {
...
}

public void Image extractImage(Image img, int classId) {
...
}

}
}

private static void saveSemanticImage(Image img) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

We still want to save segmented image, and we can save a few different mode:

  1. only colors
  2. transparent color overlay on existing image
  3. replace background with other image

@xyang16 xyang16 force-pushed the update_semanticSegmentationTranslator branch from 8c60b7f to 4c16f9b Compare September 30, 2022 21:40
@@ -120,6 +120,12 @@ public Image fromNDArray(NDArray array) {
return new BitMapWrapper(bitmap);
}

/** {@inheritDoc} */
@Override
public Image fromArray(int[] pixels, int width, int height) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Android depends on published snapshot build.
Move android changes into separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK

@@ -157,6 +165,16 @@ public Object getWrappedImage() {
return image;
}

@Override
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@Override
/** {@inheritDoc} */
@Override

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

@xyang16 xyang16 force-pushed the update_semanticSegmentationTranslator branch 6 times, most recently from cdc0d4c to 97791e7 Compare October 6, 2022 18:54
@frankfliu frankfliu force-pushed the update_semanticSegmentationTranslator branch from 0e7470f to 3501500 Compare October 8, 2022 19:26
@frankfliu frankfliu merged commit 22add9b into deepjavalibrary:master Oct 8, 2022
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.

None yet

4 participants