Repository: deepjavalibrary/djl
Pull request #1860 (2022-08-02 22:44:41)

add android CI tests
## Description ##

Fix cAT and add android CI testing



Patch:
diff --git a/.github/workflows/continuous.yml b/.github/workflows/continuous.yml
index f7b945fcc..bce696a0d 100644
--- a/.github/workflows/continuous.yml
+++ b/.github/workflows/continuous.yml
@@ -9,6 +9,7 @@ on:
       - "**.html"
       - "**.js"
       - "**.css"
+      - "android/**"
 
 jobs:
   build:
diff --git a/.github/workflows/nightly_android.yml b/.github/workflows/nightly_android.yml
new file mode 100644
index 000000000..fcf43771d
--- /dev/null
+++ b/.github/workflows/nightly_android.yml
@@ -0,0 +1,29 @@
+name: Continuous Android
+
+on:
+  pull_request:
+    paths:
+      - "android/**"
+
+jobs:
+  build:
+    runs-on: macos-latest
+    strategy:
+      matrix:
+        api-level: [ 26 ]
+    steps:
+      - uses: actions/checkout@v3
+      - name: Set up JDK 11
+        uses: actions/setup-java@v1
+        with:
+          java-version: 11
+      - name: Gradle cache
+        uses: gradle/gradle-build-action@v2
+      - name: run tests
+        uses: reactivecircus/android-emulator-runner@v2
+        with:
+          api-level: ${{ matrix.api-level }}
+          force-avd-creation: false
+          emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
+          disable-animations: true
+          script: cd android/core && ./gradlew cAT
diff --git a/gradle.properties b/gradle.properties
index 429fb42dd..d4c487129 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,5 +1,9 @@
 org.gradle.daemon=true
-org.gradle.jvmargs=-Xmx1024M
+org.gradle.jvmargs=-Xmx1024M --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
+  --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
+  --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
+  --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
+  --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
 
 systemProp.org.gradle.internal.http.socketTimeout=120000
 systemProp.org.gradle.internal.http.connectionTimeout=60000
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index fdd2345a0..cf75dbb03 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip


Test patch:
diff --git a/android/core/src/androidTest/java/ai/djl/android/core/ModelLoadingTest.java b/android/core/src/androidTest/java/ai/djl/android/core/ModelLoadingTest.java
index ea655a6bd..73277e972 100644
--- a/android/core/src/androidTest/java/ai/djl/android/core/ModelLoadingTest.java
+++ b/android/core/src/androidTest/java/ai/djl/android/core/ModelLoadingTest.java
@@ -22,6 +22,7 @@ import ai.djl.inference.Predictor;
 import ai.djl.modality.Classifications;
 import ai.djl.modality.cv.Image;
 import ai.djl.modality.cv.ImageFactory;
+import ai.djl.modality.cv.transform.Resize;
 import ai.djl.modality.cv.transform.ToTensor;
 import ai.djl.modality.cv.translator.ImageClassificationTranslator;
 import ai.djl.repository.zoo.Criteria;
@@ -34,22 +35,26 @@ public class ModelLoadingTest {
 
     @Test
     public void testModelLoading() throws IOException, ModelException, TranslateException {
-        ImageClassificationTranslator translator = ImageClassificationTranslator.builder()
+
+        String modelUrl = "https://resources.djl.ai/demo/pytorch/traced_resnet18.zip";
+        ImageClassificationTranslator.builder()
+            .addTransform(new Resize(224, 224))
+            .addTransform(new ToTensor())
+            .optApplySoftmax(true)
+            .build();
+        Criteria<Image, Classifications> criteria = Criteria.builder()
+            .setTypes(Image.class, Classifications.class)
+            .optModelUrls(modelUrl)
+            .optTranslator(ImageClassificationTranslator.builder()
+                .addTransform(new Resize(224, 224))
                 .addTransform(new ToTensor())
-                .optFlag(Image.Flag.GRAYSCALE)
-                .optApplySoftmax(true)
-                .build();
-        Criteria<Image, Classifications> criteria =
-                Criteria.builder()
-                        .setTypes(Image.class, Classifications.class)
-                        .optModelUrls("https://djl-ai.s3.amazonaws.com/resources/demo/pytorch/doodle_mobilenet.zip")
-                        .optTranslator(translator)
-                        .build();
-        Image image = ImageFactory.getInstance().fromUrl("https://resources.djl.ai/images/0.png");
+                .optApplySoftmax(true).build())
+            .build();
+        Image image = ImageFactory.getInstance().fromUrl("https://resources.djl.ai/images/kitten.jpg");
         try (ZooModel<Image, Classifications> model = ModelZoo.loadModel(criteria);
              Predictor<Image, Classifications> predictor = model.newPredictor()) {
             Classifications result = predictor.predict(image);
-            Assert.assertEquals("matches", result.best().getClassName());
+            Assert.assertEquals("n02124075 Egyptian cat", result.best().getClassName());
         }
     }
 }