System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow):NO
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): MacOS 10.13.6
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: BlackBerry KEY2
- TensorFlow installed from (source or binary): source
- TensorFlow version (use command below): master branch last commit is 78f5862
- Python version:3.6.3
- Bazel version (if compiling from source):0.15.2
- GCC/Compiler version (if compiling from source): NDK r17 toolchain
- CUDA/cuDNN version:NA
- GPU model and memory:NA
- Exact command to reproduce:
Describe the problem
I download the pre-trained modals with MobileNet-v2 from mobilenetv2_coco_voc_trainaug. covered model to tflite then load into android application, I see internal error at OP Pad on prepare.
Source code / logs
using below command to cover the model without any errors:
bazel run //tensorflow/contrib/lite/toco:toco -- \
--input_file=/tmp/frozen_inference_graph.pb \
--output_file=/tmp/optimized_graph.tflite \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--input_type=QUANTIZED_UINT8 \
--input_arrays=ImageTensor \
--output_arrays=SemanticPredictions \
--input_shapes=1,513,513,3
below command to build tensorflow-lite.aar
bazel build --cxxopt='--std=c++11' -c opt \
--fat_apk_cpu=x86,x86_64,arm64-v8a,armeabi-v7a \
//tensorflow/contrib/lite/java:tensorflow-lite
Then I load optimized_graph.tflite and tensorflow-lite.aar into Android application project
private static final int DIM_PIXEL_SIZE = 3;
static final int DIM_IMG_SIZE_X = 513;
static final int DIM_IMG_SIZE_Y = 513;
tflite = new Interpreter(loadModelFile(activity));
imgData =
ByteBuffer.allocateDirect(
DIM_IMG_SIZE_X * DIM_IMG_SIZE_Y * DIM_PIXEL_SIZE);
imgData.order(ByteOrder.nativeOrder());
outputs = new int[DIM_IMG_SIZE_X * DIM_IMG_SIZE_Y];
/** Memory-map the model file in Assets. */
private MappedByteBuffer loadModelFile(Activity activity) throws IOException {
AssetFileDescriptor fileDescriptor = activity.getAssets().openFd(MODEL_PATH);
FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor());
FileChannel fileChannel = inputStream.getChannel();
long startOffset = fileDescriptor.getStartOffset();
long declaredLength = fileDescriptor.getDeclaredLength();
return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength);
}
run Interpreter
tflite.run(imgData, outputs);
Error Logs:
07-31 16:20:36.144 25819-25974/android.example.com.tflitecamerademo E/AndroidRuntime: FATAL EXCEPTION: CameraBackground
Process: android.example.com.tflitecamerademo, PID: 25819
java.lang.IllegalArgumentException: Internal error: Failed to run on the given Interpreter: tensorflow/contrib/lite/kernels/pad.cc:96 op_context.dims != 4 (3 != 4)Node number 24 (PAD) failed to prepare.
at org.tensorflow.lite.NativeInterpreterWrapper.run(Native Method)
at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:130)
at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:168)
at org.tensorflow.lite.Interpreter.run(Interpreter.java:145)
System information
Describe the problem
I download the pre-trained modals with MobileNet-v2 from mobilenetv2_coco_voc_trainaug. covered model to tflite then load into android application, I see internal error at OP Pad on prepare.
Source code / logs
using below command to cover the model without any errors:
below command to build tensorflow-lite.aar
Then I load optimized_graph.tflite and tensorflow-lite.aar into Android application project
run Interpreter
Error Logs: