Repository: deepjavalibrary/djl
Pull request #2115 (2022-11-02 01:16:23)

bump up onnxruntime and xgboost
## Description ##

upgrade onnxruntime and xgboost


codecov-commenter: # [Codecov](https://codecov.io/gh/deepjavalibrary/djl/pull/2115?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) Report
Base: **72.08**% // Head: **71.34**% // Decreases project coverage by **`-0.74%`** :warning:
> Coverage data is based on head [(`a2620b6`)](https://codecov.io/gh/deepjavalibrary/djl/pull/2115?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) compared to base [(`bb5073f`)](https://codecov.io/gh/deepjavalibrary/djl/commit/bb5073f7ffc33f1883621fc1783dbb01e70b418f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary).
> Patch coverage: 71.66% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff              @@
##             master    #2115      +/-   ##
============================================
- Coverage     72.08%   71.34%   -0.75%     
- Complexity     5126     6282    +1156     
============================================
  Files           473      624     +151     
  Lines         21970    27819    +5849     
  Branches       2351     3000     +649     
============================================
+ Hits          15838    19848    +4010     
- Misses         4925     6511    +1586     
- Partials       1207     1460     +253     
```


| [Impacted Files](https://codecov.io/gh/deepjavalibrary/djl/pull/2115?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) | Coverage Δ | |
|---|---|---|
| [api/src/main/java/ai/djl/modality/cv/Image.java](https://codecov.io/gh/deepjavalibrary/djl/pull/2115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L0ltYWdlLmphdmE=) | `69.23% <ø> (-4.11%)` | :arrow_down: |
| [...rc/main/java/ai/djl/modality/cv/MultiBoxPrior.java](https://codecov.io/gh/deepjavalibrary/djl/pull/2115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L011bHRpQm94UHJpb3IuamF2YQ==) | `76.00% <ø> (ø)` | |
| [...rc/main/java/ai/djl/modality/cv/output/Joints.java](https://codecov.io/gh/deepjavalibrary/djl/pull/2115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L291dHB1dC9Kb2ludHMuamF2YQ==) | `71.42% <ø> (ø)` | |
| [.../main/java/ai/djl/modality/cv/output/Landmark.java](https://codecov.io/gh/deepjavalibrary/djl/pull/2115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L291dHB1dC9MYW5kbWFyay5qYXZh) | `100.00% <ø> (ø)` | |
| [...main/java/ai/djl/modality/cv/output/Rectangle.java](https://codecov.io/gh/deepjavalibrary/djl/pull/2115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L291dHB1dC9SZWN0YW5nbGUuamF2YQ==) | `72.41% <0.00%> (ø)` | |
| [...i/djl/modality/cv/translator/BigGANTranslator.java](https://codecov.io/gh/deepjavalibrary/djl/pull/2115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvQmlnR0FOVHJhbnNsYXRvci5qYXZh) | `21.42% <0.00%> (-5.24%)` | :arrow_down: |
| [.../modality/cv/translator/ImageFeatureExtractor.java](https://codecov.io/gh/deepjavalibrary/djl/pull/2115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvSW1hZ2VGZWF0dXJlRXh0cmFjdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [.../ai/djl/modality/cv/translator/YoloTranslator.java](https://codecov.io/gh/deepjavalibrary/djl/pull/2115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvWW9sb1RyYW5zbGF0b3IuamF2YQ==) | `27.77% <0.00%> (+18.95%)` | :arrow_up: |
| [...modality/cv/translator/wrapper/FileTranslator.java](https://codecov.io/gh/deepjavalibrary/djl/pull/2115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3Ivd3JhcHBlci9GaWxlVHJhbnNsYXRvci5qYXZh) | `44.44% <ø> (ø)` | |
| [...y/cv/translator/wrapper/InputStreamTranslator.java](https://codecov.io/gh/deepjavalibrary/djl/pull/2115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3Ivd3JhcHBlci9JbnB1dFN0cmVhbVRyYW5zbGF0b3IuamF2YQ==) | `44.44% <ø> (ø)` | |
| ... and [558 more](https://codecov.io/gh/deepjavalibrary/djl/pull/2115/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/deepjavalibrary/djl/pull/2115?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary).


Patch:
diff --git a/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/engine/OrtEngine.java b/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/engine/OrtEngine.java
index bb49ac51c..6bf773e15 100644
--- a/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/engine/OrtEngine.java
+++ b/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/engine/OrtEngine.java
@@ -99,7 +99,7 @@ public final class OrtEngine extends Engine {
     /** {@inheritDoc} */
     @Override
     public String getVersion() {
-        return "1.12.1";
+        return "1.13.1";
     }
 
     /** {@inheritDoc} */
diff --git a/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/engine/OrtSymbolBlock.java b/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/engine/OrtSymbolBlock.java
index e05f95568..aa54b43f3 100644
--- a/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/engine/OrtSymbolBlock.java
+++ b/engines/onnxruntime/onnxruntime-engine/src/main/java/ai/djl/onnxruntime/engine/OrtSymbolBlock.java
@@ -25,12 +25,12 @@ import ai.djl.nn.SymbolBlock;
 import ai.djl.training.ParameterStore;
 import ai.djl.util.PairList;
 import ai.onnxruntime.OnnxJavaType;
+import ai.onnxruntime.OnnxMap;
 import ai.onnxruntime.OnnxSequence;
 import ai.onnxruntime.OnnxTensor;
 import ai.onnxruntime.OnnxValue;
 import ai.onnxruntime.OrtException;
 import ai.onnxruntime.OrtSession;
-import ai.onnxruntime.SequenceInfo;
 
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
@@ -135,7 +135,12 @@ public class OrtSymbolBlock extends AbstractSymbolBlock implements AutoCloseable
                 output.add(manager.createInternal((OnnxTensor) value));
             } else if (value instanceof OnnxSequence) {
                 // TODO: avoid memory copying to heap
-                output.add(seq2Nd((OnnxSequence) value));
+                OnnxSequence seq = (OnnxSequence) value;
+                if (seq.getInfo().isSequenceOfMaps()) {
+                    output.add(seq2Nd(seq));
+                } else {
+                    output.addAll(seq2NdList(seq));
+                }
             } else {
                 throw new UnsupportedOperationException("Unsupported output type! " + r.getKey());
             }
@@ -146,40 +151,36 @@ public class OrtSymbolBlock extends AbstractSymbolBlock implements AutoCloseable
     @SuppressWarnings("unchecked")
     private NDArray seq2Nd(OnnxSequence seq) {
         try {
-            List<Object> values = seq.getValue();
-            OnnxJavaType type = seq.getInfo().sequenceType;
-            Shape shape = new Shape(values.size());
+            List<OnnxMap> values = (List<OnnxMap>) seq.getValue();
             DataType dp;
-            SequenceInfo info = seq.getInfo();
-            if (info.sequenceOfMaps) {
-                type = info.mapInfo.valueType;
-                List<Object> valuesTmp = new ArrayList<>();
-                values.forEach(map -> valuesTmp.addAll(((Map<Object, Object>) map).values()));
-                shape = new Shape(values.size(), valuesTmp.size() / values.size());
-                values = valuesTmp;
+            List<Object> finalData = new ArrayList<>();
+            OnnxJavaType type = seq.getInfo().mapInfo.valueType;
+            for (OnnxMap map : values) {
+                finalData.addAll(((Map<Object, Object>) map.getValue()).values());
             }
-            ByteBuffer buffer = ByteBuffer.allocate(values.size() * type.size);
+            Shape shape = new Shape(values.size(), finalData.size() / values.size());
+            ByteBuffer buffer = ByteBuffer.allocate(finalData.size() * type.size);
             switch (type) {
                 case FLOAT:
-                    values.forEach(ele -> buffer.putFloat((Float) ele));
+                    finalData.forEach(ele -> buffer.putFloat((Float) ele));
                     buffer.rewind();
                     return manager.create(buffer.asFloatBuffer(), shape, DataType.FLOAT32);
                 case DOUBLE:
-                    values.forEach(ele -> buffer.putDouble((Double) ele));
+                    finalData.forEach(ele -> buffer.putDouble((Double) ele));
                     buffer.rewind();
                     return manager.create(buffer.asDoubleBuffer(), shape, DataType.FLOAT64);
                 case BOOL:
                 case INT8:
                     dp = (type == OnnxJavaType.BOOL) ? DataType.BOOLEAN : DataType.INT8;
-                    values.forEach(ele -> buffer.put((Byte) ele));
+                    finalData.forEach(ele -> buffer.put((Byte) ele));
                     buffer.rewind();
                     return manager.create(buffer, shape, dp);
                 case INT32:
-                    values.forEach(ele -> buffer.putInt((Integer) ele));
+                    finalData.forEach(ele -> buffer.putInt((Integer) ele));
                     buffer.rewind();
                     return manager.create(buffer.asIntBuffer(), shape, DataType.INT32);
                 case INT64:
-                    values.forEach(ele -> buffer.putLong((Long) ele));
+                    finalData.forEach(ele -> buffer.putLong((Long) ele));
                     buffer.rewind();
                     return manager.create(buffer.asLongBuffer(), shape, DataType.INT64);
                 default:
@@ -190,6 +191,18 @@ public class OrtSymbolBlock extends AbstractSymbolBlock implements AutoCloseable
         }
     }
 
+    private NDList seq2NdList(OnnxSequence sequence) {
+        try {
+            NDList list = new NDList();
+            for (OnnxValue value : sequence.getValue()) {
+                list.add(manager.createInternal((OnnxTensor) value));
+            }
+            return list;
+        } catch (OrtException e) {
+            throw new EngineException(e);
+        }
+    }
+
     /** {@inheritDoc} */
     @Override
     public void close() {
diff --git a/gradle.properties b/gradle.properties
index 275aaed1d..7f754b706 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -18,12 +18,12 @@ tensorflow_version=2.7.0
 tflite_version=2.6.2
 dlr_version=1.6.0
 trt_version=8.4.1
-onnxruntime_version=1.12.1
+onnxruntime_version=1.13.1
 paddlepaddle_version=2.2.2
 sentencepiece_version=0.1.96
 tokenizers_version=0.12.0
 fasttext_version=0.9.2
-xgboost_version=1.6.1
+xgboost_version=1.6.2
 lightgbm_version=3.2.110
 rapis_version=22.04.0
 


Test patch:
diff --git a/engines/ml/xgboost/src/test/java/ai/djl/ml/xgboost/XgbModelTest.java b/engines/ml/xgboost/src/test/java/ai/djl/ml/xgboost/XgbModelTest.java
index 8dffbdbbc..e354f43ad 100644
--- a/engines/ml/xgboost/src/test/java/ai/djl/ml/xgboost/XgbModelTest.java
+++ b/engines/ml/xgboost/src/test/java/ai/djl/ml/xgboost/XgbModelTest.java
@@ -54,7 +54,7 @@ public class XgbModelTest {
     @Test
     public void testVersion() {
         Engine engine = Engine.getEngine("XGBoost");
-        Assert.assertEquals("1.6.1", engine.getVersion());
+        Assert.assertEquals("1.6.2", engine.getVersion());
     }
 
     /*