1

I have made an image classification model using Keras in Python which is in ".h5" format. I am trying to use it in my Android application using Deeplearning4j.

I am facing an issue when I try to do image classification by loading a Mat image using NativeImageLoader constructor. The code is as follows :

NativeImageLoader nativeImageLoader = new NativeImageLoader(60, 60, 3);
INDArray image = nativeImageLoader.asMatrix(testImage);   // testImage is of Mat format

// 0-255 to 0-1
DataNormalization scaler = new ImagePreProcessingScaler(0, 1);
scaler.transform(image);
// Pass through to neural Net
INDArray output = model.output(image);
INDArray labels = model.getLabels();

When the app builds it gives an error at the second line of the code above i.e INDArray image = nativeImageLoader.asMatrix(testImage);

I get the following error when I build the apk:

Error:(1109, 51) error: cannot access BufferedImage
class file for java.awt.image.BufferedImage not found

I tried to find the solution but this and this says that AWT package is not supported in Android.

Please help me with a solution or a work around. Thank you.

Community
  • 1
  • 1
Vikas
  • 116
  • 10

1 Answers1

0

You have to refactor Deeplearning4j to port the java-awt specific lib to a platform independat java lib with platfrom specific handlers for android and awt/j2se

In the java Deeplearning4j lib you have to hide all java-awt specific classes (like BufferedImage) behind an interface IBitmap and implement that interface for j2se and independantly for Android.

I have done this successfully for exif/icc/ipc metadata processing and implemented interface pixymeta-lib/.../IBitmap.java with implementation for j2se pixymeta-j2se-lib/.../j2se/BitmapNative.java and android pixymeta-android-lib/.../android/BitmapNative.java

So I have these packages

  • pixymeta-lib
    • transformed platform independant lib where all awt-references are replaced by IBitmap interface
  • pixymeta-j2se-lib
    • awt/j2se implementation of IBitmap
  • pixymeta-android-lib
    • android implementation of IBitmap

Part of this answer is copied from here

Community
  • 1
  • 1
k3b
  • 14,517
  • 7
  • 53
  • 85