如何将VGG从darknet转换为张量



我试图将现有的VGG模型(在1类中训练(从darknet格式(包括.cfg文件和.puferate文件(转换为tensorflow格式。最终目标是使用Intel OpenVino Toolkit以Tensorflow格式使用文件。

作为初次尝试,我尝试使用DW2TF,但在运行程序时遇到了错误。

我首先尝试使用Pjreddie网站上提供的官方文件,并遇到以下错误。

我不是专门寻找以下错误的直接解决方案,而是寻找最佳的方法,可以将Darknet格式的VGG转换为TensorFlow或任何其他途径,以便我可以与Intel OpenVino一起使用该模型工具包。欢迎任何评论或建议。

感谢您的阅读。


使用的命令:

python3 main.py
--cfg data/vgg-16.cfg
--weights data/vgg-16.weights
--output output
--gpu 0

收到的错误:

0 Tensor("network/net1:0", shape=(?, 256, 256, 3), dtype=float32)
=> Ignore:  {'name': 'crop', 'crop_height': '224', 'crop_width': '224', 'flip': '1', 'exposure': '1', 'saturation': '1', 'angle': '0'}
1 Tensor("network/net1:0", shape=(?, 256, 256, 3), dtype=float32)
2 Tensor("network/convolutional1/Activation:0", shape=(?, 256, 256, 64), dtype=float32)
3 Tensor("network/convolutional2/Activation:0", shape=(?, 256, 256, 64), dtype=float32)
4 Tensor("network/maxpool1/MaxPool:0", shape=(?, 128, 128, 64), dtype=float32)
5 Tensor("network/convolutional3/Activation:0", shape=(?, 128, 128, 128), dtype=float32)
6 Tensor("network/convolutional4/Activation:0", shape=(?, 128, 128, 128), dtype=float32)
7 Tensor("network/maxpool2/MaxPool:0", shape=(?, 64, 64, 128), dtype=float32)
8 Tensor("network/convolutional5/Activation:0", shape=(?, 64, 64, 256), dtype=float32)
9 Tensor("network/convolutional6/Activation:0", shape=(?, 64, 64, 256), dtype=float32)
10 Tensor("network/convolutional7/Activation:0", shape=(?, 64, 64, 256), dtype=float32)
11 Tensor("network/maxpool3/MaxPool:0", shape=(?, 32, 32, 256), dtype=float32)
12 Tensor("network/convolutional8/Activation:0", shape=(?, 32, 32, 512), dtype=float32)
13 Tensor("network/convolutional9/Activation:0", shape=(?, 32, 32, 512), dtype=float32)
14 Tensor("network/convolutional10/Activation:0", shape=(?, 32, 32, 512), dtype=float32)
15 Tensor("network/maxpool4/MaxPool:0", shape=(?, 16, 16, 512), dtype=float32)
16 Tensor("network/convolutional11/Activation:0", shape=(?, 16, 16, 512), dtype=float32)
17 Tensor("network/convolutional12/Activation:0", shape=(?, 16, 16, 512), dtype=float32)
18 Tensor("network/convolutional13/Activation:0", shape=(?, 16, 16, 512), dtype=float32)
19 Tensor("network/maxpool5/MaxPool:0", shape=(?, 8, 8, 512), dtype=float32)
=> Ignore:  {'name': 'connected', 'output': '4096', 'activation': 'relu'}
20 Tensor("network/maxpool5/MaxPool:0", shape=(?, 8, 8, 512), dtype=float32)
=> Ignore:  {'name': 'dropout', 'probability': '.5'}
21 Tensor("network/maxpool5/MaxPool:0", shape=(?, 8, 8, 512), dtype=float32)
=> Ignore:  {'name': 'connected', 'output': '4096', 'activation': 'relu'}
22 Tensor("network/maxpool5/MaxPool:0", shape=(?, 8, 8, 512), dtype=float32)
=> Ignore:  {'name': 'dropout', 'probability': '.5'}
23 Tensor("network/maxpool5/MaxPool:0", shape=(?, 8, 8, 512), dtype=float32)
=> Ignore:  {'name': 'connected', 'output': '1000', 'activation': 'linear'}
24 Tensor("network/maxpool5/MaxPool:0", shape=(?, 8, 8, 512), dtype=float32)
Traceback (most recent call last):
  File "/home/acusensus/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1628, in _create_c_op
    c_op = c_api.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got 8 for 'network/softmax1/Squeeze' (op: 'Squeeze') with input shapes: [?,8,8,512].
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "main.py", line 112, in <module>
    main(args)
  File "main.py", line 53, in main
    parse_net(args.layers, args.cfg, args.weights, args.training)
  File "main.py", line 33, in parse_net
    training=training, const_inits=const_inits, verbose=verbose)
  File "/home/acusensus/usb_accel_proj/DW2TF/util/cfg_layer.py", line 198, in get_cfg_layer
    layer = _cfg_layer_dict.get(layer_name, cfg_ignore)(B, H, W, C, net, param, weights_walker, stack, output_index, scope, training, const_inits, verbose)
  File "/home/acusensus/usb_accel_proj/DW2TF/util/cfg_layer.py", line 169, in cfg_softmax
    net = tf.squeeze(net, axis=[1, 2], name=scope+'/Squeeze')
  File "/home/acusensus/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 488, in new_func
    return func(*args, **kwargs)
  File "/home/acusensus/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 2573, in squeeze
    return gen_array_ops.squeeze(input, axis, name)
  File "/home/acusensus/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 8236, in squeeze
    "Squeeze", input=input, squeeze_dims=axis, name=name)
  File "/home/acusensus/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/acusensus/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 488, in new_func
    return func(*args, **kwargs)
  File "/home/acusensus/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3274, in create_op
    op_def=op_def)
  File "/home/acusensus/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1792, in __init__
    control_input_ops)
  File "/home/acusensus/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1631, in _create_c_op
    raise ValueError(str(e))
ValueError: Can not squeeze dim[1], expected a dimension of 1, got 8 for 'network/softmax1/Squeeze' (op: 'Squeeze') with input shapes: [?,8,8,512].

我建议您在下面的教程中查看一个良好的指导,以转换yolov3 for Openvino XML,bin格式。

  • https://github.com/intel-iot-devkit/smart-video-workshop/blob/master/master/object/object/object/readme_yolov3.md

您还应该检查张量流的版本,尝试将其降级至1.12。本教程中的方法对我有用。

想法是从

获取体重转换工具
  • https://github.com/mystic123/tensorflow-yolo-v3

然后,使用convert_weights_pb.py脚本将其转换为IR格式转换。

相关内容

  • 没有找到相关文章

最新更新