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

Create translator options #2145

Merged
merged 2 commits into from
Nov 18, 2022
Merged

Conversation

zachgk
Copy link
Contributor

@zachgk zachgk commented Nov 9, 2022

This creates a new tool for TranslatorOptions based on the characteristic function ((InputClass, OutputClass) -> Translator). Unlike the TranslatorFactory, it doesn't require arguments or a model. So, the TranslatorFactory is mainly used as part of model loading where the TranslatorOptions can be more broad.

In particular, it connects to both Dataset and Translator. Both of them gain a new function that will return a TranslatorOptions (matchingTranslatorOptions for the Dataset and getExpansions for the translator). Right now, I made both of these optional with a default value of null so that users don't have to define them, it is just a possibility.

To connect the TranslatorOptions and TranslatorFactory, I created a class ExpansionTranslatorFactory. This is used for the common abstraction where we have a base translator and multiple "expansions" for it that come before it in pre-processing or after it in post-processing. With a way to construct the base translator with the options, it works as a TranslatorFactory. With a starting Translator, it can become the TranslatorOptions.

Lastly and probably worth calling out, the ExpansionTranslatorFactory creates a map of the options. This allows the supported types and the functions to be defined in only one place instead of two. In a followup PR, I will make a version of this that creates a BaseImageTranslatorFactory matching the BaseImageTranslator and will handle all of the repeated code for all of the image translator factories.

@codecov-commenter
Copy link

codecov-commenter commented Nov 9, 2022

Codecov Report

Base: 72.08% // Head: 71.52% // Decreases project coverage by -0.56% ⚠️

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

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2145      +/-   ##
============================================
- Coverage     72.08%   71.52%   -0.57%     
- Complexity     5126     6337    +1211     
============================================
  Files           473      628     +155     
  Lines         21970    27969    +5999     
  Branches       2351     3008     +657     
============================================
+ Hits          15838    20004    +4166     
- Misses         4925     6496    +1571     
- Partials       1207     1469     +262     
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%) ⬇️
.../modality/cv/translator/ImageFeatureExtractor.java 0.00% <0.00%> (ø)
.../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% <ø> (ø)
... and 561 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.

This creates a new tool for TranslatorOptions based on the characteristic
function ((InputClass, OutputClass) -> Translator). Unlike the
TranslatorFactory, it doesn't require arguments or a model. So, the
TranslatorFactory is mainly used as part of model loading where the
TranslatorOptions can be more broad.

In particular, it connects to both Dataset and Translator. Both of them gain a
new function that will return a TranslatorOptions (matchingTranslatorOptions for
the Dataset and getExpansions for the translator). Right now, I made both of
these optional with a default value of null so that users don't have to define
them, it is just a possibility.

To connect the TranslatorOptions and TranslatorFactory, I created a class
ExpansionTranslatorFactory. This is used for the common abstraction where we
have a base translator and multiple "expansions" for it that come before it in
pre-processing or after it in post-processing. With a way to construct the base
translator with the options, it works as a TranslatorFactory. With a starting
Translator, it can become the TranslatorOptions.

Lastly and probably worth calling out, the ExpansionTranslatorFactory creates a
map of the options. This allows the supported types and the functions to be
defined in only one place instead of two. In a followup PR, I will make a
version of this that creates a BaseImageTranslatorFactory matching the
BaseImageTranslator and will handle all of the repeated code for all of the
image translator factories.
@zachgk zachgk merged commit 7ceb7cd into deepjavalibrary:master Nov 18, 2022
@zachgk zachgk deleted the translatorExpansion branch November 18, 2022 21:10
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