Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pruning_with_keras.ipynb issue #7

Closed
kuri-leo opened this issue Jun 10, 2019 · 3 comments
Closed

pruning_with_keras.ipynb issue #7

kuri-leo opened this issue Jun 10, 2019 · 3 comments
Assignees
Labels
technique:pruning Regarding tfmot.sparsity.keras APIs and docs

Comments

@kuri-leo
Copy link

Hi,

When I run official guide in Colab, the guide raised an error of "unsupported op(FusedBatchNormV3)" during running Convert the model with TFLiteConverter.

It seems that this op was brought to TF days ago --> as the instruction says, I install the nightly-preview, may a stable version is much suitable?

Attached is the full log:

---------------------------------------------------------------------------
ConverterError                            Traceback (most recent call last)
<ipython-input-29-62dfa126ef60> in <module>()
      1 tflite_model_file = '/tmp/sparse_mnist.tflite'
      2 converter = tf.lite.TFLiteConverter.from_keras_model_file(pruned_keras_file)
----> 3 tflite_model = converter.convert()
      4 with open(tflite_model_file, 'wb') as f:
      5   f.write(tflite_model)

2 frames
/usr/local/lib/python3.6/dist-packages/tensorflow_core/lite/python/convert.py in toco_convert_protos(model_flags_str, toco_flags_str, input_data_str)
    170       stderr = _try_convert_to_unicode(stderr)
    171       raise ConverterError(
--> 172           "TOCO failed. See console for info.\n%s\n%s\n" % (stdout, stderr))
    173   finally:
    174     # Must manually cleanup files.

ConverterError: TOCO failed. See console for info.
WARNING: Logging before flag parsing goes to stderr.
W0610 10:27:17.025386 140352251447168 deprecation_wrapper.py:118] From /usr/local/lib/python3.6/dist-packages/tensorflow/__init__.py:94: The name tf.AUTO_REUSE is deprecated. Please use tf.compat.v1.AUTO_REUSE instead.

W0610 10:27:17.025773 140352251447168 deprecation_wrapper.py:118] From /usr/local/lib/python3.6/dist-packages/tensorflow/__init__.py:94: The name tf.AttrValue is deprecated. Please use tf.compat.v1.AttrValue instead.

W0610 10:27:17.025909 140352251447168 deprecation_wrapper.py:118] From /usr/local/lib/python3.6/dist-packages/tensorflow/__init__.py:94: The name tf.COMPILER_VERSION is deprecated. Please use tf.version.COMPILER_VERSION instead.

W0610 10:27:17.026037 140352251447168 deprecation_wrapper.py:118] From /usr/local/lib/python3.6/dist-packages/tensorflow/__init__.py:94: The name tf.CXX11_ABI_FLAG is deprecated. Please use tf.sysconfig.CXX11_ABI_FLAG instead.

W0610 10:27:17.026163 140352251447168 deprecation_wrapper.py:118] From /usr/local/lib/python3.6/dist-packages/tensorflow/__init__.py:94: The name tf.ConditionalAccumulator is deprecated. Please use tf.compat.v1.ConditionalAccumulator instead.

2019-06-10 10:27:17.071062: I tensorflow/lite/toco/import_tensorflow.cc:1336] Converting unsupported operation: FusedBatchNormV3
2019-06-10 10:27:17.093824: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 35 operators, 57 arrays (0 quantized)
2019-06-10 10:27:17.094147: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 35 operators, 57 arrays (0 quantized)
2019-06-10 10:27:17.094683: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 1: 10 operators, 29 arrays (0 quantized)
2019-06-10 10:27:17.118420: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 2: 9 operators, 28 arrays (0 quantized)
2019-06-10 10:27:17.118589: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 3: 8 operators, 26 arrays (0 quantized)
2019-06-10 10:27:17.118704: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Group bidirectional sequence lstm/rnn: 8 operators, 26 arrays (0 quantized)
2019-06-10 10:27:17.118783: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before dequantization graph transformations: 8 operators, 26 arrays (0 quantized)
2019-06-10 10:27:17.118915: I tensorflow/lite/toco/allocate_transient_arrays.cc:345] Total transient array allocated size: 125440 bytes, theoretical optimal value: 125440 bytes.
2019-06-10 10:27:17.119187: E tensorflow/lite/toco/toco_tooling.cc:462] We are continually in the process of adding support to TensorFlow Lite for more ops. It would be helpful if you could inform us of how this conversion went by opening a github issue at https://github.com/tensorflow/tensorflow/issues/new?template=40-tflite-op-request.md
 and pasting the following:

