NPU tensorflow pb 转换问题

我在使用 OCR 测试的时候,模型转换不了:

pb 文件:
链接:百度网盘 请输入提取码
提取码:vrtl

转换命令:

./bin/convertensorflow --tf-pb model.pb --inputs “Placeholder Placeholder_1” --input-size-list ‘300,300,3#3’ --outputs “rpn_cls_score/Reshape_1” --net-output /Data/tgz/aml_npu_sdk/ocr-vgg.json --data-output ocr-vgg.data

相关代码:
GitHub - youkpan/chinese_ocr: CTPN + DenseNet + CTC based end-to-end Chinese OCR implemented using tensorflow and keras

里面最后一层确实调用了 pyfun 的函数
但是 我不能抽头 抽出几个倒数几个层的接口吗 ,
真正最后输出的是 rois/Reshape

node 列表:
box.hayoou.com/1587977132260/nodes.txt

执行结果:
./bin/convertensorflow --tf-pb /Data/tgz/model.pb --inputs “Placeholder Placeholder_1” --input-size-list ‘300,300,3#3’ --outputs “rpn_cls_score/Reshape_1” --net-output /Data/tgz/aml_npu_sdk/ocr-vgg.json --data-output ocr-vgg.data
Traceback (most recent call last):
File “convertensorflow.py”, line 62, in
File “convertensorflow.py”, line 58, in main
File “acuitylib/app/importer/import_tensorflow.py”, line 81, in run
File “acuitylib/converter/convert_tf.py”, line 80, in init
File “acuitylib/converter/convert_tf.py”, line 80, in
ValueError: invalid literal for int() with base 10: ‘‘300’
[30718] Failed to execute script convertensorflow

目前不能

这个模型是你自己训练的还是直接从网上拿的

模型是网上的,我自己转换了一次。全部相关node 都导出到pb 文件了
上面那个model.pb 是去掉了最后一层的,因为里面有python function 。
我这里有个完整的 ,导出也是错误 ,因为pyfun 的operation 操作符是不能转换的。
model_all
链接:https://pan.baidu.com/s/1UKKNhPIM2XiXAnfA5xp8NQ
提取码:8uer

