TfLite: 把pb、h5文件转换为TfLite格式and quantilize

2024-06-03 14:58

本文主要是介绍TfLite: 把pb、h5文件转换为TfLite格式and quantilize,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

现在不是都用keras生成h5格式文件,然后用tflite_convert 吗?

问题来源

写了个很简单的RNN LSTM 模型

input = keras.Input(shape=(X_train.shape[1], X_train.shape[2]))
x = layers.LSTM(64, return_sequences = True)(input)
x = layers.LSTM(64)(x)
output = layers.Dense(6, activation='softmax')(x)
model = keras.Model(inputs=input, outputs=output)
model.summary()
Model: "model"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_2 (InputLayer)         [(None, 200, 3)]          0         
_________________________________________________________________
lstm_1 (LSTM)                (None, 200, 64)           17408     
_________________________________________________________________
lstm_2 (LSTM)                (None, 64)                33024     
_________________________________________________________________
dense (Dense)                (None, 6)                 390       
=================================================================

出现如下错误
 


In [102]: model = keras.models.load_model('ar_model.h5')

In [103]: converter = tf.lite.TFLiteConverter.from_keras_model(model)

In [104]: tflite_model = converter.convert()
2019-07-04 18:27:11.251237: I tensorflow/core/grappler/devices.cc:60] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0 (Note: TensorFlow was not compiled with CUDA support)
2019-07-04 18:27:11.251429: I tensorflow/core/grappler/clusters/single_machine.cc:359] Starting new session
2019-07-04 18:27:11.266766: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:716] Optimization results for grappler item: graph_to_optimize
2019-07-04 18:27:11.266814: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:718]   function_optimizer: Graph size after: 437 nodes (262), 654 edges (442), time = 8.606ms.
2019-07-04 18:27:11.266822: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:718]   function_optimizer: function_optimizer did nothing. time = 0.551ms.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-104-c548bab089a8> in <module>()
----> 1 tflite_model = converter.convert()

