tensorflow: [TFlite]: Failed to instantiate the interpreter with a StyleGAN2 generator model
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: Pixel4, Samsung Galaxy S9+
- TensorFlow installed from (source or binary): binary
- TensorFlow version on desktop (use command below): tensorflow 2.2.0 + tensorflow-gpu 2.2.0
- TensorFlow lite version on mobile: tensorflow-lite:0.0.0-nightly + tensorflow-lite-gpu:0.0.0-nightly
- Python version: 3.6.10
- Bazel version (if compiling from source): NA
- GCC/Compiler version (if compiling from source): NA
- CUDA/cuDNN version: V10.2.89
- GPU model and memory: 4* TITAN RTX 24GB
Describe the current behavior
I used tf.compat.v1.lite.TFLiteConverter.from_session
to convert StyleGAN2 generator in Tensorflow lite format. the conversion gives no error and no warning.
The option used for the conversion are as follow:
converter.optimizations = [tf.lite.Optimize.DEFAULT] converter.target_ops = [tf.lite.OpsSet.TFLITE_BUILTINS]
On phone, the interpreter instanciation fails when running on CPU: tflite = new Interpreter(tfliteModel, tfliteOptions);
gives the following error:
Caused by: java.lang.IllegalStateException: Internal error: Unexpected failure when preparing tensor allocations: tensorflow/lite/kernels/pad.cc:111 op_context.dims <= reference_ops::PadKernelMaxDimensionCount() was not true. Node number 239 (PAD) failed to prepare.
When trying to use GPU or NNAPI delegates, i have the same kind of error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.helloworld/org.pytorch.helloworld.MainActivity}: java.lang.IllegalArgumentException: Internal error: Failed to apply delegate: tensorflow/lite/kernels/pad.cc:111 op_context.dims <= reference_ops::PadKernelMaxDimensionCount() was not true. Node number 239 (PAD) failed to prepare.
Describe the expected behavior I expect the model to be able to execute whatever target (CPU/GPU/NNAPI) is used, but most likely on NNAPI or GPU to get the best performances.
Standalone code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/Jupyter/any notebook.
Other info / logs
I tried several things to cope with this issue. When using the following option:
converter.target_ops=SELECT_TF_OPS
It is working on CPU, but fails with another error on GPU:
ignoring failed delegate application: java.lang.IllegalArgumentException: Internal error: Failed to apply delegate: Attempting to use a delegate that only supports static-sized tensors with a graph that has dynamic-sized tensors.
I guess this is because these target ops are not compatible with GPU and NNAPI delegates.
I also tried to use converter v2 using the following method:
converter = tf.lite.TFLiteConverter.from_concrete_functions([func])
But the model size is very huge (624MB instead of 110MB for converter.v1) and i faced the same error when running on mobile:
Caused by: java.lang.IllegalStateException: Internal error: Unexpected failure when preparing tensor allocations: tensorflow/lite/kernels/pad.cc:111 op_context.dims <= reference_ops::PadKernelMaxDimensionCount() was not true. Node number 221 (PAD) failed to prepare.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 35 (17 by maintainers)
FYI, Flex + GPU combination is now working at tf-nightly version if the graph has only static shapes.