./bin/convertensorflow --tf-pb model_all.pb --inputs “Placeholder Placeholder_1” --input-size-list ‘300,300,3#3’ --outputs “rois/Reshape” --net-output ocr-vgg.json --data-output ocr-vgg.data
I Current TF Model producer version 0 min consumer version 0 bad consumer version []
I short-cut lstm_o/bidirectional_rnn/fw/lstm_cell/bias:out0 - lstm_o/bidirectional_rnn/fw/fw/while/lstm_cell/BiasAdd/Enter:in0 skip lstm_o/bidirectional_rnn/fw/lstm_cell/bias/read
I short-cut conv3_1/biases:out0 - conv3_1/BiasAdd:in1 skip conv3_1/biases/read
I short-cut rpn_conv/3x3/biases:out0 - rpn_conv/3x3/BiasAdd:in1 skip rpn_conv/3x3/biases/read
I short-cut rpn_cls_score/weights:out0 - rpn_cls_score/MatMul:in1 skip rpn_cls_score/weights/read
I short-cut lstm_o/biases:out0 - lstm_o/add:in1 skip lstm_o/biases/read
I short-cut lstm_o/bidirectional_rnn/bw/lstm_cell/kernel:out0 - lstm_o/bidirectional_rnn/bw/bw/while/lstm_cell/MatMul/Enter:in0 skip lstm_o/bidirectional_rnn/bw/lstm_cell/kernel/read
I short-cut conv3_3/biases:out0 - conv3_3/BiasAdd:in1 skip conv3_3/biases/read
I short-cut conv5_3/biases:out0 - conv5_3/BiasAdd:in1 skip conv5_3/biases/read
I short-cut conv1_2/weights:out0 - conv1_2/Conv2D:in1 skip conv1_2/weights/read
I short-cut conv2_1/weights:out0 - conv2_1/Conv2D:in1 skip conv2_1/weights/read
I short-cut conv3_2/biases:out0 - conv3_2/BiasAdd:in1 skip conv3_2/biases/read
I short-cut conv4_2/biases:out0 - conv4_2/BiasAdd:in1 skip conv4_2/biases/read
I short-cut conv2_2/biases:out0 - conv2_2/BiasAdd:in1 skip conv2_2/biases/read
I short-cut rpn_bbox_pred/biases:out0 - rpn_bbox_pred/add:in1 skip rpn_bbox_pred/biases/read
I short-cut lstm_o/weights:out0 - lstm_o/MatMul:in1 skip lstm_o/weights/read
I short-cut rpn_bbox_pred/weights:out0 - rpn_bbox_pred/MatMul:in1 skip rpn_bbox_pred/weights/read
I short-cut conv1_2/biases:out0 - conv1_2/BiasAdd:in1 skip conv1_2/biases/read
I short-cut conv3_3/weights:out0 - conv3_3/Conv2D:in1 skip conv3_3/weights/read
I short-cut conv3_1/weights:out0 - conv3_1/Conv2D:in1 skip conv3_1/weights/read
I short-cut conv2_2/weights:out0 - conv2_2/Conv2D:in1 skip conv2_2/weights/read
I short-cut conv4_3/biases:out0 - conv4_3/BiasAdd:in1 skip conv4_3/biases/read
I short-cut conv4_3/weights:out0 - conv4_3/Conv2D:in1 skip conv4_3/weights/read
I short-cut conv5_1/biases:out0 - conv5_1/BiasAdd:in1 skip conv5_1/biases/read
I short-cut conv4_2/weights:out0 - conv4_2/Conv2D:in1 skip conv4_2/weights/read
I short-cut lstm_o/bidirectional_rnn/bw/lstm_cell/bias:out0 - lstm_o/bidirectional_rnn/bw/bw/while/lstm_cell/BiasAdd/Enter:in0 skip lstm_o/bidirectional_rnn/bw/lstm_cell/bias/read
I short-cut conv5_2/weights:out0 - conv5_2/Conv2D:in1 skip conv5_2/weights/read
I short-cut rpn_cls_score/biases:out0 - rpn_cls_score/add:in1 skip rpn_cls_score/biases/read
I short-cut conv1_1/biases:out0 - conv1_1/BiasAdd:in1 skip conv1_1/biases/read
I short-cut conv2_1/biases:out0 - conv2_1/BiasAdd:in1 skip conv2_1/biases/read
I short-cut conv1_1/weights:out0 - conv1_1/Conv2D:in1 skip conv1_1/weights/read
I short-cut conv4_1/weights:out0 - conv4_1/Conv2D:in1 skip conv4_1/weights/read
I short-cut conv3_2/weights:out0 - conv3_2/Conv2D:in1 skip conv3_2/weights/read
I short-cut lstm_o/bidirectional_rnn/fw/lstm_cell/kernel:out0 - lstm_o/bidirectional_rnn/fw/fw/while/lstm_cell/MatMul/Enter:in0 skip lstm_o/bidirectional_rnn/fw/lstm_cell/kernel/read
I short-cut rpn_conv/3x3/weights:out0 - rpn_conv/3x3/Conv2D:in1 skip rpn_conv/3x3/weights/read
I short-cut conv5_3/weights:out0 - conv5_3/Conv2D:in1 skip conv5_3/weights/read
I short-cut conv5_2/biases:out0 - conv5_2/BiasAdd:in1 skip conv5_2/biases/read
I short-cut conv5_1/weights:out0 - conv5_1/Conv2D:in1 skip conv5_1/weights/read
I short-cut conv4_1/biases:out0 - conv4_1/BiasAdd:in1 skip conv4_1/biases/read
I Have 25 tensors convert to const tensor
[‘lstm_o/bidirectional_rnn/bw/bw/Minimum:out0’, ‘Reshape/shape:out0’, ‘Reshape_1/shape:out0’, ‘lstm_o/bidirectional_rnn/fw/fw/strided_slice_1:out0’, ‘lstm_o/Reshape/shape:out0’, ‘lstm_o/bidirectional_rnn/bw/bw/LSTMCellZeroState/zeros:out0’, ‘lstm_o/bidirectional_rnn/bw/bw/concat_2:out0’, ‘Reshape_2/shape:out0’, ‘lstm_o/bidirectional_rnn/fw/fw/concat_2:out0’, ‘rpn_cls_score/Reshape/shape:out0’, ‘lstm_o/bidirectional_rnn/bw/bw/TensorArrayUnstack/range:out0’, ‘rpn_cls_prob/shape:out0’, ‘lstm_o/bidirectional_rnn/fw/fw/Minimum:out0’, ‘lstm_o/bidirectional_rnn/fw/fw/concat:out0’, ‘rpn_cls_score/Reshape_1/shape:out0’, ‘lstm_o/bidirectional_rnn/fw/fw/TensorArrayUnstack/range:out0’, ‘lstm_o/bidirectional_rnn/fw/fw/LSTMCellZeroState/zeros_1:out0’, ‘rpn_bbox_pred/Reshape_1/shape:out0’, ‘lstm_o/Reshape_2/shape:out0’, ‘lstm_o/Reshape_1/shape:out0’, ‘lstm_o/bidirectional_rnn/bw/bw/strided_slice_1:out0’, ‘lstm_o/bidirectional_rnn/bw/bw/LSTMCellZeroState/zeros_1:out0’, ‘rpn_bbox_pred/Reshape/shape:out0’, ‘lstm_o/bidirectional_rnn/fw/fw/LSTMCellZeroState/zeros:out0’, ‘lstm_o/bidirectional_rnn/bw/bw/concat:out0’]
2020-04-27 23:01:16.684071: W tensorflow/core/framework/allocator.cc:108] Allocation of 9437184 exceeds 10% of system memory.
2020-04-27 23:01:16.691500: W tensorflow/core/framework/allocator.cc:108] Allocation of 9437184 exceeds 10% of system memory.
2020-04-27 23:01:16.696836: W tensorflow/core/framework/allocator.cc:108] Allocation of 9437184 exceeds 10% of system memory.
2020-04-27 23:01:16.702320: W tensorflow/core/framework/allocator.cc:108] Allocation of 9437184 exceeds 10% of system memory.
2020-04-27 23:01:16.707087: W tensorflow/core/framework/allocator.cc:108] Allocation of 9437184 exceeds 10% of system memory.
I build output layer attach_rois/Reshape:out0
I build input layer Placeholder:out0
I build input layer Placeholder_1:out0
D Try match Reshape rois/Reshape
I Match reshape [[‘rois/Reshape’, ‘rois/Reshape/shape’]] [[‘Reshape’, ‘C’]] to [[‘reshape’]]
D Try match PyFunc rois/PyFunc
W Not match node rois/PyFunc PyFunc
Traceback (most recent call last):
File “convertensorflow.py”, line 62, in
File “convertensorflow.py”, line 58, in main
File “acuitylib/app/importer/import_tensorflow.py”, line 150, in run
File “acuitylib/converter/convert_tf.py”, line 584, in match_paragraph_and_param
File “acuitylib/converter/convert_tf.py”, line 483, in _tf_push_ready_node
TypeError: ‘NoneType’ object is not iterable
[2497] Failed to execute script convertensorflow

@hayoou 既然是这样,建议你在这个pb的基础上,拿掉最后一层,留你需要的层做输出,重新训练再转换吧,有一些层这个工具是不支持的.

我们测试了很多次,包括修改 pbtxt 或者替换里面的input ,但都是同样错误。

@hayoou不是很清楚原因,可能是你们使用了哪些不支持的层