text:
How can I convert custom pb file to tflite?

System information

Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
OS Platform and Distribution (e.g., Linux Ubuntu 16.04):Linux Ubuntu 16.04
Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:-
TensorFlow installed from (source or binary): binary
TensorFlow version (use command below):1.15.0
Python version:2.7.12
Bazel version (if compiling from source):0.19.2
GCC/Compiler version (if compiling from source):-
CUDA/cuDNN version:-
GPU model and memory: no GPU / 8GB memory(VM)

I tried to convert frozen & custom .pb file(Specifically, SSD) to .tflite with toco tools.
but I get some error & core dump.(below)
convert command & results is below:*****************************************************************
$   (path)/.local/bin/toco
--input_file=(path)/ssd1.pb
--output_file=(path)/ssd2.tflite
--input_format=TENSORFLOW_GRAPHDEF
--output_format=TFLITE
--input_shape=1,300,300,3
--input_array=input_13
--output_array=predictions/concat
--input_data_type=FLOAT
--inference_type=FLOAT
--allow_custom_ops
2018-12-04 11:39:52.856924: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: Prod
2018-12-04 11:39:52.857097: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: Prod
2018-12-04 11:39:52.857156: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: Prod
2018-12-04 11:39:52.857214: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: Prod
2018-12-04 11:39:52.857271: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: Prod
2018-12-04 11:39:52.857389: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: Prod
2018-12-04 11:39:52.857474: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: Prod
2018-12-04 11:39:52.857533: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: Prod
2018-12-04 11:39:52.857586: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: Prod
2018-12-04 11:39:52.857638: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: Prod
2018-12-04 11:39:52.857720: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: StridedSlice
2018-12-04 11:39:52.857784: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: StridedSlice
2018-12-04 11:39:52.857878: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: StridedSlice
2018-12-04 11:39:52.857976: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: StridedSlice
2018-12-04 11:39:52.858055: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: StridedSlice
2018-12-04 11:39:52.858156: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: StridedSlice
2018-12-04 11:39:52.858226: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: StridedSlice
2018-12-04 11:39:52.858287: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: StridedSlice
2018-12-04 11:39:52.858337: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: StridedSlice
2018-12-04 11:39:52.858382: I   tensorflow/contrib/lite/toco/import_tensorflow.cc:1057] Converting   unsupported operation: Exp
2018-12-04 11:39:52.862297: I   tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39]   Before general graph transformations: 309 operators, 499 arrays (0 quantized)
2018-12-04 11:39:53.124941: F   tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:785]   Check failed: crops_data[1] == 0 (5 vs. 0)
Coredump

model summarize is below:(trained environmental is keras. and I converted .json & .h5 to .pb)*********
$   bazel-bin/tensorflow/tools/graph_transforms/summarize_graph
--in_graph=(path)/ssd1.pb
Found 1 possible inputs: (name=input_13,   type=float(1), shape=[?,300,300,3])
No variables spotted.
Found 1 possible outputs:   (name=predictions/concat, op=ConcatV2)
Found 25824093 (25.82M) const   parameters, 0 (0) variable parameters, and 0 control_edges
Op types used: 189 Const, 73 Identity,   33 BiasAdd, 31 Conv2D, 21 Relu, 19 Pack, 19 StridedSlice, 19 Shape, 13   Reshape, 10 Prod, 6 Tile, 6 ExpandDims, 5 MaxPool, 4 ConcatV2, 2 Sum, 2 Mul,   2 MatMul, 1 RealDiv, 1 Sub, 1 Square, 1 SpaceToBatchND, 1 Exp, 1 Rsqrt, 1   Placeholder, 1 Pad, 1 BatchToSpaceND, 1 Mean, 1 Maximum, 1 Max
To use with   tensorflow/tools/benchmark:benchmark_model try these arguments:
bazel run   tensorflow/tools/benchmark:benchmark_model --
--graph=(path)/ssd1.pb --show_flops   --input_layer=input_13
--input_layer_type=float   --input_layer_shape=-1,300,300,3 --output_layer=predictions/concat

How can I convert pb file to tflite?
or Is Tensorflow lite unsupported this problem still now?
or process of convert pb file has something wrong?
(because I feel that the number of output_layer is small...)

It looks like you have some tflite unsupported ops in your model. Please refer TensorFlow Lite & TensorFlow Compatibility Guide

Thanks for your answer.
I confirmed the Compatibility Guide.
If my model included unsupported function , How I convert pb to tflite?
Should I reprogramming code without unsupported function?(...I don't have confidence to realize it)
or Should I abandon converting ? (...Implement on mobile as tensorflow-moblile(=pb))
or Should I wait support?
Which reaction do you think best?

Adding @liyunlu0618 She may know more.

Please take a look at this and give it a try:
https://www.tensorflow.org/lite/using_select_tf_ops
This is an effort meant for expanding the op support in tflite. In theory it should be able to convert any tensorflow op. It's still in a 'preview' phase and let us know any issue you run into. Thanks!

Can you try again with tflite_convert instead of toco?
Remove the "--allow_custom_ops" flag.

Sorry to late replying the advise.

I couldn't use "tflite_covert" command . (because of my tensorflow version 1.5.1(<1.9)?)
using toco command and removing " --allow_custom_ops ", result was same.(happened core dump)

I will confirm how to use the "tflite_convert" command and confirm that it can be changed.
If there is progress, we will post again.

I could convert pb file to tflite file by using "tflite_convert" command.
Initially, the "tflite_convert" command wasn't recognized, but the "tflite_convert" command was recognized by updating tensorflow version from 1.5 to 1.9.
The terminal display when conversion successfully is shown below.
$ (path) tflite_convert
--output_file=(path)/ssd2.tflite
--graph_def_file=(path)/ssd1.pb
--input_arrays=input_13
--output_arrays=predictions/concat
--allow_custom_ops=True
2018-12-26 15:37:34.772285: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Thanks to liyunlu & ymodak !!

By the way... I want to convert to quantized model, but I couldn't convert...
Therefore, updating tensorflow version from 1.9 to 1.10 , simple model converted to quantized model without problem.
but custom model(SSD) couldn't convert to quantized model.
bellow error was happen.
Do you know the solution?
#command
$ (path) tflite_convert
--output_file=(path)/ssd2.tflite
--graph_def_file=(path)/ssd1.pb
--input_arrays=input_13
--output_arrays=predictions/concat
--allow_custom_ops=True
--inference_type=QUANTIZED_UINT8
--mean_values=128
--std_dev_values=127
--default_ranges_min=0
--default_ranges_max=6
--tflite_convert:error:argument --allow_custom_ops: ignored explicit argument "True"

By the way... I want to convert to quantized model.
but custom model(SSD) couldn't convert to quantized model.
bellow error was happen.
Do you know the solution?
#command
$ (path) tflite_convert
--output_file=(path)/ssd2.tflite
--graph_def_file=(path)/ssd1.pb
--input_arrays=input_13
--output_arrays=predictions/concat
--allow_custom_ops=True
--inference_type=QUANTIZED_UINT8
--mean_values=128
--std_dev_values=127
--default_ranges_min=0
--default_ranges_max=6
#result
2018-12-27 10:34:14.675240: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
File "/home/.local/bin/tflite_convert", line 11, in sys.exit(main())
File"/home/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 370, in main app.run(main=run_main, argv=sys.argv[:1])
File "/home/.local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 125, in run_sys.exit(main(argv))
File"/home/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 366, in run_main_convert_model(tflite_flags)
File"/home/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 143, in _convert_model output_data = converter.convert()
File "/home/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/lite.py", line 374, in convert dump_graphviz_video=self.dump_graphviz_video)
File "/home/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 246, in toco_convert input_data.SerializeToString())
File "/home/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 106, in toco_convert_protos (stdout, stderr))
RuntimeError: TOCO failed see console for info.
2018-12-27 10:34:16.679149: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679266: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679313: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679355: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679401: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679508: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679566: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679631: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679692: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679742: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.687343: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 307 operators, 497 arrays (0 quantized)
2018-12-27 10:34:16.692008: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 307 operators, 497 arrays (0 quantized)
2018-12-27 10:34:16.847001: I tensorflow/contrib/lite/toco/graph_transformations/identify_dilated_conv.cc:161] Identified sub-network emulating dilated convolution.
2018-12-27 10:34:16.847101: I tensorflow/contrib/lite/toco/graph_transformations/identify_dilated_conv.cc:209] Replaced with Dilated Conv2D op outputting "fc6/convolution".
2018-12-27 10:34:16.973428: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 1: 121 operators, 271 arrays (1 quantized)
2018-12-27 10:34:16.976343: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 2: 118 operators, 269 arrays (1 quantized)
2018-12-27 10:34:16.978081: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 3: 96 operators, 220 arrays (1 quantized)
2018-12-27 10:34:16.979551: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before pre-quantization graph transformations: 96 operators, 220 arrays (1 quantized)
2018-12-27 10:34:16.980254: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before default min-max range propagation graph transformations: 96 operators, 220 arrays (1 quantized)
2018-12-27 10:34:16.981095: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After default min-max range propagation graph transformations pass 1: 96 operators, 220 arrays (1 quantized)
2018-12-27 10:34:16.982101: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before quantization graph transformations: 96 operators, 220 arrays (1 quantized)
2018-12-27 10:34:16.982162: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv1_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:16.982244: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv1_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:16.982911: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv2_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:16.984138: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv2_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:16.986618: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv3_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:16.991730: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv3_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.001478: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv3_3/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.011443: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv4_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.031214: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv4_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.070534: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv4_3/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.109856: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv5_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.149394: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv5_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.188472: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv5_3/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.227761: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array fc6/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.311359: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array fc7/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.329462: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv6_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.333997: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv6_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.353890: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv7_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.355148: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv7_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.360063: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv8_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.360758: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv4_3_norm/conv4_3_norm_gamma lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.360814: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv8_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.365651: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv4_3_norm_mbox_conf/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.370659: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array fc7_mbox_conf/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.390781: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv6_2_mbox_conf/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.401131: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv7_2_mbox_conf/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.406407: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv8_2_mbox_conf/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.411938: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv4_3_norm_mbox_loc/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.412961: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array fc7_mbox_loc/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.419789: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv6_2_mbox_loc/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.421751: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv7_2_mbox_loc/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.422763: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv8_2_mbox_loc/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.423781: F tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:461] Unimplemented: this graph contains an operator of type (Unsupported TensorFlow op: Prod) for which the quantized form is not yet implemented. Sorry, and patches welcome (that's a relatively fun patch to write, mostly providing the actual quantized arithmetic code for this op).
Aborted (core dumped)
None

By the way... I want to convert to quantized model.
but custom model(SSD) couldn't convert to quantized model.
bellow error was happen.
Do you know the solution?
#command
$ (path) tflite_convert
--output_file=(path)/ssd2.tflite
--graph_def_file=(path)/ssd1.pb
--input_arrays=input_13
--output_arrays=predictions/concat
--allow_custom_ops    *"True" is not neccessary
--inference_type=QUANTIZED_UINT8
--mean_values=128
--std_dev_values=127
--default_ranges_min=0
--default_ranges_max=6
#result
2018-12-27 10:34:14.675240: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
File "/home/.local/bin/tflite_convert", line 11, in sys.exit(main())
File"/home/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 370, in main app.run(main=run_main, argv=sys.argv[:1])
File "/home/.local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 125, in run_sys.exit(main(argv))
File"/home/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 366, in run_main_convert_model(tflite_flags)
File"/home/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 143, in _convert_model output_data = converter.convert()
File "/home/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/lite.py", line 374, in convert dump_graphviz_video=self.dump_graphviz_video)
File "/home/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 246, in toco_convert input_data.SerializeToString())
File "/home/.local/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 106, in toco_convert_protos (stdout, stderr))
RuntimeError: TOCO failed see console for info.
2018-12-27 10:34:16.679149: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679266: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679313: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679355: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679401: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679508: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679566: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679631: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679692: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.679742: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Prod
2018-12-27 10:34:16.687343: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 307 operators, 497 arrays (0 quantized)
2018-12-27 10:34:16.692008: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 307 operators, 497 arrays (0 quantized)
2018-12-27 10:34:16.847001: I tensorflow/contrib/lite/toco/graph_transformations/identify_dilated_conv.cc:161] Identified sub-network emulating dilated convolution.
2018-12-27 10:34:16.847101: I tensorflow/contrib/lite/toco/graph_transformations/identify_dilated_conv.cc:209] Replaced with Dilated Conv2D op outputting "fc6/convolution".
2018-12-27 10:34:16.973428: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 1: 121 operators, 271 arrays (1 quantized)
2018-12-27 10:34:16.976343: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 2: 118 operators, 269 arrays (1 quantized)
2018-12-27 10:34:16.978081: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 3: 96 operators, 220 arrays (1 quantized)
2018-12-27 10:34:16.979551: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before pre-quantization graph transformations: 96 operators, 220 arrays (1 quantized)
2018-12-27 10:34:16.980254: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before default min-max range propagation graph transformations: 96 operators, 220 arrays (1 quantized)
2018-12-27 10:34:16.981095: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After default min-max range propagation graph transformations pass 1: 96 operators, 220 arrays (1 quantized)
2018-12-27 10:34:16.982101: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before quantization graph transformations: 96 operators, 220 arrays (1 quantized)
2018-12-27 10:34:16.982162: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv1_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:16.982244: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv1_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:16.982911: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv2_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:16.984138: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv2_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:16.986618: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv3_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:16.991730: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv3_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.001478: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv3_3/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.011443: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv4_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.031214: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv4_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.070534: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv4_3/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.109856: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv5_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.149394: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv5_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.188472: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv5_3/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.227761: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array fc6/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.311359: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array fc7/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.329462: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv6_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.333997: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv6_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.353890: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv7_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.355148: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv7_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.360063: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv8_1/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.360758: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv4_3_norm/conv4_3_norm_gamma lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.360814: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv8_2/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.365651: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv4_3_norm_mbox_conf/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.370659: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array fc7_mbox_conf/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.390781: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv6_2_mbox_conf/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.401131: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv7_2_mbox_conf/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.406407: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv8_2_mbox_conf/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.411938: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv4_3_norm_mbox_loc/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.412961: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array fc7_mbox_loc/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.419789: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv6_2_mbox_loc/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.421751: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv7_2_mbox_loc/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.422763: W tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:87] Constant array conv8_2_mbox_loc/kernel lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2018-12-27 10:34:17.423781: F tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:461] Unimplemented: this graph contains an operator of type (Unsupported TensorFlow op: Prod) for which the quantized form is not yet implemented. Sorry, and patches welcome (that's a relatively fun patch to write, mostly providing the actual quantized arithmetic code for this op).
Aborted (core dumped)
None

Your model needs to be trained with quantization for this conversion to work. This process will add the missing min/max to the tensors, as complained in the error message.
If you do not have to run quantized inference, we have another post-training optimization tools that doesn't require retraining your model. Please check it out and see if it applies.

We don't support quantization aware training with keras yet...
Your understanding is correct. Currently we don't have a well supported way to do quantization aware training with a model containing custom ops and convert it...

Since I was able to convert SSD model to tensorflow mobile format 8bit model(pb), I will use that model.
And I compare the speed of the 8bit model and the speed of the 32bit model, but it is a little disappointing that there has been almost no change.(Validate with smartphone)
If I could convert to 8bit model of tensorflow lite format, can it speed up..?
Anyway, since the conversion from pb to tflite which was an agenda has been solved, close the comment. (Remaining: Convert custom model to tensorflow lite format 8bit model(.tflite(8bit-custom))
liyunlu0618 Thank you for your comment.

Please take a look at this and give it a try:
https://www.tensorflow.org/lite/using_select_tf_ops
This is an effort meant for expanding the op support in tflite. In theory it should be able to convert any tensorflow op. It's still in a 'preview' phase and let us know any issue you run into. Thanks!

@liyunlu0618 Hi, I have a question, you said using target_ops can convert any tensorflow op, but there is still wrong.
#tf version
1.14
#command
$ (path) tflite_convert
--output_file=densenet.tflite
--graph_def_file=densenet.pb
--input_arrays=input_1
--output_arrays=ctc/ExpandDims
--allow_custom_ops
--target_ops=TFLITE_BUILTINS,SELECT_TF_OPS
#result
Traceback (most recent call last):
File "/home/anaconda3/bin/toco_from_protos", line 11, in
sys.exit(main())
File "/home/anaconda3/lib/python3.6/site-packages/tensorflow/lite/toco/python/toco_from_protos.py", line 59, in main
app.run(main=execute, argv=[sys.argv[0]] + unparsed)
File "/home/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "/home/anaconda3/lib/python3.6/site-packages/absl/app.py", line 300, in run
_run_main(main, args)
File "/home/anaconda3/lib/python3.6/site-packages/absl/app.py", line 251, in _run_main
sys.exit(main(argv))
File "/home/anaconda3/lib/python3.6/site-packages/tensorflow/lite/toco/python/toco_from_protos.py", line 33, in execute
output_str = tensorflow_wrap_toco.TocoConvert(model_str, toco_str, input_str)
Exception: TensorFlow Lite currently doesn't support control flow ops: Merge, Switch.
Looking forward your replace!Thanks

instead of posting things that do not work at all why not just post something that works 200%

I could convert pb file to tflite file by using "tflite_convert" command.
Initially, the "tflite_convert" command wasn't recognized, but the "tflite_convert" command was recognized by updating tensorflow version from 1.5 to 1.9.
The terminal display when conversion successfully is shown below.
$ (path) tflite_convert
--output_file=(path)/ssd2.tflite
--graph_def_file=(path)/ssd1.pb
--input_arrays=input_13
--output_arrays=predictions/concat
--allow_custom_ops=True
May I know how you came up with these parameters?

2018-12-26 15:37:34.772285: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Thanks to liyunlu & ymodak !!

I could convert pb file to tflite file by using "tflite_convert" command.
Initially, the "tflite_convert" command wasn't recognized, but the "tflite_convert" command was recognized by updating tensorflow version from 1.5 to 1.9.
The terminal display when conversion successfully is shown below.
$ (path) tflite_convert
--output_file=(path)/ssd2.tflite
--graph_def_file=(path)/ssd1.pb
--input_arrays=input_13
--output_arrays=predictions/concat
--allow_custom_ops=True
2018-12-26 15:37:34.772285: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Thanks to liyunlu & ymodak !!

May I know how you come up with these settings?  Thanks,

--input_arrays=input_13
--output_arrays=predictions/concat

I could convert pb file to tflite file by using "tflite_convert" command.
Initially, the "tflite_convert" command wasn't recognized, but the "tflite_convert" command was recognized by updating tensorflow version from 1.5 to 1.9.
The terminal display when conversion successfully is shown below.
$ (path) tflite_convert
--output_file=(path)/ssd2.tflite
--graph_def_file=(path)/ssd1.pb
--input_arrays=input_13
--output_arrays=predictions/concat
--allow_custom_ops=True
2018-12-26 15:37:34.772285: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Thanks to liyunlu & ymodak !!

Hi, @fkjpn1204
You converted pb to tflite with custom ops - ImageExtractPatches.

Someone deleted the colab that converts .pb to .tflite that helps me a lot, and now I'm looking for it, looks like they deleted it, Can I have a copy of that one again please.

Someone deleted the colab that converts .pb to .tflite that helps me a lot, and now I'm looking for it, looks like they deleted it, Can I have a copy of that one again please.


text:
Could port to OpenCL?

Could the project be port to OpenCL? Currently it only supports CUDA which is proprietary. OpenCL can be more wide spread and portable.

Thanks for the feedback -- this is tracked in https://github.com/tensorflow/tensorflow/issues/22

source: gharchive/issue

repo: tensorflow/tensorflow

license_type: permissive

license_source: github-api


text:
Tensorboard Graph is different when using File Writer as opposed to Tensorboard callback

The graph generated using tensorboard callback and the graph generated using FileWriter are different. Also, I am not able to retrieve scalar values when using FileWriter. Why is the behaviour different when using FileWriter? What changes should be done in FileWriter to get the graph and results similar to as when tensorboard callbacks are used? I have added the code as well as the tensorboard images.
System information

TF Version: 2.0.0-dev20190527
TF GIT Version: v1.12.1-2821-gc5b8e15064
Python Version: 3.6.6

Using tensorboard callback
import tensorflow as tf
from tensorflow import keras

# Load the data.
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()

# Pre-processing.
train_images = train_images / 255.0
test_images = test_images / 255.0

tb_callback = tf.keras.callbacks.TensorBoard(log_dir="/tmp/tb_test_1", histogram_freq=1)  # Create tensorboard callback

def create_model():
    return keras.Sequential([
        keras.layers.Flatten(input_shape=(28, 28)),
        keras.layers.Dense(128, activation=tf.nn.relu),
        keras.layers.Dense(10, activation=tf.nn.softmax)
    ])

model = create_model()
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
model.fit(train_images, train_labels, epochs=1, callbacks=[tb_callback], verbose=1)

Tensorboard Graph
Tensorboard Scalar
Using File Writer
import tensorflow as tf
from tensorflow import keras

# Load the data.
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()

# Pre-processing.
train_images = train_images / 255.0
test_images = test_images / 255.0

logdir = '/tmp/tb_test_2/'
writer = tf.summary.create_file_writer(logdir)

class MyModel(keras.Model):
    def __init__(self):
        super(MyModel, self).__init__()
        self.flatten = keras.layers.Flatten()
        self.d1 = keras.layers.Dense(128, activation='relu')
        self.d2 = keras.layers.Dense(10, activation='softmax')

    def call(self, x):
        x = self.flatten(x)
        x = self.d1(x)
        return self.d2(x)

model = MyModel()
optimizer = keras.optimizers.Adam(0.1)
loss_fn = keras.losses.SparseCategoricalCrossentropy()

@tf.function
def train_step(inputs, labels, step):
    with tf.GradientTape() as tape:
        predictions = model(inputs)
        pred_loss = loss_fn(labels, predictions)
        tf.summary.scalar("loss", pred_loss, step=step, description=None)

    gradients = tape.gradient(pred_loss, model.trainable_variables)
    optimizer.apply_gradients(zip(gradients, model.trainable_variables))

for i in range(5):
    tf.summary.trace_on(graph=True)
    train_step(train_images, train_labels, step=i)
    with writer.as_default():
        tf.summary.trace_export(name="test_model", step=i)
        writer.flush()

Tensorboard Graph
Tensorboard Scalar is absent.

@gupta-vivek ,
This question is better asked in Github Tensorboard Repo as the issues related to Tensorboard are given more attention there.

I don't think tensorboard is the issue but the way graph is being saved by tensorflow.

@gupta-vivek Please post this issue on tensorflow/tensorboard as its you can get your questions answered fast. Thanks!

authors: gowtham-kp gupta-vivek rmothukuru


text:
tflite gpu delegate create and load model use v2 api is very slow compare with v1 api(10x) why ?

System information

Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): android
Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
TensorFlow installed from (source or binary):
TensorFlow version (use command below): 2.2 rc2
Python version:
Bazel version (if compiling from source):
GCC/Compiler version (if compiling from source):
CUDA/cuDNN version:
GPU model and memory:

i compile tflite.a (2.2 rc2) from source and use ndk c++ api to run tflite model as follow:
`
#ifdef V2
TfLiteGpuDelegateOptionsV2 tOptions = TfLiteGpuDelegateOptionsV2Default();
if (m_bGPUAllowFP16)
{
tOptions.is_precision_loss_allowed = 1;
}
tOptions.inference_preference = 1;
m_pGPUDelegate = TfLiteGpuDelegateV2Create(&tOptions);

#else
TfLiteGpuDelegateOptions tOptions = {.metadata = nullptr, .compile_options = {.precision_loss_allowed = 0, .preferred_gl_object_type = TFLITE_GL_OBJECT_TYPE_FASTEST, .dynamic_batch_enabled = 0,},};
if (m_bGPUAllowFP16)
{
tOptions.compile_options.precision_loss_allowed = 1;
}
m_pGPUDelegate = TfLiteGpuDelegateCreate(&tOptions);

#endif
auto iRetCode = m_pInterp->ModifyGraphWithDelegate(m_pGPUDelegate);
if (iRetCode != kTfLiteOk)
{
    return -1;
}

`
but the time cost is very different, v1 load time cost is only 10% of v2 load time.  the model has Conv2DTranspose op, if use v1 api the inference time is 4x of v2 api, so why has this performance different?

Could you share logcat output for v2 API?

i use time count around the init op, logcat has no other tflite output log, i test the follow set, the load time is fast but still low than v1 load time:
tOptions.inference_preference = TFLITE_GPU_INFERENCE_PREFERENCE_FAST_SINGLE_ANSWER;
170     tOptions.inference_priority1 = TFLITE_GPU_INFERENCE_PRIORITY_MIN_LATENCY;
171     tOptions.inference_priority2 = TFLITE_GPU_INFERENCE_PRIORITY_MAX_PRECISION;
172     tOptions.inference_priority3 = TFLITE_GPU_INFERENCE_PRIORITY_AUTO;

Can you share your model?

can use the official model mobilenetv2, or tensorflow object detection api trained ssd mobilenetv2 model.   my model only retrained these model, no other change

Our benchmark tool is using v2 API and I don't see any issue with it.
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/tools/delegates/gpu_delegate_provider.cc#L113
You'd better check it to figure out if your delegate creation code is correct or not.

this is all the create code

The backend type might have the difference. FYI, you can explicitly select backend with this.
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/delegates/gpu/delegate.h#L70
BTW, I don't have this issue. You mentioned that you have the issue with Pixel 2 and Samsung Galaxy. Could you share which SW version you're using for those devices?
Could you confirm that if you see the same issue with the original mobilenetv2 here?
https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet
If you do, could you also tell me which specific mobilenetv2 you used?

i download the mobilenet_v2_1.0_224 and load tflite model on two devices:
one on MTK pad <Android 9, Kernel: 4.14.87>:
V2 api:
load model: "input: 224/224, type: 1, output type: 1, time cost: 1592 ms"
model forward avg time: 60ms
V1 api :
load model: "input: 224/224, type: 1, output type: 1, time cost: 1184 ms"
model forward avg time: 100ms
one on Samsung Galaxy Note8 <Android 9, Kernel: 4.4.153-17975032>:
V2 api:
load model: "input: 224/224, type: 1, output type: 1, time cost: 1424 ms"
model forward avg time: 10ms
V1 api:
load model: "input: 224/224, type: 1, output type: 1, time cost: 333 ms"
model forward avg time: 50 ms
two device performance is different a lot, but V2 api load model time all most the same, and more slow than V1 api, but forward time is much faster than V1 api.
used tflite2.2 version to compile static lib and use jni & ndk cross compile

@terryheo any guide for me to process this problem?

Passing to @impjdi , any idea on this?

OpenCL compilation takes much longer than OpenGL even if you turn off tuning (TFLITE_GPU_INFERENCE_PREFERENCE_FAST_SINGLE_ANSWER); this is not what we can change.  If this slow init is not desirable, I would suggest to use OpenGL instead.

Is there a way to precompile and cache the OpenCL kernels? Maybe as part of the tflite export? Or maybe the GPU delegate can cache the kernels locally on the device?

Is there a way to precompile and cache the OpenCL kernels? Maybe as part of the tflite export? Or maybe the GPU delegate can cache the kernels locally on the device for subsequent runs?

+1

While this functionality is present (was just added about a month ago), it doesn't follow the paths of the GPU delegate, and there is a lot more involved in getting the plumbing done.  You can take a look at tensorflow/lite/delegates/gpu/cl/serialization.h and make your experiment with it (sorry, no official documentation or support).  Note that the generated binary is not universal, i.e. it differs by mobile vendor, device, OS version, and GPU driver.  So for each new model, you would have to run & generate it once on that particular user device and store it.  You also need to know when you're going to flush it with a new OS version, GPU driver, and your ML model, so you'll need quite a lot of logic around this.

While this functionality is present (was just added about a month ago), it doesn't follow the paths of the GPU delegate, and there is a lot more involved in getting the plumbing done. You can take a look at tensorflow/lite/delegates/gpu/cl/serialization.h and make your experiment with it (sorry, no official documentation or support). Note that the generated cache binary is not universal, i.e. it differs by mobile vendor, device, OS version, and GPU driver. So for each new model, you would have to run & generate it once on that particular user device and store it. You also need to know when you're going to flush it with a new OS version, GPU driver, and your ML model, so you'll need quite a lot of logic around this.

i use mnn(https://github.com/alibaba/MNN) framework which support gpu cache, only the first time load will cost lot of time

While this functionality is present (was just added about a month ago), it doesn't follow the paths of the GPU delegate, and there is a lot more involved in getting the plumbing done. You can take a look at tensorflow/lite/delegates/gpu/cl/serialization.h and make your experiment with it (sorry, no official documentation or support). Note that the generated cache binary is not universal, i.e. it differs by mobile vendor, device, OS version, and GPU driver. So for each new model, you would have to run & generate it once on that particular user device and store it. You also need to know when you're going to flush it with a new OS version, GPU driver, and your ML model, so you'll need quite a lot of logic around this.

@impjdi   hi impjdi,   could you give a example?  it's very useful to save init time!!
mycode as follows, but i don't how to use Encode API in  serialization.h.
Thanks!
    // Load model
    std::unique_ptr<tflite::FlatBufferModel> model =
      tflite::FlatBufferModel::BuildFromFile(model_file);

    tflite::ops::builtin::BuiltinOpResolver resolver;
    tflite::InterpreterBuilder builder(*model, resolver);
    builder(&_interpreter);

    TfLiteGpuDelegateOptionsV2 gpu_opts = TfLiteGpuDelegateOptionsV2Default();
    auto delegate = CreateGPUDelegate(&gpu_opts);

    _interpreter->ModifyGraphWithDelegate(delegate.get());

While this functionality is present (was just added about a month ago), it doesn't follow the paths of the GPU delegate, and there is a lot more involved in getting the plumbing done. You can take a look at tensorflow/lite/delegates/gpu/cl/serialization.h and make your experiment with it (sorry, no official documentation or support). Note that the generated cache binary is not universal, i.e. it differs by mobile vendor, device, OS version, and GPU driver. So for each new model, you would have to run & generate it once on that particular user device and store it. You also need to know when you're going to flush it with a new OS version, GPU driver, and your ML model, so you'll need quite a lot of logic around this.

@impjdi   hi impjdi,   could you give a example?  it's very useful to save init time!!
mycode as follows, but i don't how to use Encode API in  serialization.h.
Thanks!
    // Load model
    std::unique_ptr<tflite::FlatBufferModel> model =
      tflite::FlatBufferModel::BuildFromFile(model_file);

    tflite::ops::builtin::BuiltinOpResolver resolver;
    tflite::InterpreterBuilder builder(*model, resolver);
    builder(&_interpreter);

    TfLiteGpuDelegateOptionsV2 gpu_opts = TfLiteGpuDelegateOptionsV2Default();
    auto delegate = CreateGPUDelegate(&gpu_opts);

    _interpreter->ModifyGraphWithDelegate(delegate.get());

I tried to initialize multiple tflite models with GPU delegate v2 api at the same time through multi-threading, but found that it takes about the same time for multi-threading to initialize multiple models at the same time and single-threading to initialize multiple models sequentially，Can someone explain why~

@impjdi : I have been testing with delegate serialization in tflite 2.7. It seems to be working well, but I have a question about your comment above "Note that the generated cache binary is not universal, i.e. it differs by mobile vendor, device, OS version, and GPU driver. So for each new model, you would have to run & generate it once on that particular user device and store it. You also need to know when you're going to flush it with a new OS version, GPU driver, and your ML model". With 2.7's serialization, does this still apply? If so, how does the cache get cleaned for OS version or GPU driver version? We are very interested in shipping this feature, but need to understand how to manage the cache. I don't see any real guidance in the 2.7 docs. Thanks!

@lauriebyrum If you are using Android's getCacheDir as the serialization directory, then it will get cleaned automatically for OS version update. @impjdi does the GPU delegate know if the GPU driver version has been updated? In the general case, user may have to append the GPU driver version to serialization_dir to avoid incorrect cache hits.

If we need to append the driver version, sample code would be very much appreciated...

(how bad is it if the cache doesn't get cleaned across these version updates? by any chance, does tflite ignore incompatible caches or are we going to get failures?)

by any chance, does tflite ignore incompatible caches or are we going to get failures?
how bad is it if the cache doesn't get cleaned across these version updates?

The TFLite layer will pass on the cached representation if it finds one; @impjdi will the GPU delegate crash (or just be suboptimal) if the GPU driver version has changed underneath?

Chances are high that it'll crash with driver version update.  I unfortunately don't have a code snippet that checks the driver version.  So far, we used this caching only in a setting where the app is updated with the OS update only, and there are no individual graphics driver update from Play Store, and we never ran into this issue ourselves =/

Thanks, @impjdi . To make sure I understand your comment: do third party apps need to somehow watch out for gpu driver updates or not? If they only occur during OS updates, we don't, but if there's some way they can happen outside of that, we do and I don't understand how to do that. Thanks!

A colleague did some research and found https://www.gizmochina.com/2020/03/25/gpu-driver-update-tool-play-store/ and https://www.androidauthority.com/gpu-driver-updates-phones-1096423/ . So it sounds like we app developers really do need to worry about gpu driver updates separate from OS updates. Does Google have guidance on handling this? We are hoping to ship with this in January, so we don't have much time.

Hey @lauriebyrum , sorry for the delay. I confirmed with our internal GPU team, and looks like the serialization data will automatically get re-initialized in case of a GPU driver update. This happens within the internal code that does serialization in tensorflow/lite/delegates/gpu/cl/serialization.cc, where the GetPlatformVersion() check fails if there is an update. Additionally, if you use CacheDir() from Android, your serialization folder will get reset for app or OS updates. Does that sound good?

That's fantastic news! Thanks @srjoglekar246

@srjoglekar246 : one more question. We are storing our serialized models in a subdir under getCacheDir so we can just throw away the subdir if things seem to be unstable for a user. I happened to have a pending android security update for one of my phones, so I went ahead and updated and the serialized bits did not get deleted during the update. That said, the serialization still seemed to work, so maybe the update was smart enough to realize that deleting the bits wasn't needed? Does this match your expectation? I was expecting that android updates would just toss out the caches generally, but it seems I'm wrong?

@lauriebyrum My bad, can you try using getCodeCacheDir?

tflite gpu delegate supported Conv2DTranspose????

authors: WillLiGitHub duanshanchong impjdi lauriebyrum linshizuowei menchunlei mlinxiang srjoglekar246 tailsu terryheo


text:
Incompatible shapes using sample_weight in Graph execution

Works fine in Eager. Code + error below; pasted outputs are from a Colab instance with tf.__version__ == 2.3.0-dev20200526, also reproduced in 2.2.0 and on Windows 10. No error in TF 1.14.0 Graph.

Attempted debug: Placing below here (in local install)
print(sample_weight)
try: print("sample_weight =", K.eval(sample_weight))
except: pass
print(loss, '\n')

yields:
# EAGER
Tensor("ExpandDims:0", shape=(32, 1), dtype=float32)
Tensor("mean_squared_error/weighted_loss/value:0", shape=(), dtype=float32)

Tensor("ExpandDims:0", shape=(32, 1), dtype=float32)
Tensor("mean_squared_error/weighted_loss/value:0", shape=(), dtype=float32)

# GRAPH
1.0
sample_weight = 1.0
Tensor("loss/conv2d_loss/weighted_loss/Mul:0", shape=(32, 28, 28), dtype=float32)

Tensor("conv2d_sample_weights:0", shape=(None,), dtype=float32)
sample_weight = [1.]
Tensor("loss_1/conv2d_loss/weighted_loss/Mul:0", shape=(32, 28, 28), dtype=float32)

Graph handles sample_weight tensor differently; also see example at bottom.

Reproducible code + Error:
import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import Input, Conv2D
from tensorflow.keras.models import Model
tf.compat.v1.disable_eager_execution()

batch_shape = (32, 28, 28, 1)

ipt = Input(batch_shape=batch_shape)
out = Conv2D(filters=1, kernel_size=(1, 1))(ipt)
model = Model(ipt, out)
model.compile('adam', 'mse')

x = y = np.random.randn(*batch_shape)
sw = np.ones(len(x))

model.train_on_batch(x, y, sw)

/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in __call__(self, *args, **kwargs)
   1470         ret = tf_session.TF_SessionRunCallable(self._session._session,
   1471                                                self._handle, args,
-> 1472                                                run_metadata_ptr)
   1473         if run_metadata:
   1474           proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
InvalidArgumentError: Incompatible shapes: [32] vs. [32,28,28]
	 [[{{node training/Adam/gradients/gradients/loss_1/conv2d_loss/weighted_loss/Mul_grad/Mul}}]]

No error case: both Graph and Eager work fine if output shape is instead 2D.

Example code
import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import Input, Conv2D, Dense, Flatten
from tensorflow.keras.models import Model

tf.compat.v1.disable_eager_execution()

batch_shape = (32, 28, 28, 1)

ipt = Input(batch_shape=batch_shape)
x   = Conv2D(filters=1, kernel_size=(1, 1))(ipt)
x   = Flatten()(x)
out = Dense(10, activation='softmax')(x)
model = Model(ipt, out)
model.compile('adam', 'categorical_crossentropy')

x = np.random.randn(*batch_shape)
n_classes, batch_size = 10, 32
class_labels = np.random.randint(0, n_classes, batch_size)
y = np.eye(n_classes)[class_labels]
sw = np.random.uniform(0, 2, (len(x),))

model.train_on_batch(x, y, sw)

sample_weight = 1.0
Tensor("loss/dense_loss/weighted_loss/Mul:0", shape=(32,), dtype=float32)
Tensor("dense_sample_weights:0", shape=(None,), dtype=float32)
sample_weight = [1.]
Tensor("loss_1/dense_loss/weighted_loss/Mul:0", shape=(32,), dtype=float32)

However, sample_weight still prints [1.], even though we passed in np.random.uniform(0, 2, ...).

Was able to reproduce the issue with TF v2.2 and TF-nightly. Please find the attached gist. Thanks!

Was able to reproduce the issue in TF 2.5. Please find the gist here. Thanks!

While trying to reproduce your issue in tf2.6 and tf-nightly(2.8.0-dev20211012) facing different error, please find the gist here,Thanks!

Hi There,
This is a stale issue. As you are using an older version of tensorflow, we are checking to see if you still need help on this issue. Please test the issue with the latest TensorFlow (TF2.7 and tf-nightly). If the issue still persists with the newer versions of TF, please feel free to open it in keras-team/keras repository by providing details about the issue and a standalone code to reproduce the issue. Thanks!
Please note that Keras development has moved to a separate Keras-team/keras repository to focus entirely on only Keras. Thanks!

authors: OverLordGoldDragon amahendrakar chunduriv saikumarchalla tensorflowbutler


text:
Docker Image : cuda:10.0-cudnn7-devel-ubuntu16.04 -Training performance low - GPU Util% keep changing - Process Id section empty

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): Docker Image : cuda:10.0-cudnn7-devel-ubuntu16.04
Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: No
TensorFlow installed from (source or binary): binary
TensorFlow version (use command below): tensorflow-gpu ==1.15.0
Python version: python 3.6
Bazel version (if compiling from source):
GCC/Compiler version (if compiling from source):
CUDA/cuDNN version: 10.2
GPU model and memory: 4 GPU - Model : V100 Memory: 16160 MB
collected some of this information using our environment capture
script
tf_env.txt
Environment:
Docker Image : cuda:10.0-cudnn7-devel-ubuntu16.04
Total GPUs : 4 nos Tesla V100 - GPU Memory 16.2 GB
CUDA: 10.2
Tensorflow-gpu - 1.15
keras: 2.1.3
Describe the current behavior
nvidia-smi shows as below - that is all GPUs Utilisation is above 90% for few seconds

Then nvidia-smi window shows as follows, that is all GPUs Utilisation is 0% for few seconds

Then nvidia-smi window shows as follows, that is  Utilisation% is random in all GPUs Utilisation for few seconds

I have noticed Training performance is low and taking longer duration in Docker container mentioned here. Same code is working fine in Tesla K80 2 GPUs with CUDA 10.0 on a Dedicated server as shown below.

But in Docker container, Why GPU utilization% is keep changing unusually and why process list section is empty? Why CUDA version is shown a 10.2 in the cuda:10.0-cudnn7-devel-ubuntu16.04 Image refer first three nvidia-smi schreen shots? I have not installed CUDA 10.2 toolkit and CuDNN libraries in the Image. How can i solve this issue?
ps aux command shows processids but nvidia-smi doesn’t show

@suresh-s
Please note we do not have support for 1.x, could you please upgrade to 2.x and let us know in case you face any issues.


text:
tensorflow.python.framework.errors_impl.UnknownError: Access is denied.

Hi again!
System information

OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
TensorFlow installed from (source or binary):  binary i think
TensorFlow version: 2.5.0-dev20201028
Python version: Python 3.8.3
Installed using virtualenv? pip? conda?: pip

Describe the problem
I can't train the model to recognize custom object.
So, my structure folder is like these:
-SistemiDigitali
    - ImageCollector
        - images
             - test
                    -images with xml file
             - train
                    -images with xml file
             - test.record
             - test_labels.csv
             - train.record
             - train_labels.csv
    - model (the folder where tensorflow model is located)
    - models-master (folder from git cloning the models repo)

So i have changed the pipeline inside model like this:

model {
  ssd {
    num_classes: 1
    image_resizer {
      fixed_shape_resizer {
        height: 320
        width: 320
      }
    }
    feature_extractor {
      type: "ssd_mobilenet_v2_fpn_keras"
      depth_multiplier: 1.0
      min_depth: 16
      conv_hyperparams {
        regularizer {
          l2_regularizer {
            weight: 3.9999998989515007e-05
          }
        }
        initializer {
          random_normal_initializer {
            mean: 0.0
            stddev: 0.009999999776482582
          }
        }
        activation: RELU_6
        batch_norm {
          decay: 0.996999979019165
          scale: true
          epsilon: 0.0010000000474974513
        }
      }
      use_depthwise: true
      override_base_feature_extractor_hyperparams: true
      fpn {
        min_level: 3
        max_level: 7
        additional_layer_depth: 128
      }
    }
    box_coder {
      faster_rcnn_box_coder {
        y_scale: 10.0
        x_scale: 10.0
        height_scale: 5.0
        width_scale: 5.0
      }
    }
    matcher {
      argmax_matcher {
        matched_threshold: 0.5
        unmatched_threshold: 0.5
        ignore_thresholds: false
        negatives_lower_than_unmatched: true
        force_match_for_each_row: true
        use_matmul_gather: true
      }
    }
    similarity_calculator {
      iou_similarity {
      }
    }
    box_predictor {
      weight_shared_convolutional_box_predictor {
        conv_hyperparams {
          regularizer {
            l2_regularizer {
              weight: 3.9999998989515007e-05
            }
          }
          initializer {
            random_normal_initializer {
              mean: 0.0
              stddev: 0.009999999776482582
            }
          }
          activation: RELU_6
          batch_norm {
            decay: 0.996999979019165
            scale: true
            epsilon: 0.0010000000474974513
          }
        }
        depth: 128
        num_layers_before_predictor: 4
        kernel_size: 3
        class_prediction_bias_init: -4.599999904632568
        share_prediction_tower: true
        use_depthwise: true
      }
    }
    anchor_generator {
      multiscale_anchor_generator {
        min_level: 3
        max_level: 7
        anchor_scale: 4.0
        aspect_ratios: 1.0
        aspect_ratios: 2.0
        aspect_ratios: 0.5
        scales_per_octave: 2
      }
    }
    post_processing {
      batch_non_max_suppression {
        score_threshold: 9.99999993922529e-09
        iou_threshold: 0.6000000238418579
        max_detections_per_class: 100
        max_total_detections: 100
        use_static_shapes: false
      }
      score_converter: SIGMOID
    }
    normalize_loss_by_num_matches: true
    loss {
      localization_loss {
        weighted_smooth_l1 {
        }
      }
      classification_loss {
        weighted_sigmoid_focal {
          gamma: 2.0
          alpha: 0.25
        }
      }
      classification_weight: 1.0
      localization_weight: 1.0
    }
    encode_background_as_zeros: true
    normalize_loc_loss_by_codesize: true
    inplace_batchnorm_update: true
    freeze_batchnorm: false
  }
}
train_config {
  batch_size: 128
  data_augmentation_options {
    random_horizontal_flip {
    }
  }
  data_augmentation_options {
    random_crop_image {
      min_object_covered: 0.0
      min_aspect_ratio: 0.75
      max_aspect_ratio: 3.0
      min_area: 0.75
      max_area: 1.0
      overlap_thresh: 0.0
    }
  }
  sync_replicas: true
  optimizer {
    momentum_optimizer {
      learning_rate {
        cosine_decay_learning_rate {
          learning_rate_base: 0.07999999821186066
          total_steps: 50000
          warmup_learning_rate: 0.026666000485420227
          warmup_steps: 1000
        }
      }
      momentum_optimizer_value: 0.8999999761581421
    }
    use_moving_average: false
  }
  fine_tune_checkpoint: "D:/Davide/Uni/SistemiDigitali/model/checkpoint/ckpt-0"
  num_steps: 50000
  startup_delay_steps: 0.0
  replicas_to_aggregate: 8
  max_number_of_boxes: 100
  unpad_groundtruth_tensors: false
  fine_tune_checkpoint_type: "detection"
  fine_tune_checkpoint_version: V2
}
train_input_reader {
  label_map_path: "D:/Davide/Uni/SistemiDigitali/ImageCollector/label_map.pbtxt"
  tf_record_input_reader {
    input_path: "D:/Davide/Uni/SistemiDigitali/ImageCollector/images/train.record"
  }
}
eval_config {
  metrics_set: "coco_detection_metrics"
  use_moving_averages: false
}
eval_input_reader {
  label_map_path: "D:/Davide/Uni/SistemiDigitali/ImageCollector/label_map.pbtxt"
  shuffle: false
  num_epochs: 1
  tf_record_input_reader {
    input_path: "D:/Davide/Uni/SistemiDigitali/ImageCollector/images/test.record"
  }
}

But when i run this command:
python models-master/research/object_detection/model_main_tf2.py --pipeline_config_path=model/pipeline.config --model_dir=model --alsologtostderr
I get this exception
WARNING:tensorflow:model\checkpoint: Checkpoint ignored
W1104 21:34:18.945756  6844 checkpoint_management.py:296] model\checkpoint: Checkpoint ignored
Traceback (most recent call last):
  File "models-master/research/object_detection/model_main_tf2.py", line 113, in <module>
    tf.compat.v1.app.run()
  File "C:\Users\Davide\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "C:\Users\Davide\AppData\Local\Programs\Python\Python38\lib\site-packages\absl\app.py", line 300, in run
    _run_main(main, args)
  File "C:\Users\Davide\AppData\Local\Programs\Python\Python38\lib\site-packages\absl\app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "models-master/research/object_detection/model_main_tf2.py", line 104, in main
    model_lib_v2.train_loop(
  File "C:\Users\Davide\AppData\Local\Programs\Python\Python38\lib\site-packages\object_detection-0.1-py3.8.egg\object_detection\model_lib_v2.py", line 630, in train_loop
    manager.save()
  File "C:\Users\Davide\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\checkpoint_management.py", line 824, in save
    self._record_state()
  File "C:\Users\Davide\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\checkpoint_management.py", line 727, in _record_state
    update_checkpoint_state_internal(
  File "C:\Users\Davide\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\checkpoint_management.py", line 247, in update_checkpoint_state_internal
    file_io.atomic_write_string_to_file(coord_checkpoint_filename,
  File "C:\Users\Davide\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 573, in atomic_write_string_to_file
    rename(temp_pathname, filename, overwrite)
  File "C:\Users\Davide\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 532, in rename
    rename_v2(oldname, newname, overwrite)
  File "C:\Users\Davide\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 548, in rename_v2
    _pywrap_file_io.RenameFile(
tensorflow.python.framework.errors_impl.UnknownError: Failed to rename: model\checkpoint.tmp2ddac8459ee545f28c333f066a5292cc to: model\checkpoint : Access is denied.
; Input/output error

I'm sorry about that. I have actually solved the problem.
Now i get this output:
INFO:tensorflow:Step 100 per-step time 2.474s loss=0.629
I1105 00:47:38.029456 12864 model_lib_v2.py:649] Step 100 per-step time 2.474s loss=0.629

So i suppose everything is fine. The error was that i didn't understand how everything worked. I had to copy pipeline.config inside a new folder, and this is where the new model will be created. Instead of doing so i edited the pipeline.config of the model i have downloaded from internet and i gave that pipeline.config and folder to the training script.

@fanto88,
Is this still an issue? Please feel free to close the issue if resolved. Thanks!

I'm sorry about that. I have actually solved the problem.
Now i get this output:
INFO:tensorflow:Step 100 per-step time 2.474s loss=0.629
I1105 00:47:38.029456 12864 model_lib_v2.py:649] Step 100 per-step time 2.474s loss=0.629

So i suppose everything is fine. The error was that i didn't understand how everything worked. I had to copy pipeline.config inside a new folder, and this is where the new model will be created. Instead of doing so i edited the pipeline.config of the model i have downloaded from internet and i gave that pipeline.config and folder to the training script.

I have this issue and can't figure it out can you please explain how you solved it, as i am confused by your file structure

I'm sorry about that. I have actually solved the problem.
Now i get this output:
INFO:tensorflow:Step 100 per-step time 2.474s loss=0.629
I1105 00:47:38.029456 12864 model_lib_v2.py:649] Step 100 per-step time 2.474s loss=0.629

So i suppose everything is fine. The error was that i didn't understand how everything worked. I had to copy pipeline.config inside a new folder, and this is where the new model will be created. Instead of doing so i edited the pipeline.config of the model i have downloaded from internet and i gave that pipeline.config and folder to the training script.

I have this issue and can't figure it out can you please explain how you solved it, as i am confused by your file structure

authors: RMC-G amahendrakar fanto88


text:
Keras Model.compile() exception text is unclear when a loss method is not specified during compile()

System information

TensorFlow version (you are using): 2.3.1
Are you willing to contribute it (Yes/No): Yes

Describe the feature and the current behavior/state. User is not given an obvious error message when  tensorflow.keras.models.Sequential.compile() is called and a loss function is omitted.
# Build the model
tf_model = Sequential()
tf_model.add(LSTM(
    units=32,
    input_shape=[window, 1],
))
tf_model.add(Dense(units=1))
tf_model.compile()
tf_model.fit(rolling_x, rolling_y, epochs=100)

Triggers the following exception:
\env\lib\site-packages\tensorflow\python\keras\optimizer_v2\optimizer_v2.py:1270 _filter_grads
        raise ValueError("No gradients provided for any variable: %s." %

Will this change the current api? How? No
Who will benefit with this feature? New users

Can you try with tf-nighlty?

Yes, this still occurs with nightly. PS. Due to Nvidia software mismatch this was run on CPU and not GPU. I don't think that matters.

Can you fill your variable in you code example so that I could run your same code quickly?

authors: bhack drjubbs


text:
Detection postprocess operator output differs between TFL and TFLM

@tensorflow/micro
System information

Host OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
TensorFlow installed from (source or binary):
Tensorflow version (commit SHA if source): 6c0245b27c3b5dd319d3021b05c89a0cd17beb20
Target platform (e.g. Arm Mbed OS, Arduino Nano 33 etc.):

Describe the problem
Detection post process operator output differs between TFL and TFLM because of floating point imprecision on different platforms. It can be fixed by e.g. this change in both kernels:
#if 1
float ycenter = static_cast(
static_cast(box_centersize.y) /
static_cast(scale_values.y) *
static_cast(anchor.h) + static_cast(anchor.y));
float xcenter = static_cast(
static_cast(box_centersize.x) /
static_cast(scale_values.x) *
static_cast(anchor.w) + static_cast(anchor.x));
float half_h = static_cast(
0.5 * (std::exp(static_cast(box_centersize.h) /
static_cast(scale_values.h))) *
static_cast(anchor.h));
float half_w = static_cast(
0.5 * (std::exp(static_cast(box_centersize.w) /
static_cast(scale_values.w))) *
static_cast(anchor.w));
#else
float ycenter = box_centersize.y / scale_values.y * anchor.h + anchor.y;
float xcenter = box_centersize.x / scale_values.x * anchor.w + anchor.x;
float half_h =
0.5f * static_cast(std::exp(box_centersize.h / scale_values.h)) *
anchor.h;
float half_w =
0.5f * static_cast(std::exp(box_centersize.w / scale_values.w)) *
anchor.w;
#endif
Please provide the exact sequence of commands/steps when you ran into the problem

Tagging @advaitjain


text:
Error with cude even with tf nightly

Please make sure that this is a bug. As per our
System information

Have I written custom code (as opposed to using a stock example script provided in TensorFlow): I juste wrote from tensorflow.keras import layers
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): W10 Family
TensorFlow installed from (source or binary): Don't
TensorFlow version (use command below):  tf-estimator-nightly-2.5.0.dev2021030601
pip install tf-nightly-gpu
Python version: 3.7
CUDA/cuDNN version: 11.2
GPU model and memory: GTX 1660TI 6gb

Describe the current behavior
I try to run script using tensorflow . But I have :

2021-03-07 06:41:09.619717: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-03-07 06:41:09.634433: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

Describe the expected behavior
I should not have an error.
Standalone code to reproduce the issue
Write a script with this code : from tensorflow.keras import layers
pip install tf-nightly-gpu

@LucasColas,
Every TensorFlow release is compatible with a certain CUDA/cuDNN version, for more information please take a look at the tested build configurations.

Version
Python version
Compiler
Build tools
cuDNN
CUDA

tensorflow_gpu-2.4.0
3.6-3.8
MSVC 2019
Bazel 3.1.0
8.0
11.0

tensorflow_gpu-2.3.0
3.5-3.8
MSVC 2019
Bazel 3.1.0
7.6
10.1

tensorflow_gpu-2.2.0
3.5-3.8
MSVC 2019
Bazel 2.0.0
7.6
10.1

In this case, can you please try installing TensorFlow v2.4 with CUDA 11.0 and cuDNN 8 and check if you are facing the same error. Thanks!

Also, seems like this is a duplicate of issue #47602. Can we close this issue as it is already being tracked there. Thanks!

authors: LucasColas amahendrakar


text:
java.lang.UnsatisfiedLinkError: Failed to load native TensorFlow Lite methods.

System information

OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows
Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: Samsung Galaxy s5 min
TensorFlow installed from (source or binary): source
TensorFlow version: 'org.tensorflow:tensorflow-lite:2.4.0' + org.tensorflow:tensorflow-android:1.13.1'
Python version:
Installed using virtualenv? pip? conda?:
Bazel version (if compiling from source):
GCC/Compiler version (if compiling from source):
CUDA/cuDNN version:
GPU model and memory:

hello little question for a computer project in computer license I have to refactor an old application and make it modular. But here's when I build my generate signed bundle and I launch a feature on demand who use tensorflow on my android I have this error:
FATAL EXCEPTION: Thread-9
Process: descartes.info.l3ak2.eyetrek, PID: 7275
java.lang.UnsatisfiedLinkError: Failed to load native TensorFlow Lite methods. Check that the correct native libraries are present, and, if using a custom native library, have been properly loaded via System.loadLibrary():
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/androidx.test.tools.crawler-gvh38WebyoKL_IpGVoIEuw==/base.apk", zip file "/data/app/descartes.info.l3ak2.eyetrek-h1-hReoVf26OAguR-8QZHw==/base.apk", zip file "/data/app/descartes.info.l3ak2.eyetrek-h1-hReoVf26OAguR-8QZHw==/split_config.xxhdpi.apk", zip file "/data/app/descartes.info.l3ak2.eyetrek-h1-hReoVf26OAguR-8QZHw==/split_moduleastronomie.apk", zip file "/data/app/descartes.info.l3ak2.eyetrek-h1-hReoVf26OAguR-8QZHw==/split_moduleastronomie.config.xxhdpi.apk", zip file "/data/app/descartes.info.l3ak2.eyetrek-h1-hReoVf26OAguR-8QZHw==/split_modulereconnaissancechantsoiseaux.apk", zip file "/data/app/descartes.info.l3ak2.eyetrek-h1-hReoVf26OAguR-8QZHw==/split_modulereconnaissancechantsoiseaux.config.xxhdpi.apk", zip file "/data/app/descartes.info.l3ak2.eyetrek-h1-hReoVf26OAguR-8QZHw==/split_modulereconnaissancefeuille.apk", zip file "/data/app/descartes.info.l3ak2.eyetrek-h1-hReoVf26OAguR-8QZHw==/split_modulereconnaissancefeuille.config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/androidx.test.tools.crawler-gvh38WebyoKL_IpGVoIEuw==/lib/arm64, /data/app/descartes.info.l3ak2.eyetrek-h1-hReoVf26OAguR-8QZHw==/lib/arm64, /system/lib64, /vendor/lib64]]] couldn't find "libtensorflowlite_jni.so"
at org.tensorflow.lite.TensorFlowLite.init(TensorFlowLite.java:80)
at org.tensorflow.lite.NativeInterpreterWrapper.(NativeInterpreterWrapper.java:52)
at org.tensorflow.lite.Interpreter.(Interpreter.java:277)
at org.tensorflow.lite.Interpreter.(Interpreter.java:262)
at descartes.info.l3ak2.eyetrek.module_reconnaissance_feuille.tensorflow.ImageClassifierFpasF.(ImageClassifierFpasF.java:102)
at descartes.info.l3ak2.eyetrek.module_reconnaissance_feuille.fragment.FragmentScanFeuille$6.run(FragmentScanFeuille.java:1306)
at java.lang.Thread.run(Thread.java:764)
how can I resolve this ?

Fyi, https://support.google.com/android/answer/7680439?hl=en

Fyi, https://support.google.com/android/answer/7680439?hl=en

Version android : 6.01
Security patch level : ASKS v1.2 Release 161011

Fyi, https://support.google.com/android/answer/7680439?hl=en

Version android : 6.01
Security patch level : ASKS v1.2 Release 161011

I specify I changed the software of my phone so that I can do the tests in android 6.0. The application must work at least in 6.0 (it is recorded on the specifications ^^)

@thaink could you take a look?

I am still waiting for your answer. have you found a solution to my problem ^^ ?

Instead of using the mixed version like the below one;
api 'org.tensorflow:tensorflow-lite:2.4.0'
api 'org.tensorflow:tensorflow-android:1.13.1'
api 'org.tensorflow:tensorflow-lite:2.4.0'
api 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly'

Use the same version:
   // Import tflite dependencies
    implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly-SNAPSHOT'
    // The GPU delegate library is optional. Depend on it as needed.
    implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly-SNAPSHOT'

Instead of using the mixed version like the below one;
api 'org.tensorflow:tensorflow-lite:2.4.0'
api 'org.tensorflow:tensorflow-android:1.13.1'
api 'org.tensorflow:tensorflow-lite:2.4.0'
api 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly'

Use the same version:
   // Import tflite dependencies
    implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly-SNAPSHOT'
    // The GPU delegate library is optional. Depend on it as needed.
    implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly-SNAPSHOT'

ok i will try I'll let you know ^^

Instead of using the mixed version like the below one;
api 'org.tensorflow:tensorflow-lite:2.4.0'
api 'org.tensorflow:tensorflow-android:1.13.1'
api 'org.tensorflow:tensorflow-lite:2.4.0'
api 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly'

Use the same version:
   // Import tflite dependencies
    implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly-SNAPSHOT'
    // The GPU delegate library is optional. Depend on it as needed.
    implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly-SNAPSHOT'

the same error yet
i try to put alone implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly-SNAPSHOT' in my app graddle (no work) and the same for api 'org.tensorflow:tensorflow-lite:2.4.0'

@Duskley Does it work on emulator with the same Android version?

@Duskley Does it work on emulator with the same Android version?

Hello, yes it works very well. To switch from an aab format to an apk format I have to change the ndk filters. I'm going from arm64-v8a, armeabi-v7a to armeabi-v7a (My phone only supports armeabi-v7a). Does this crash have something to do with ndk filters?

Not sure but I suspect that or sourceSets might be the problem.
Could you check if the .so file does exists in the apk and tests several option on these fields?

Not sure but I suspect that or sourceSets might be the problem.
Could you check if the .so file does exists in the apk and tests several option on these fields?

Hello, sorry for the late reply. I have checked in my apk and the libtensorflowlite.so file is present but in the aab file it cannot be found, so I think my problem is due to the libtensorflowlite.so file which is nonexistent in my aab file. The question now is "is there a step to include .so files in the aab?". I specify there are normally other .so which are present in my apk but which are not found in the aab

I am not familiar with aab bundling. Hope this link could help: https://developer.android.com/studio/build/configure-apk-splits#configure-split

authors: Duskley abattery thaink