Some of the operators in the model are not supported by the standard TensorFlow Lite runtime. If those are native TensorFlow operators, you might be able to use the extended runtime by passing --enable_select_tf_ops, or by setting target_ops=TFLITE_BUILTINS,SELECT_TF_OPS when calling tf.lite.TFLiteConverter(). Otherwise, if you have a custom implementation for them you can disable this error with --allow_custom_ops, or by setting allow_custom_ops=True when calling tf.lite.TFLiteConverter(). Here is a list of builtin operators you are using: CONV_2D, DEPTHWISE_CONV_2D, FULLY_CONNECTED, MAX_POOL_2D, SOFTMAX. Here is a list of operators for which you will need custom implementations: FusedBatchNormV3.
Traceback (most recent call last):
  File "/usr/local/bin/toco_from_protos", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 59, in main
    app.run(main=execute, argv=[sys.argv[0]] + unparsed)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 33, in execute
    output_str = tensorflow_wrap_toco.TocoConvert(model_str, toco_str, input_str)
Exception: We are continually in the process of adding support to TensorFlow Lite for more ops. It would be helpful if you could inform us of how this conversion went by opening a github issue at https://github.com/tensorflow/tensorflow/issues/new?template=40-tflite-op-request.md
 and pasting the following:

Some of the operators in the model are not supported by the standard TensorFlow Lite runtime. If those are native TensorFlow operators, you might be able to use the extended runtime by passing --enable_select_tf_ops, or by setting target_ops=TFLITE_BUILTINS,SELECT_TF_OPS when calling tf.lite.TFLiteConverter(). Otherwise, if you have a custom implementation for them you can disable this error with --allow_custom_ops, or by setting allow_custom_ops=True when calling tf.lite.TFLiteConverter(). Here is a list of builtin operators you are using: CONV_2D, DEPTHWISE_CONV_2D, FULLY_CONNECTED, MAX_POOL_2D, SOFTMAX. Here is a list of operators for which you will need custom implementations: FusedBatchNormV3.

thanks!

@alanchiao alanchiao self-assigned this Jun 10, 2019
@alanchiao
Copy link

Thanks for reporting this issue.

There is a in-flight change that'll add conversion support for FusedBatchNormV3, after which the tutorial should start working again.

You're right that a stable version would be preferable. Our pruning API has dependencies on changes only introduced in TF 1.14, which is in the midst of release. Once that release finishes, we'll update everything to use 1.14 where possible.

@alanchiao
Copy link

Conversion support has been added in tensorflow/tensorflow@ce690f7. Things will work tomorrow (after the next nightly release). Thanks!

@andreydung
Copy link

@alanchiao I'm wondering if there any update on this? Tried tf-nightly-2.0 but still got the same error: FusedBatchNormV3 and AddV2 not supported on TFLite.

import tensorflow as tf
model = tf.keras.applications.MobileNetV2(
    weights="imagenet", input_shape=(224, 224, 3))

# Convert the model.
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()

@alanchiao alanchiao added the technique:pruning Regarding tfmot.sparsity.keras APIs and docs label Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technique:pruning Regarding tfmot.sparsity.keras APIs and docs
Projects
None yet
Development

No branches or pull requests

3 participants