Toybrick

facessd_mobilenet_v2_quantized_320x320模型转换出错

iamher0

注册会员

积分
111
楼主
发表于 2019-8-26 09:28:49    查看: 8921|回复: 4 | [复制链接]    打印 | 只看该作者
本帖最后由 iamher0 于 2019-8-26 09:40 编辑

http://download.tensorflow.org/models/object_detection/facessd_mobilenet_v2_quantized_320x320_open_image_v4.tar.gz
转换源码:
from rknn.api import RKNN  

INPUT_SIZE = 64

if __name__ == '__main__':
    # 创建RKNN执行对象
    rknn = RKNN()
# 配置模型输入,用于NPU对数据输入的预处理
# channel_mean_value='0 0 0 255',那么模型推理时,将会对RGB数据做如下转换
# (R - 0)/255, (G - 0)/255, (B - 0)/255。推理时,RKNN模型会自动做均值和归一化处理
# reorder_channel=’0 1 2’用于指定是否调整图像通道顺序,设置成0 1 2即按输入的图像通道顺序不做调整
# reorder_channel=’2 1 0’表示交换0和2通道,如果输入是RGB,将会被调整为BGR。如果是BGR将会被调整为RGB
#图像通道顺序不做调整
    rknn.config(channel_mean_value='0 0 0 255', reorder_channel='0 1 2')

# 加载TensorFlow模型
# tf_pb='digital_gesture.pb'指定待转换的TensorFlow模型
# inputs指定模型中的输入节点
# outputs指定模型中输出节点
# input_size_list指定模型输入的大小
    print('--> Loading model')
    rknn.load_tensorflow(tf_pb='frozen_inference_graph.pb',
                         inputs=['image_tensor'],
                         outputs=['detection_classes','num_detections','detection_boxes','detection_scores'],
                         input_size_list=[[320, 320, 3]])
    print('done')

# 创建解析pb模型
# do_quantization=False指定不进行量化
# 量化会减小模型的体积和提升运算速度,但是会有精度的丢失
    print('--> Building model')
    rknn.build(do_quantization=False)
    print('done')

    # 导出保存rknn模型文件
    rknn.export_rknn('./facemobilenetv2ssd.rknn')

    # Release RKNN Context
    rknn.release()



错误输出:
/usr/lib64/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
--> Loading model
E Catch exception when loading tensorflow model: frozen_inference_graph.pb!
T Traceback (most recent call last):
T   File "/home/toybrick/.local/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", line 418, in import_graph_def
T     graph._c_graph, serialized, options)  # pylint: disable=protected-access
T tensorflow.python.framework.errors_impl.InvalidArgumentError: NodeDef mentions attr 'Truncate' not in Op<name=Cast; signature=x:SrcT -> ystT; attr=SrcT:type; attr=DstT:type>; NodeDef: Cast = Cast[DstT=DT_FLOAT, SrcT=DT_UINT8, Truncate=false](image_tensor). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
T During handling of the above exception, another exception occurred:
T Traceback (most recent call last):
T   File "rknn/api/rknn_base.py", line 137, in rknn.api.rknn_base.RKNNBase.load_tensorflow
T   File "rknn/base/RKNNlib/converter/convert_tf.py", line 482, in rknn.base.RKNNlib.converter.convert_tf.convert_tf.pre_process
T   File "rknn/base/RKNNlib/converter/tensorflowloader.py", line 102, in rknn.base.RKNNlib.converter.tensorflowloader.TF_Graph_Preprocess.pre_proces
T   File "rknn/base/RKNNlib/converter/tensorflowloader.py", line 627, in rknn.base.RKNNlib.converter.tensorflowloader.TF_Graph_Preprocess.calc_2_const
T   File "rknn/base/RKNNlib/converter/tf_util.py", line 371, in rknn.base.RKNNlib.converter.tf_util.TFProto_Util.query_tensor
T   File "rknn/base/RKNNlib/converter/tf_util.py", line 372, in rknn.base.RKNNlib.converter.tf_util.TFProto_Util.query_tensor
T   File "/home/toybrick/.local/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 454, in new_func
T     return func(*args, **kwargs)
T   File "/home/toybrick/.local/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", line 422, in import_graph_def
T     raise ValueError(str(e))
T ValueError: NodeDef mentions attr 'Truncate' not in Op<name=Cast; signature=x:SrcT -> ystT; attr=SrcT:type; attr=DstT:type>; NodeDef: Cast = Cast[DstT=DT_FLOAT, SrcT=DT_UINT8, Truncate=false](image_tensor). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
done
--> Building model
E Model or data is None, please load model first.
done
E RKNN model data is None, please load model first!

回复

使用道具 举报

iamher0

注册会员

积分
111
沙发
 楼主| 发表于 2019-8-26 09:30:58 | 只看该作者
转换报了一大堆错误
回复

使用道具 举报

iamher0

注册会员

积分
111
板凳
 楼主| 发表于 2019-8-26 09:35:37 | 只看该作者
iamher0 发表于 2019-8-26 09:30
转换报了一大堆错误

