0

我正在尝试将现有的 VGG 模型(在 1 个类上训练)从 Darknet 格式(包括 .cfg 文件和 .weights 文件)转换为 TensorFlow 格式。最终目标是将 TensorFlow 格式的文件与英特尔 OpenVINO 工具包一起使用。

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

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

我并不是专门寻找以下错误的直接解决方案,而是寻找可以将 Darknet 格式的 VGG 转换为 TensorFlow 或任何其他途径的最佳方法,以便我可以将模型与英特尔 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].

4

1 回答 1

0

我建议您查看以下教程,以获得将 Yolov3 转换为 OpenVINO xml、bin 格式的良好指导。

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

想法是从

然后,使用 convert_weights_pb.py 脚本对其进行转换,使其准备好进行 IR 格式转换。

于 2019-07-17T11:07:20.990 回答