/usr/local/lib/python2.7/dist-packages/tensorflow/lite/python/lite.pyc in convert(self)
    346
    347     frozen_func = _convert_to_constants.convert_variables_to_constants_v2(
--> 348         self._funcs[0])
    349     input_tensors = [
    350         tensor for tensor in frozen_func.inputs

/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/convert_to_constants.pyc in convert_variables_to_constants_v2(func)
    164         input_name = get_name(map_name_to_node[input_name].input[0])
    165       if map_name_to_node[input_name].op != "Placeholder":
--> 166         raise ValueError("Cannot find the Placeholder op that is an input "
    167                          "to the ReadVariableOp.")
    168       # Build a map of Placeholder ops that are inputs to ReadVariableOps to the

ValueError: Cannot find the Placeholder op that is an input to the ReadVariableOp.

 

LSTM并不是所有的类型都支持,该模型的底层实现使用了?

https://www.tensorflow.org/lite/convert/rnn

怎样看keras的实现使用的是什么operator?

 

使用Tensorflow构建模型,控制使用的LSTM类型

https://medium.com/@curiousily/human-activity-recognition-using-lstms-on-android-tensorflow-for-hackers-part-vi-492da5adef64

# Stack 2 LSTM layers

lstm_layers = [tf.contrib.rnn.BasicLSTMCell(N_HIDDEN_UNITS, forget_bias=1.0)
for _ in range(2)]
lstm_layers = tf.contrib.rnn.MultiRNNCell(lstm_layers)
outputs, _ = tf.contrib.rnn.static_rnn(lstm_layers, hidden, dtype=tf.float32)
# Get output for the last time step lstm_last_output = outputs[-1]

怎样把得到的pb文件转化成tflite

https://zhuanlan.zhihu.com/p/59496851

这篇提到使用bazel build生成源码相关的工具,感觉比较靠谱,关键是bazel 还算熟悉

查看模型结构的工具:得到toco的输入参数
$ bazel build tensorflow/tools/graph_transforms:summarize_graph

格式转化的工具

$ bazel build tensorflow/lite/toco:toco

bin文件编出后,可以copy到需要的路径下,如pb文件所在的路径

./summarize_graph --in_graph=frozen_har.pb
Found 1 possible inputs: (name=input, type=float(1), shape=[?,200,3]
No variables spotted.
Found 1 possible outputs: (name=y_, op=Softmax
Found 67919 (67.92k) const parameters, 0 (0) variable parameters, and 0 control_edges
Op types used: 1230 Const, 1200 Mul, 1200 Sigmoid, 802 Add, 800 Tanh, 404 ConcatV2, 402 MatMul, 401 Split, 400 BiasAdd, 8 Identity, 4 ExpandDims, 4 Fill, 1 Transpose, 1 StridedSlice, 1 Softmax, 1 Shape, 1 Reshape, 1 Relu, 1 Placeholder
To use with tensorflow/tools/benchmark:benchmark_model try these arguments:
bazel run tensorflow/tools/benchmark:benchmark_model -- --graph=frozen_har.pb --show_flops --input_layer=input --input_layer_type=float --input_layer_shape=-1,200,3 --output_layer=y_
 

toco的基本参数意义(主要里面有废弃的参数)

--input_file=""                      
string    
Input file (model of any supported format). 
For Protobuf formats, both text and binary are supported regardless of file extension.

--output_file=""                     
string    
Output file. For Protobuf formats, the binary format will be used.

--output_format="TFLITE"             
string    
Output file format. One of TENSORFLOW_GRAPHDEF, TFLITE, GRAPHVIZ_DOT.

--inference_type=""                  
string    
Target data type of arrays in the output file (for input_arrays, this may be overridden by inference_input_type). 
One of FLOAT, QUANTIZED_UINT8.

--inference_input_type=""            
string    
Target data type of input arrays. If not specified, inference_type is used. One of FLOAT, QUANTIZED_UINT8.

--input_arrays=""                    
string    
Names of the input arrays, comma-separated. If not specified, will try to read that information from the input file.

--output_arrays=""                   
string    Names of the output arrays, comma-separated. If not specified, 
will try to read that information from the input file.

--input_shapes=""                    
string    
Shapes corresponding to --input_arrays, colon-separated. For many models each shape takes the form batch size, input array height, input array width, input array depth.

--input_data_types=""                
string    
Input arrays types, comma-separated, if not already provided in the graph. 
Typically needs to be specified when passing arbitrary arrays to --input_arrays.

input_shapes=[?,200,3]

这里写 ?、-1还是1, 从错误信息看出应该写1

./toco --input_file="frozen_har.pb" --output_file="frozen_har.tflite" --input_format="TENSORFLOW_GRAPHDEF" --output_format="TFLITE" --inference_type="FLOAT" --input_shapes="-1,200,3" --input_arrays="input"  --output_arrays="y_"
2019-07-05 17:36:16.423579: F tensorflow/lite/toco/tooling_util.cc:622] Check failed: dim >= 1 (-1 vs. 1)

执行过程、结果

./toco --input_file="frozen_har.pb" --output_file="frozen_har.tflite" --input_format="TENSORFLOW_GRAPHDEF" --output_format="TFLITE" --inference_type="FLOAT" --input_shapes="1,200,3" --input_arrays="input"  --output_arrays="y_" 
2019-07-05 17:36:54.449902: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 5631 operators, 8261 arrays (0 quantized)
2019-07-05 17:36:58.338339: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 5631 operators, 8261 arrays (0 quantized)
2019-07-05 17:37:07.555026: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 1: 5220 operators, 8241 arrays (0 quantized)
2019-07-05 17:37:15.311358: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 2: 5219 operators, 8240 arrays (0 quantized)
2019-07-05 17:37:23.238861: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 3: 5196 operators, 8201 arrays (0 quantized)
2019-07-05 17:37:31.016187: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before dequantization graph transformations: 5196 operators, 8201 arrays (0 quantized)
2019-07-05 17:37:32.857134: I tensorflow/lite/toco/allocate_transient_arrays.cc:345] Total transient array allocated size: 102400 bytes, theoretical optimal value: 102400 bytes.
2019-07-05 17:37:34.249694: I tensorflow/lite/toco/toco_tooling.cc:397] Estimated count of arithmetic ops: 0.034719 billion (note that a multiply-add is counted as 2 ops).

生成的tflite文件比pb文件还大这正常吗?

-rw-r--r--  1 ws ws  1393628 7月   5 16:56 frozen_har.pb
-rw-rw-r--  1 ws ws  1399504 7月   5 17:37 frozen_har.tflite

 

模型文件的不同格式

GraphDef(.pb),

FrozenGraphDef (.pb with frozen variables),

SavedModel (.pb – used to infer the common format on the server side), and

Checkpoint files (serialized variables during training).

SavedModel

Training Model will generate 3 files representing the network structure. We care about GraphDef and checkpoint files. 

-rw-r--r-- 1 ws ws       73 6月  28 16:52 checkpoint
-rw-r--r-- 1 ws ws   800336 6月  28 16:52 har.ckpt.data-00000-of-00001
-rw-r--r-- 1 ws ws      955 6月  28 16:52 har.ckpt.index
-rw-r--r-- 1 ws ws 11945604 6月  28 16:52 har.ckpt.meta
-rw-r--r-- 1 ws ws 16349895 6月  28 16:52 har.pbtxt
此时使用Tensorboard 看到图是training的图

Since we named the input and output layers, we can easily identify them and then begin to understand which layers are necessary for inference and which layers can be discarded.

Again, everything before the input_tensor is not necessary. We need to crop this image before executing it on the mobile device. Most training layers in TFLite are also not supported.

Freeze graph

– this will freeze checkpoint variables in GraphDef

freeze_graph

--input_graph=/tmp/mnist_graph_def_with_ckpts/graph.pbtxt

--input_checkpoint=/tmp/mnist_graph_def_with_ckpts/model.ckpt-48000

-input_binary=false

--output_graph=/tmp/mnist_graph_def_with_ckpts/frozen_mnist.pb

--output_node_names=softmax_tensor

  1. If you installed TensorFlow with pip, you will get the freeze_graph command. ( installation instructions )
  2. Open the checkpoint file and determine the latest file. In our case it is model.ckpt-48000
  3. The Input binary option is false because we are passing a .pbtxt file instead of .pb (in which case it should be true).
  4. The hardest part is identifying the output_node_name, but since we gave it a name in the training script, it's easy. If you don't provide a training script for the model you're building, you'll need to use Tensorboard and find the automatically generated name for it (I spent a lot of time trying to understand this, so in short, the training script is handy is a huge one.) reward). tf.nn.softmax(logits, name='softmax_tensor'),

 Note that freeze_graph actually removes most of the layers used in the training. However, we still have something that is incompatible with TFLite. Specifically, notice the "dropout" and "iterator" layers. These layers are used for training and still need to be cropped (optimize_for_inference当前已经没有这个工具?)

TFLite

The final step is to execute the toco tool and the TensorFlow Lite optimized converter. 

也就是上面说的toco工具

TFLite post_training_quantize

/toco --input_file='30_cnn.tflite' --input_format=TFLITE --output_format=TFLITE --output_file='quanized_30_cnn.tflite' --inference_type=FLOAT --input_type=FLOAT --input_arrays=conv1d_input --output_arrays=Identity --input_shapes=1,80,3 --post_training_quantize

Quantization(但依赖saved model dir)

使用底层tensorflow API才能得到SavedModel? keras可以吗?

By reducing the precision of values and operations within a model, quantization can reduce both the size of model and the time required for inference. For many models, there is only a minimal loss of accuracy.

The TensorFlow Lite converter makes it easy to quantize TensorFlow models. The following Python code quantizes a SavedModel and saves it to disk:

import tensorflow as tfconverter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
tflite_quant_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_quantized_model)

 使用TOCO工具 --post_training_quantize用于模型压缩

注意要使用源码编译出参考上面的bazel build 自动安装的toco不行

网上给的例子都是pb到tflite 且quantization, 但没有tflite作为输入进行quantization的例子

bazel-bin/tensorflow/lite/toco/toco --input_file='../kerasyolo3/m/transfer_multi_4cl_1207.pb' --input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE --output_file='../kerasyolo3/m/transfer_multi_4cl_1207.tflite' --inference_type=FLOAT --input_type=FLOAT --input_arrays=input_1 --output_arrays=output_1,output_2,output_3 --input_shapes=1,416,416,3

仔细看toco的help: 这里的输入格式可以是TFLITE

--input_format="TENSORFLOW_GRAPHDEF"    string    Input file format. One of: TENSORFLOW_GRAPHDEF, TFLITE

 ./toco

--input_file='30_cnn.tflite'

--input_format=TFLITE

--output_format=TFLITE

--output_file='quanized_30_cnn.tflite'

--inference_type=FLOAT

--input_type=FLOAT

--input_arrays=conv1d_input

--output_arrays=Identity

--input_shapes=1,80,3

--post_training_quantize

这里关键的是上面几个参数 可以从tflite::PrintInterpreterState(interpreter.get());打印的log看出

Inputs: 1
Outputs: 0

Tensor   0 Identity             kTfLiteFloat32  kTfLiteArenaRw         24 bytes ( 0.0 MB)  1 6
Tensor   1 conv1d_input         kTfLiteFloat32  kTfLiteArenaRw        960 bytes ( 0.0 MB)  1 80 3
 

toco执行log

./toco --input_file='30_cnn.tflite' --input_format=TFLITE --output_format=TFLITE --output_file='quanized_30_cnn.tflite' --inference_type=FLOAT --input_type=FLOAT --input_arrays=conv1d_input --output_arrays=Identity --input_shapes=1,80,3 --post_training_quantize
2019-07-11 11:09:30.601131: W tensorflow/lite/toco/toco_cmdline_flags.cc:283] --input_type is deprecated. It was an ambiguous flag that set both --input_data_types and --inference_input_type. If you are trying to complement the input file with information about the type of input arrays, use --input_data_type. If you are trying to control the quantization/dequantization of real-numbers input arrays in the output file, use --inference_input_type.
2019-07-11 11:09:30.603468: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 12 operators, 28 arrays (0 quantized)
2019-07-11 11:09:30.603855: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 12 operators, 28 arrays (0 quantized)
2019-07-11 11:09:30.604693: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 1: 12 operators, 28 arrays (0 quantized)
2019-07-11 11:09:30.605595: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before dequantization graph transformations: 12 operators, 28 arrays (0 quantized)
2019-07-11 11:09:30.606233: I tensorflow/lite/toco/allocate_transient_arrays.cc:345] Total transient array allocated size: 17024 bytes, theoretical optimal value: 16064 bytes.
2019-07-11 11:09:30.606453: I tensorflow/lite/toco/toco_tooling.cc:397] Estimated count of arithmetic ops: 0.00166014 billion (note that a multiply-add is counted as 2 ops).
2019-07-11 11:09:30.607429: I tensorflow/lite/toco/tflite/export.cc:569] Quantizing TFLite model after conversion to flatbuffer. dump_graphviz will only output the model before this transformation. To visualize the output graph use lite/tools/optimize.py.
2019-07-11 11:09:30.612030: I tensorflow/lite/tools/optimize/quantize_weights.cc:199] Skipping quantization of tensor sequential/conv1d/conv1d/ExpandDims_1 because it has fewer than 1024 elements (900).
2019-07-11 11:09:30.612066: I tensorflow/lite/tools/optimize/quantize_weights.cc:278] Quantizing tensor sequential/conv1d_1/conv1d/ExpandDims_1 with 9000 elements for hybrid evaluation.
2019-07-11 11:09:30.612170: I tensorflow/lite/tools/optimize/quantize_weights.cc:278] Quantizing tensor sequential/conv1d_2/conv1d/ExpandDims_1 with 14400 elements for hybrid evaluation.
2019-07-11 11:09:30.612302: I tensorflow/lite/tools/optimize/quantize_weights.cc:278] Quantizing tensor sequential/conv1d_3/conv1d/ExpandDims_1 with 23040 elements for hybrid evaluation.
2019-07-11 11:09:30.612508: I tensorflow/lite/tools/optimize/quantize_weights.cc:199] Skipping quantization of tensor sequential/dense/MatMul/ReadVariableOp/transpose because it has fewer than 1024 elements (288)

按错误提示修改反而crash了

2019-07-11 11:09:30.601131: W tensorflow/lite/toco/toco_cmdline_flags.cc:283] --input_type is deprecated. It was an ambiguous flag that set both --input_data_types and --inference_input_type. If you are trying to complement the input file with information about the type of input arrays, use --input_data_type. If you are trying to control the quantization/dequantization of real-numbers input arrays in the output file, use --inference_input_type.

./toco --input_file='30_cnn.tflite' --input_format=TFLITE --output_format=TFLITE --output_file='quanized_30_cnn.tflite' --inference_input_type=FLOAT --input_data_type=FLOAT --input_arrays=conv1d_input --output_arrays=Identity --input_shapes=1,80,3 --post_training_quantize
2019-07-11 12:05:17.201982: F tensorflow/lite/toco/model_cmdline_flags.cc:289] Check failed: uses_single_input_flags 
[1]    25774 abort (core dumped)  ./toco --input_file='30_cnn.tflite' --input_format=TFLITE 

quantilize前后的文件大小变化过程

-rw-r--r--  1 ws ws   195212 7月  10 17:55 30_cnn.tflite

-rw-r--r--  1 ws ws    55872 7月  11 11:09 quanized_30_cnn.tflite

Tensor   0 Identity             kTfLiteFloat32  kTfLiteArenaRw         24 bytes ( 0.0 MB)  1 6
Tensor   1 conv1d_input         kTfLiteFloat32  kTfLiteArenaRw        960 bytes ( 0.0 MB)  1 80 3
Tensor   2 sequential/conv1d/Relu kTfLiteFloat32  kTfLiteArenaRw       8520 bytes ( 0.0 MB)  1 1 71 30
Tensor   3 sequential/conv1d/conv1d/ExpandDims kTfLiteFloat32  kTfLiteArenaRw        960 bytes ( 0.0 MB)  1 1 80 3
Tensor   4 sequential/conv1d/conv1d/ExpandDims/dim_0 kTfLiteInt32   kTfLiteMmapRo         16 bytes ( 0.0 MB)  1 4
Tensor   5 sequential/conv1d/conv1d/ExpandDims_1 kTfLiteFloat32   kTfLiteMmapRo       3600 bytes ( 0.0 MB)  30 1 10 3
Tensor   6 sequential/conv1d/conv1d_bias kTfLiteFloat32   kTfLiteMmapRo        120 bytes ( 0.0 MB)  30
Tensor   7 sequential/conv1d_1/conv1d/ExpandDims_1 kTfLiteFloat32   kTfLiteMmapRo      36000 bytes ( 0.0 MB)  30 1 10 30
Tensor   8 sequential/conv1d_1/conv1d/Squeeze kTfLiteFloat32  kTfLiteArenaRw       7440 bytes ( 0.0 MB)  1 1 62 30
Tensor   9 sequential/conv1d_1/conv1d_bias kTfLiteFloat32   kTfLiteMmapRo        120 bytes ( 0.0 MB)  30
Tensor  10 sequential/conv1d_2/conv1d/ExpandDims kTfLiteFloat32  kTfLiteArenaRw       2400 bytes ( 0.0 MB)  1 1 20 30
Tensor  11 sequential/conv1d_2/conv1d/ExpandDims/dim_0 kTfLiteInt32   kTfLiteMmapRo         16 bytes ( 0.0 MB)  1 4
Tensor  12 sequential/conv1d_2/conv1d/ExpandDims_1 kTfLiteFloat32   kTfLiteMmapRo      57600 bytes ( 0.1 MB)  48 1 10 30
Tensor  13 sequential/conv1d_2/conv1d/Squeeze kTfLiteFloat32  kTfLiteArenaRw       2112 bytes ( 0.0 MB)  1 1 11 48
Tensor  14 sequential/conv1d_2/conv1d_bias kTfLiteFloat32   kTfLiteMmapRo        192 bytes ( 0.0 MB)  48
Tensor  15 sequential/conv1d_3/Relu kTfLiteFloat32  kTfLiteArenaRw        384 bytes ( 0.0 MB)  1 2 48
Tensor  16 sequential/conv1d_3/conv1d/ExpandDims_1 kTfLiteFloat32   kTfLiteMmapRo      92160 bytes ( 0.1 MB)  48 1 10 48
Tensor  17 sequential/conv1d_3/conv1d/Squeeze kTfLiteFloat32  kTfLiteArenaRw        384 bytes ( 0.0 MB)  1 1 2 48
Tensor  18 sequential/conv1d_3/conv1d/Squeeze_shape kTfLiteInt32   kTfLiteMmapRo         12 bytes ( 0.0 MB)  3
Tensor  19 sequential/conv1d_3/conv1d_bias kTfLiteFloat32   kTfLiteMmapRo        192 bytes ( 0.0 MB)  48
Tensor  20 sequential/dense/BiasAdd kTfLiteFloat32  kTfLiteArenaRw         24 bytes ( 0.0 MB)  1 6
Tensor  21 sequential/dense/MatMul/ReadVariableOp/transpose kTfLiteFloat32   kTfLiteMmapRo       1152 bytes ( 0.0 MB)  6 48
Tensor  22 sequential/dense/MatMul_bias kTfLiteFloat32   kTfLiteMmapRo         24 bytes ( 0.0 MB)  6
Tensor  23 sequential/global_average_pooling1d/Mean kTfLiteFloat32  kTfLiteArenaRw        192 bytes ( 0.0 MB)  1 48
Tensor  24 sequential/global_average_pooling1d/Mean/reduction_indices kTfLiteInt32   kTfLiteMmapRo          4 bytes ( 0.0 MB) 
Tensor  25 sequential/max_pooling1d/ExpandDims kTfLiteFloat32  kTfLiteArenaRw       7440 bytes ( 0.0 MB)  1 62 1 30
Tensor  26 sequential/max_pooling1d/ExpandDims/dim_0 kTfLiteInt32   kTfLiteMmapRo         16 bytes ( 0.0 MB)  1 4
Tensor  27 sequential/max_pooling1d/MaxPool kTfLiteFloat32  kTfLiteArenaRw       2400 bytes ( 0.0 MB)  1 20 1 30

 

Tensor   0 Identity             kTfLiteFloat32  kTfLiteArenaRw         24 bytes ( 0.0 MB)  1 6
Tensor   1 conv1d_input         kTfLiteFloat32  kTfLiteArenaRw        960 bytes ( 0.0 MB)  1 80 3
Tensor   2 sequential/conv1d/Relu kTfLiteFloat32  kTfLiteArenaRw       8520 bytes ( 0.0 MB)  1 1 71 30
Tensor   3 sequential/conv1d/conv1d/ExpandDims kTfLiteFloat32  kTfLiteArenaRw        960 bytes ( 0.0 MB)  1 1 80 3
Tensor   4 sequential/conv1d/conv1d/ExpandDims/dim_0 kTfLiteInt32   kTfLiteMmapRo         16 bytes ( 0.0 MB)  1 4
Tensor   5 sequential/conv1d/conv1d/ExpandDims_1 kTfLiteFloat32   kTfLiteMmapRo       3600 bytes ( 0.0 MB)  30 1 10 3
Tensor   6 sequential/conv1d/conv1d_bias kTfLiteFloat32   kTfLiteMmapRo        120 bytes ( 0.0 MB)  30
Tensor   7 sequential/conv1d_1/conv1d/ExpandDims_1 kTfLiteUInt8   kTfLiteMmapRo       9000 bytes ( 0.0 MB)  30 1 10 30
Tensor   8 sequential/conv1d_1/conv1d/Squeeze kTfLiteFloat32  kTfLiteArenaRw       7440 bytes ( 0.0 MB)  1 1 62 30
Tensor   9 sequential/conv1d_1/conv1d_bias kTfLiteFloat32   kTfLiteMmapRo        120 bytes ( 0.0 MB)  30
Tensor  10 sequential/conv1d_2/conv1d/ExpandDims kTfLiteFloat32  kTfLiteArenaRw       2400 bytes ( 0.0 MB)  1 1 20 30
Tensor  11 sequential/conv1d_2/conv1d/ExpandDims/dim_0 kTfLiteInt32   kTfLiteMmapRo         16 bytes ( 0.0 MB)  1 4
Tensor  12 sequential/conv1d_2/conv1d/ExpandDims_1 kTfLiteUInt8   kTfLiteMmapRo      14400 bytes ( 0.0 MB)  48 1 10 30
Tensor  13 sequential/conv1d_2/conv1d/Squeeze kTfLiteFloat32  kTfLiteArenaRw       2112 bytes ( 0.0 MB)  1 1 11 48
Tensor  14 sequential/conv1d_2/conv1d_bias kTfLiteFloat32   kTfLiteMmapRo        192 bytes ( 0.0 MB)  48
Tensor  15 sequential/conv1d_3/Relu kTfLiteFloat32  kTfLiteArenaRw        384 bytes ( 0.0 MB)  1 2 48
Tensor  16 sequential/conv1d_3/conv1d/ExpandDims_1 kTfLiteUInt8   kTfLiteMmapRo      23040 bytes ( 0.0 MB)  48 1 10 48
Tensor  17 sequential/conv1d_3/conv1d/Squeeze kTfLiteFloat32  kTfLiteArenaRw        384 bytes ( 0.0 MB)  1 1 2 48
Tensor  18 sequential/conv1d_3/conv1d/Squeeze_shape kTfLiteInt32   kTfLiteMmapRo         12 bytes ( 0.0 MB)  3
Tensor  19 sequential/conv1d_3/conv1d_bias kTfLiteFloat32   kTfLiteMmapRo        192 bytes ( 0.0 MB)  48
Tensor  20 sequential/dense/BiasAdd kTfLiteFloat32  kTfLiteArenaRw         24 bytes ( 0.0 MB)  1 6
Tensor  21 sequential/dense/MatMul/ReadVariableOp/transpose kTfLiteFloat32   kTfLiteMmapRo       1152 bytes ( 0.0 MB)  6 48
Tensor  22 sequential/dense/MatMul_bias kTfLiteFloat32   kTfLiteMmapRo         24 bytes ( 0.0 MB)  6
Tensor  23 sequential/global_average_pooling1d/Mean kTfLiteFloat32  kTfLiteArenaRw        192 bytes ( 0.0 MB)  1 48
Tensor  24 sequential/global_average_pooling1d/Mean/reduction_indices kTfLiteInt32   kTfLiteMmapRo          4 bytes ( 0.0 MB) 
Tensor  25 sequential/max_pooling1d/ExpandDims kTfLiteFloat32  kTfLiteArenaRw       7440 bytes ( 0.0 MB)  1 62 1 30
Tensor  26 sequential/max_pooling1d/ExpandDims/dim_0 kTfLiteInt32   kTfLiteMmapRo         16 bytes ( 0.0 MB)  1 4
Tensor  27 sequential/max_pooling1d/MaxPool kTfLiteFloat32  kTfLiteArenaRw       2400 bytes ( 0.0 MB)  1 20 1 30
 

