Repository: deepjavalibrary/djl
Pull request #1462 (2022-01-13 18:01:17)

[tensorflow] Upgrade tensorflow to 2.7.0
Change-Id: I20ba464309c52564cb75698de72433b9749841bf

## 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/1462?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) Report
> Merging [#1462](https://codecov.io/gh/deepjavalibrary/djl/pull/1462?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary) (b4ba395) into [master](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) (bb5073f) will **decrease** coverage by `1.42%`.
> The diff coverage is `48.19%`.

[![Impacted file tree graph](https://codecov.io/gh/deepjavalibrary/djl/pull/1462/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/1462?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary)

```diff
@@             Coverage Diff              @@
##             master    #1462      +/-   ##
============================================
- Coverage     72.08%   70.66%   -1.43%     
- Complexity     5126     5297     +171     
============================================
  Files           473      493      +20     
  Lines         21970    23222    +1252     
  Branches       2351     2533     +182     
============================================
+ Hits          15838    16410     +572     
- Misses         4925     5534     +609     
- Partials       1207     1278      +71     
```


| [Impacted Files](https://codecov.io/gh/deepjavalibrary/djl/pull/1462?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/1462/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: |
| [...i/djl/modality/cv/translator/BigGANTranslator.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1462/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% <ø> (-5.24%)` | :arrow_down: |
| [...odality/cv/translator/BigGANTranslatorFactory.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1462/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvQmlnR0FOVHJhbnNsYXRvckZhY3RvcnkuamF2YQ==) | `33.33% <0.00%> (+8.33%)` | :arrow_up: |
| [...nslator/InstanceSegmentationTranslatorFactory.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1462/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvSW5zdGFuY2VTZWdtZW50YXRpb25UcmFuc2xhdG9yRmFjdG9yeS5qYXZh) | `14.28% <0.00%> (-3.90%)` | :arrow_down: |
| [.../modality/cv/translator/YoloTranslatorFactory.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1462/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvWW9sb1RyYW5zbGF0b3JGYWN0b3J5LmphdmE=) | `8.33% <0.00%> (-1.67%)` | :arrow_down: |
| [...i/djl/modality/cv/translator/YoloV5Translator.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1462/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvWW9sb1Y1VHJhbnNsYXRvci5qYXZh) | `5.69% <0.00%> (ø)` | |
| [...odality/cv/translator/YoloV5TranslatorFactory.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1462/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL21vZGFsaXR5L2N2L3RyYW5zbGF0b3IvWW9sb1Y1VHJhbnNsYXRvckZhY3RvcnkuamF2YQ==) | `8.33% <0.00%> (-1.67%)` | :arrow_down: |
| [...pi/src/main/java/ai/djl/ndarray/BytesSupplier.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1462/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL25kYXJyYXkvQnl0ZXNTdXBwbGllci5qYXZh) | `54.54% <0.00%> (-12.13%)` | :arrow_down: |
| [...i/src/main/java/ai/djl/ndarray/NDArrayAdapter.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1462/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL25kYXJyYXkvTkRBcnJheUFkYXB0ZXIuamF2YQ==) | `15.23% <0.00%> (-0.83%)` | :arrow_down: |
| [...l/training/loss/SigmoidBinaryCrossEntropyLoss.java](https://codecov.io/gh/deepjavalibrary/djl/pull/1462/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary#diff-YXBpL3NyYy9tYWluL2phdmEvYWkvZGpsL3RyYWluaW5nL2xvc3MvU2lnbW9pZEJpbmFyeUNyb3NzRW50cm9weUxvc3MuamF2YQ==) | `64.00% <0.00%> (ø)` | |
| ... and [162 more](https://codecov.io/gh/deepjavalibrary/djl/pull/1462/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/1462?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/1462?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=deepjavalibrary). Last update [995718e...b4ba395](https://codecov.io/gh/deepjavalibrary/djl/pull/1462?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/engines/tensorflow/tensorflow-api/build.gradle b/engines/tensorflow/tensorflow-api/build.gradle
index 6645c82d9..5e564e128 100644
--- a/engines/tensorflow/tensorflow-api/build.gradle
+++ b/engines/tensorflow/tensorflow-api/build.gradle
@@ -5,12 +5,9 @@ configurations {
 }
 
 dependencies {
-    // javacpp bug fix https://github.com/bytedeco/javacpp/commit/7f27899578dfa18e22738a3dd49701e1806b464a
     api "org.bytedeco:javacpp:${javacpp_version}"
     api "com.google.protobuf:protobuf-java:${protobuf_version}"
-    api("org.tensorflow:tensorflow-core-api:0.3.1") {
-        exclude group: "org.bytedeco", module: "javacpp"
-    }
+    api "org.tensorflow:tensorflow-core-api:0.4.0"
 
     exclusion "org.bytedeco:javacpp:${javacpp_version}"
     exclusion "com.google.protobuf:protobuf-java:${protobuf_version}"
diff --git a/engines/tensorflow/tensorflow-engine/src/main/java/ai/djl/tensorflow/engine/TfNDManager.java b/engines/tensorflow/tensorflow-engine/src/main/java/ai/djl/tensorflow/engine/TfNDManager.java
index c5c26535b..24af0248c 100644
--- a/engines/tensorflow/tensorflow-engine/src/main/java/ai/djl/tensorflow/engine/TfNDManager.java
+++ b/engines/tensorflow/tensorflow-engine/src/main/java/ai/djl/tensorflow/engine/TfNDManager.java
@@ -178,8 +178,8 @@ public class TfNDManager extends BaseNDManager {
                 NDArray kArr = create(k);
                 NDArray rowsArr = create(rows);
                 NDArray colsArr = create(cols);
-                NDArray zeros = zeros(new Shape(1))) {
-            return opExecutor("MatrixDiagV2")
+                NDArray zeros = zeros(new Shape(), dataType)) {
+            return opExecutor("MatrixDiagV3")
                     .addInput(ones)
                     .addInput(kArr)
                     .addInput(rowsArr)
diff --git a/engines/tensorflow/tensorflow-native/build.gradle b/engines/tensorflow/tensorflow-native/build.gradle
index 60ac2abcd..f42c3d75c 100644
--- a/engines/tensorflow/tensorflow-native/build.gradle
+++ b/engines/tensorflow/tensorflow-native/build.gradle
@@ -13,11 +13,11 @@ configurations {
 }
 
 dependencies {
-    download "org.tensorflow:tensorflow-core-api:0.3.1:linux-x86_64-gpu"
-    download "org.tensorflow:tensorflow-core-api:0.3.1:linux-x86_64"
-    download "org.tensorflow:tensorflow-core-api:0.3.1:macosx-x86_64"
-    download "org.tensorflow:tensorflow-core-api:0.3.1:windows-x86_64"
-    download "org.tensorflow:tensorflow-core-api:0.3.1:windows-x86_64-gpu"
+    download "org.tensorflow:tensorflow-core-api:0.4.0:linux-x86_64-gpu"
+    download "org.tensorflow:tensorflow-core-api:0.4.0:linux-x86_64"
+    download "org.tensorflow:tensorflow-core-api:0.4.0:macosx-x86_64"
+    download "org.tensorflow:tensorflow-core-api:0.4.0:windows-x86_64"
+    download "org.tensorflow:tensorflow-core-api:0.4.0:windows-x86_64-gpu"
 }
 
 task uploadTensorflowNativeLibs() {
diff --git a/gradle.properties b/gradle.properties
index 412acc01c..6848c7ff6 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -10,7 +10,7 @@ systemProp.org.gradle.internal.publish.checksums.insecure=true
 djl_version=0.15.0
 mxnet_version=1.8.0
 pytorch_version=1.10.0
-tensorflow_version=2.4.1
+tensorflow_version=2.7.0
 tflite_version=2.6.2
 dlr_version=1.6.0
 trt_version=8.0.1


Test patch:
diff --git a/engines/tensorflow/tensorflow-engine/src/test/java/ai/djl/tensorflow/integration/TfCoverageTest.java b/engines/tensorflow/tensorflow-engine/src/test/java/ai/djl/tensorflow/integration/TfCoverageTest.java
index 76cce5c0d..dede06953 100644
--- a/engines/tensorflow/tensorflow-engine/src/test/java/ai/djl/tensorflow/integration/TfCoverageTest.java
+++ b/engines/tensorflow/tensorflow-engine/src/test/java/ai/djl/tensorflow/integration/TfCoverageTest.java
@@ -12,6 +12,7 @@
  */
 package ai.djl.tensorflow.integration;
 
+import ai.djl.engine.Engine;
 import ai.djl.tensorflow.engine.TfEngine;
 import ai.djl.testing.CoverageUtils;
 import java.io.IOException;
@@ -23,6 +24,7 @@ public class TfCoverageTest {
     @Test
     public void test() throws IOException, ReflectiveOperationException, URISyntaxException {
         // tensorflow-engine
+        Engine.getEngine("TensorFlow");
         CoverageUtils.testGetterSetters(TfEngine.class);
     }
 }