Repository: deepjavalibrary/djl
Pull request #1272 (2021-10-06 02:56:15)

Add resnet101 to modelzoo
Change-Id: I39bb5c181d0c2722b524ff87760c4af11777764a

## Description ##

Brief description of what this PR is about

- If this change is a backward incompatible change, why must this change be made?
- Interesting edge cases to note here


codecov-commenter: # [Codecov](https://codecov.io/gh/deepjavalibrary/djl/pull/1272?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) Report
> Merging [#1272](https://codecov.io/gh/deepjavalibrary/djl/pull/1272?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) (337683e) into [master](https://codecov.io/gh/deepjavalibrary/djl/commit/b94f0da1aa58cde52129a3fb27e71b00c5dea2fb?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) (b94f0da) will **increase** coverage by `0.02%`.
> The diff coverage is `66.66%`.

[![Impacted file tree graph](https://codecov.io/gh/deepjavalibrary/djl/pull/1272/graphs/tree.svg?width=650&height=150&src=pr&token=mDKVNwFXRV&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary)](https://codecov.io/gh/deepjavalibrary/djl/pull/1272?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary)

```diff
@@             Coverage Diff              @@
##             master    #1272      +/-   ##
============================================
+ Coverage     72.03%   72.06%   +0.02%     
- Complexity     5121     5123       +2     
============================================
  Files           473      473              
  Lines         21955    21959       +4     
  Branches       2349     2349              
============================================
+ Hits          15815    15824       +9     
+ Misses         4935     4931       -4     
+ Partials       1205     1204       -1     
```


| [Impacted Files](https://codecov.io/gh/deepjavalibrary/djl/pull/1272?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) | Coverage Δ | |
|---|---|---|
| [...jl/modality/cv/translator/BaseImageTranslator.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1272/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvQmFzZUltYWdlVHJhbnNsYXRvci5qYXZh) | `79.68% <33.33%> (+1.73%)` | :arrow_up: |
| [...ain/java/ai/djl/repository/AbstractRepository.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1272/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL3JlcG9zaXRvcnkvQWJzdHJhY3RSZXBvc2l0b3J5LmphdmE=) | `75.77% <100.00%> (-1.10%)` | :arrow_down: |
| [.../main/java/ai/djl/onnxruntime/zoo/OrtModelZoo.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1272/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-ZW5naW5lcy9vbm54cnVudGltZS9vbm54cnVudGltZS1lbmdpbmUvc3JjL21haW4vamF2YS9haS9kamwvb25ueHJ1bnRpbWUvem9vL09ydE1vZGVsWm9vLmphdmE=) | `100.00% <100.00%> (ø)` | |
| [...gine/src/main/java/ai/djl/dlr/engine/DlrModel.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1272/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-ZW5naW5lcy9kbHIvZGxyLWVuZ2luZS9zcmMvbWFpbi9qYXZhL2FpL2RqbC9kbHIvZW5naW5lL0Rsck1vZGVsLmphdmE=) | `51.61% <0.00%> (-3.23%)` | :arrow_down: |
| [api/src/main/java/ai/djl/util/Platform.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1272/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL3V0aWwvUGxhdGZvcm0uamF2YQ==) | `69.81% <0.00%> (-1.89%)` | :arrow_down: |
| [api/src/main/java/ai/djl/repository/Artifact.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1272/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL3JlcG9zaXRvcnkvQXJ0aWZhY3QuamF2YQ==) | `87.80% <0.00%> (-1.63%)` | :arrow_down: |
| [...ain/java/ai/djl/tensorflow/engine/TfNDManager.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1272/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-ZW5naW5lcy90ZW5zb3JmbG93L3RlbnNvcmZsb3ctZW5naW5lL3NyYy9tYWluL2phdmEvYWkvZGpsL3RlbnNvcmZsb3cvZW5naW5lL1RmTkRNYW5hZ2VyLmphdmE=) | `87.78% <0.00%> (-1.53%)` | :arrow_down: |
| [...ngine/src/main/java/ai/djl/mxnet/jna/LibUtils.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1272/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-ZW5naW5lcy9teG5ldC9teG5ldC1lbmdpbmUvc3JjL21haW4vamF2YS9haS9kamwvbXhuZXQvam5hL0xpYlV0aWxzLmphdmE=) | `40.00% <0.00%> (-1.18%)` | :arrow_down: |
| [.../main/java/ai/djl/benchmark/AbstractBenchmark.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1272/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-ZXh0ZW5zaW9ucy9iZW5jaG1hcmsvc3JjL21haW4vamF2YS9haS9kamwvYmVuY2htYXJrL0Fic3RyYWN0QmVuY2htYXJrLmphdmE=) | `90.00% <0.00%> (-1.18%)` | :arrow_down: |
| ... and [7 more](https://codecov.io/gh/deepjavalibrary/djl/pull/1272/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/deepjavalibrary/djl/pull/1272?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/deepjavalibrary/djl/pull/1272?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary). Last update [b94f0da...337683e](https://codecov.io/gh/deepjavalibrary/djl/pull/1272?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary).


Patch:
diff --git a/api/src/main/java/ai/djl/modality/cv/translator/BaseImageTranslator.java b/api/src/main/java/ai/djl/modality/cv/translator/BaseImageTranslator.java
index ebc550655..618a63281 100644
--- a/api/src/main/java/ai/djl/modality/cv/translator/BaseImageTranslator.java
+++ b/api/src/main/java/ai/djl/modality/cv/translator/BaseImageTranslator.java
@@ -191,9 +191,11 @@ public abstract class BaseImageTranslator<T> implements Translator<Image, T> {
                 String[] tokens = resize.split("\\s*,\\s*");
                 if (tokens.length > 1) {
                     addTransform(
-                            new Resize(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])));
+                            new Resize(
+                                    (int) Double.parseDouble(tokens[0]),
+                                    (int) Double.parseDouble(tokens[1])));
                 } else {
-                    addTransform(new Resize(Integer.parseInt(tokens[0])));
+                    addTransform(new Resize((int) Double.parseDouble(tokens[0])));
                 }
             }
             if (getBooleanValue(arguments, "centerCrop", false)) {
diff --git a/api/src/main/java/ai/djl/repository/AbstractRepository.java b/api/src/main/java/ai/djl/repository/AbstractRepository.java
index 92c4df03e..8279eb9ee 100644
--- a/api/src/main/java/ai/djl/repository/AbstractRepository.java
+++ b/api/src/main/java/ai/djl/repository/AbstractRepository.java
@@ -37,6 +37,7 @@ import java.util.zip.ZipInputStream;
 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
 import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
 import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
+import org.apache.commons.compress.utils.CloseShieldFilterInputStream;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -238,6 +239,7 @@ public abstract class AbstractRepository implements Repository {
         } else {
             bis = new BufferedInputStream(is);
         }
+        bis = new CloseShieldFilterInputStream(bis);
         try (TarArchiveInputStream tis = new TarArchiveInputStream(bis)) {
             TarArchiveEntry entry;
             while ((entry = tis.getNextTarEntry()) != null) {
diff --git a/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/zoo/OrtModelZoo.java b/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/zoo/OrtModelZoo.java
index 4f5a8874b..6f8cb2640 100644
--- a/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/zoo/OrtModelZoo.java
+++ b/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/zoo/OrtModelZoo.java
@@ -12,6 +12,7 @@
  */
 package ai.djl.onnxruntime.zoo;
 
+import ai.djl.Application.CV;
 import ai.djl.Application.Tabular;
 import ai.djl.onnxruntime.engine.OrtEngine;
 import ai.djl.repository.MRL;
@@ -34,6 +35,9 @@ public class OrtModelZoo extends ModelZoo {
     private static final List<ModelLoader> MODEL_LOADERS = new ArrayList<>();
 
     static {
+        MRL resnet = REPOSITORY.model(CV.IMAGE_CLASSIFICATION, GROUP_ID, "resnet", "0.0.1");
+        MODEL_LOADERS.add(new BaseModelLoader(resnet));
+
         MRL irisFlower =
                 REPOSITORY.model(Tabular.SOFTMAX_REGRESSION, GROUP_ID, "iris_flowers", "0.0.1");
         MODEL_LOADERS.add(new BaseModelLoader(irisFlower));


Test patch:
diff --git a/engines/mxnet/mxnet-model-zoo/src/test/resources/mlrepo/model/cv/image_classification/ai/djl/mxnet/resnet/metadata.json b/engines/mxnet/mxnet-model-zoo/src/test/resources/mlrepo/model/cv/image_classification/ai/djl/mxnet/resnet/metadata.json
index 666fc3870..c65636ac7 100644
--- a/engines/mxnet/mxnet-model-zoo/src/test/resources/mlrepo/model/cv/image_classification/ai/djl/mxnet/resnet/metadata.json
+++ b/engines/mxnet/mxnet-model-zoo/src/test/resources/mlrepo/model/cv/image_classification/ai/djl/mxnet/resnet/metadata.json
@@ -26,8 +26,8 @@
       "arguments": {
         "width": 224,
         "height": 224,
+        "resize": 256,
         "centerCrop": true,
-        "resize": true,
         "applySoftmax": true
       },
       "files": {
@@ -60,8 +60,8 @@
       "arguments": {
         "width": 224,
         "height": 224,
+        "resize": 256,
         "centerCrop": true,
-        "resize": true,
         "applySoftmax": true
       },
       "files": {
@@ -82,6 +82,31 @@
         }
       }
     },
+    {
+      "version": "0.0.1",
+      "snapshot": false,
+      "name": "resnet101_v1",
+      "properties": {
+        "layers": "101",
+        "dataset": "imagenet"
+      },
+      "arguments": {
+        "width": 224,
+        "height": 224,
+        "resize": 256,
+        "centerCrop": true,
+        "normalize": true,
+        "applySoftmax": true
+      },
+      "files": {
+        "model": {
+          "uri": "0.0.1/resnet101_v1.tar.gz",
+          "name": "",
+          "sha1Hash": "3f2f3a216520311388d17d24c798b0c87740024a",
+          "size": 102734558
+        }
+      }
+    },
     {
       "version": "0.0.1",
       "snapshot": false,
@@ -94,8 +119,8 @@
       "arguments": {
         "width": 224,
         "height": 224,
+        "resize": 256,
         "centerCrop": true,
-        "resize": true,
         "applySoftmax": true
       },
       "files": {
@@ -128,8 +153,8 @@
       "arguments": {
         "width": 224,
         "height": 224,
+        "resize": 256,
         "centerCrop": true,
-        "resize": true,
         "applySoftmax": true
       },
       "files": {
diff --git a/engines/onnxruntime/onnxruntime-engine/src/test/resources/mlrepo/model/cv/image_classification/ai/djl/onnxruntime/resnet/metadata.json b/engines/onnxruntime/onnxruntime-engine/src/test/resources/mlrepo/model/cv/image_classification/ai/djl/onnxruntime/resnet/metadata.json
new file mode 100644
index 000000000..bb8326040
--- /dev/null
+++ b/engines/onnxruntime/onnxruntime-engine/src/test/resources/mlrepo/model/cv/image_classification/ai/djl/onnxruntime/resnet/metadata.json
@@ -0,0 +1,68 @@
+{
+  "metadataVersion": "0.2",
+  "resourceType": "model",
+  "application": "cv/image_classification",
+  "groupId": "ai.djl.onnxruntime",
+  "artifactId": "resnet",
+  "name": "Resnet",
+  "description": "Resnet image classification",
+  "website": "http://www.djl.ai/engines/onnxruntime/model-zoo",
+  "licenses": {
+    "license": {
+      "name": "The Apache License, Version 2.0",
+      "url": "https://www.apache.org/licenses/LICENSE-2.0"
+    }
+  },
+  "artifacts": [
+    {
+      "version": "0.0.1",
+      "snapshot": false,
+      "name": "resnet18_v1-7",
+      "properties": {
+        "layers": "18",
+        "dataset": "imagenet"
+      },
+      "arguments": {
+        "width": 224,
+        "height": 224,
+        "resize": 256,
+        "centerCrop": true,
+        "normalize": true,
+        "applySoftmax": true
+      },
+      "files": {
+        "model": {
+          "uri": "0.0.1/resnet18_v1-7.tar.gz",
+          "name": "",
+          "sha1Hash": "12159f62b06d303097bccf4362b0355863b68213",
+          "size": 43287819
+        }
+      }
+    },
+    {
+      "version": "0.0.1",
+      "snapshot": false,
+      "name": "resnet101_v1",
+      "properties": {
+        "layers": "101",
+        "dataset": "imagenet"
+      },
+      "arguments": {
+        "width": 224,
+        "height": 224,
+        "resize": 256,
+        "centerCrop": true,
+        "normalize": true,
+        "applySoftmax": true
+      },
+      "files": {
+        "model": {
+          "uri": "0.0.1/resnet101_v1.tar.gz",
+          "name": "",
+          "sha1Hash": "7d5a2c748386a94af868a95da38728ff3b6ea8b1",
+          "size": 165675340
+        }
+      }
+    }
+  ]
+}
diff --git a/engines/pytorch/pytorch-model-zoo/src/test/resources/mlrepo/model/cv/image_classification/ai/djl/pytorch/resnet/metadata.json b/engines/pytorch/pytorch-model-zoo/src/test/resources/mlrepo/model/cv/image_classification/ai/djl/pytorch/resnet/metadata.json
index 1774cb0a3..655d86c69 100644
--- a/engines/pytorch/pytorch-model-zoo/src/test/resources/mlrepo/model/cv/image_classification/ai/djl/pytorch/resnet/metadata.json
+++ b/engines/pytorch/pytorch-model-zoo/src/test/resources/mlrepo/model/cv/image_classification/ai/djl/pytorch/resnet/metadata.json
@@ -25,7 +25,8 @@
       "arguments": {
         "width": 224,
         "height": 224,
-        "resize": true,
+        "resize": 256,
+        "centerCrop": true,
         "normalize": true,
         "applySoftmax": true
       },
@@ -53,7 +54,8 @@
       "arguments": {
         "width": 224,
         "height": 224,
-        "resize": true,
+        "resize": 256,
+        "centerCrop": true,
         "normalize": true,
         "applySoftmax": true
       },
@@ -69,6 +71,31 @@
           "size": 43482267
         }
       }
+    },
+    {
+      "version": "0.0.1",
+      "snapshot": false,
+      "name": "resnet101_v1",
+      "properties": {
+        "layers": "101",
+        "dataset": "imagenet"
+      },
+      "arguments": {
+        "width": 224,
+        "height": 224,
+        "resize": 256,
+        "centerCrop": true,
+        "normalize": true,
+        "applySoftmax": true
+      },
+      "files": {
+        "model": {
+          "uri": "0.0.1/resnet101_v1.tar.gz",
+          "name": "",
+          "sha1Hash": "e3d85c47c751ab23662b6f3eb04cc6215727994c",
+          "size": 166376847
+        }
+      }
     }
   ]
 }