这篇关于TfLite: 把pb、h5文件转换为TfLite格式and quantilize的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1027314

相关文章

Python将博客内容html导出为Markdown格式

《Python将博客内容html导出为Markdown格式》Python将博客内容html导出为Markdown格式,通过博客url地址抓取文章,分析并提取出文章标题和内容,将内容构建成html,再转... 目录一、为什么要搞?二、准备如何搞?三、说搞咱就搞!抓取文章提取内容构建html转存markdown

Java实现时间与字符串互相转换详解

《Java实现时间与字符串互相转换详解》这篇文章主要为大家详细介绍了Java中实现时间与字符串互相转换的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、日期格式化为字符串(一)使用预定义格式(二)自定义格式二、字符串解析为日期(一)解析ISO格式字符串(二)解析自定义

在java中如何将inputStream对象转换为File对象(不生成本地文件)

《在java中如何将inputStream对象转换为File对象(不生成本地文件)》:本文主要介绍在java中如何将inputStream对象转换为File对象(不生成本地文件),具有很好的参考价... 目录需求说明问题解决总结需求说明在后端中通过POI生成Excel文件流,将输出流(outputStre

python+opencv处理颜色之将目标颜色转换实例代码

《python+opencv处理颜色之将目标颜色转换实例代码》OpenCV是一个的跨平台计算机视觉库,可以运行在Linux、Windows和MacOS操作系统上,:本文主要介绍python+ope... 目录下面是代码+ 效果 + 解释转HSV: 关于颜色总是要转HSV的掩膜再标注总结 目标:将红色的部分滤

利用Python开发Markdown表格结构转换为Excel工具

《利用Python开发Markdown表格结构转换为Excel工具》在数据管理和文档编写过程中,我们经常使用Markdown来记录表格数据,但它没有Excel使用方便,所以本文将使用Python编写一... 目录1.完整代码2. 项目概述3. 代码解析3.1 依赖库3.2 GUI 设计3.3 解析 Mark

如何自定义Nginx JSON日志格式配置

《如何自定义NginxJSON日志格式配置》Nginx作为最流行的Web服务器之一,其灵活的日志配置能力允许我们根据需求定制日志格式,本文将详细介绍如何配置Nginx以JSON格式记录访问日志,这种... 目录前言为什么选择jsON格式日志?配置步骤详解1. 安装Nginx服务2. 自定义JSON日志格式各

python dict转换成json格式的实现

《pythondict转换成json格式的实现》本文主要介绍了pythondict转换成json格式的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下... 一开始你变成字典格式data = [ { 'a' : 1, 'b' : 2, 'c编程' : 3,

C语言中的数据类型强制转换

《C语言中的数据类型强制转换》:本文主要介绍C语言中的数据类型强制转换方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C语言数据类型强制转换自动转换强制转换类型总结C语言数据类型强制转换强制类型转换:是通过类型转换运算来实现的,主要的数据类型转换分为自动转换

Java实现XML与JSON的互相转换详解

《Java实现XML与JSON的互相转换详解》这篇文章主要为大家详细介绍了如何使用Java实现XML与JSON的互相转换,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. XML转jsON1.1 代码目的1.2 代码实现2. JSON转XML3. JSON转XML并输出成指定的

Java实现将Markdown转换为纯文本

《Java实现将Markdown转换为纯文本》这篇文章主要为大家详细介绍了两种在Java中实现Markdown转纯文本的主流方法,文中的示例代码讲解详细,大家可以根据需求选择适合的方案... 目录方法一:使用正则表达式(轻量级方案)方法二:使用 Flexmark-Java 库(专业方案)1. 添加依赖(Ma