from rknn.api import RKNN  

INPUT_SIZE = 64

if __name__ == '__main__':
    # 创建RKNN执行对象
    rknn = RKNN()
# 配置模型输入,用于NPU对数据输入的预处理
# channel_mean_value='0 0 0 255',那么模型推理时,将会对RGB数据做如下转换
# (R - 0)/255, (G - 0)/255, (B - 0)/255。推理时,RKNN模型会自动做均值和归一化处理
# reorder_channel=’0 1 2’用于指定是否调整图像通道顺序,设置成0 1 2即按输入的图像通道顺序不做调整
# reorder_channel=’2 1 0’表示交换0和2通道,如果输入是RGB,将会被调整为BGR。如果是BGR将会被调整为RGB
#图像通道顺序不做调整
    rknn.config(channel_mean_value='0 0 0 255', reorder_channel='0 1 2')

# 加载TensorFlow模型
# tf_pb='digital_gesture.pb'指定待转换的TensorFlow模型
# inputs指定模型中的输入节点
# outputs指定模型中输出节点
# input_size_list指定模型输入的大小
    print('--> Loading model')
    rknn.load_tensorflow(tf_pb='frozen_inference_graph.pb',
                         inputs=['image_tensor'],
                         outputs=['detection_classes','num_detections','detection_boxes','detection_scores'],
                         input_size_list=[[320, 320, 3]])
    print('done')

# 创建解析pb模型
# do_quantization=False指定不进行量化
# 量化会减小模型的体积和提升运算速度,但是会有精度的丢失
    print('--> Building model')
    rknn.build(do_quantization=False)
    print('done')

    # 导出保存rknn模型文件
    rknn.export_rknn('./facemobilenetv2ssd.rknn')

    # Release RKNN Context
    rknn.release()
回复

使用道具 举报

iamher0

注册会员

积分
111
地板
 楼主| 发表于 2019-8-26 09:36:25 | 只看该作者
iamher0 发表于 2019-8-26 09:35
from rknn.api import RKNN  

INPUT_SIZE = 64

/usr/lib64/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
--> Loading model
E Catch exception when loading tensorflow model: frozen_inference_graph.pb!
T Traceback (most recent call last):
T   File "/home/toybrick/.local/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", line 418, in import_graph_def
T     graph._c_graph, serialized, options)  # pylint: disable=protected-access
T tensorflow.python.framework.errors_impl.InvalidArgumentError: NodeDef mentions attr 'Truncate' not in Op<name=Cast; signature=x:SrcT -> ystT; attr=SrcT:type; attr=DstT:type>; NodeDef: Cast = Cast[DstT=DT_FLOAT, SrcT=DT_UINT8, Truncate=false](image_tensor). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
T During handling of the above exception, another exception occurred:
T Traceback (most recent call last):
T   File "rknn/api/rknn_base.py", line 137, in rknn.api.rknn_base.RKNNBase.load_tensorflow
T   File "rknn/base/RKNNlib/converter/convert_tf.py", line 482, in rknn.base.RKNNlib.converter.convert_tf.convert_tf.pre_process
T   File "rknn/base/RKNNlib/converter/tensorflowloader.py", line 102, in rknn.base.RKNNlib.converter.tensorflowloader.TF_Graph_Preprocess.pre_proces
T   File "rknn/base/RKNNlib/converter/tensorflowloader.py", line 627, in rknn.base.RKNNlib.converter.tensorflowloader.TF_Graph_Preprocess.calc_2_const
T   File "rknn/base/RKNNlib/converter/tf_util.py", line 371, in rknn.base.RKNNlib.converter.tf_util.TFProto_Util.query_tensor
T   File "rknn/base/RKNNlib/converter/tf_util.py", line 372, in rknn.base.RKNNlib.converter.tf_util.TFProto_Util.query_tensor
T   File "/home/toybrick/.local/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 454, in new_func
T     return func(*args, **kwargs)
T   File "/home/toybrick/.local/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", line 422, in import_graph_def
T     raise ValueError(str(e))
T ValueError: NodeDef mentions attr 'Truncate' not in Op<name=Cast; signature=x:SrcT -> ystT; attr=SrcT:type; attr=DstT:type>; NodeDef: Cast = Cast[DstT=DT_FLOAT, SrcT=DT_UINT8, Truncate=false](image_tensor). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
done
--> Building model
E Model or data is None, please load model first.
done
E RKNN model data is None, please load model first!
回复

使用道具 举报

Zen

中级会员

积分
201
5#
发表于 2019-8-28 09:24:11 | 只看该作者
看起来像是未定义的节点操作。改model 或是等rk 支持自定义层吧

----------------------------
T tensorflow.python.framework.errors_impl.InvalidArgumentError: NodeDef mentions attr 'Truncate' not in Op<name=Cast; signature=x:SrcT -> ystT; attr=SrcT:type; attr=DstT:type>; NodeDef: Cast = Cast[DstT=DT_FLOAT, SrcT=DT_UINT8, Truncate=false](image_tensor). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表