Open tosonw opened 4 years ago
@tosonw 请问yolov4-tiny 您可以使用了么?
@LVROBOT 不能
To enable yolov4-tiny, only yolo_to_onnx.py needs to be patched as the existing script lacks the 'groups' support. The patch is borrowed from @jkjung-avt's repo, specifically the __make_routenode function:
`def _make_route_node(self, layer_name, layer_dict):
"""If the 'layers' parameter from the DarkNet configuration is only one index, continue
node creation at the indicated (negative) index. Otherwise, create an ONNX Concat node
with the route properties from the DarkNet-based graph.
Keyword arguments:
layer_name -- the layer's name (also the corresponding key in layer_configs)
layer_dict -- a layer parameter dictionary (one element of layer_configs)
"""
route_node_indexes = layer_dict['layers']
if len(route_node_indexes) == 1:
if 'groups' in layer_dict.keys():
# for CSPNet-kind of architecture
assert 'group_id' in layer_dict.keys()
groups = layer_dict['groups']
group_id = int(layer_dict['group_id'])
assert group_id < groups
index = route_node_indexes[0]
if index > 0:
# +1 for input node (same reason as below)
index += 1
route_node_specs = self._get_previous_node_specs(target_index=index)
assert route_node_specs.channels % groups == 0
channels = route_node_specs.channels // groups
outputs = [layer_name + '_%d' % i for i in range(groups)]
outputs[group_id] = layer_name
route_node = helper.make_node(
'Split',
axis=1,
split=[channels] * groups,
inputs=[route_node_specs.name],
outputs=outputs,
name=layer_name,
)
self._nodes.append(route_node)
else:
index = route_node_indexes[0]
if index > 0 :
index +=1
route_node_specs = self._get_previous_node_specs(target_index=index)
layer_name = route_node_specs.name
channels = route_node_specs.channels
else:
inputs = list()
channels = 0
for index in route_node_indexes:
if index > 0:
# Increment by one because we count the input as a node (DarkNet
# does not)
index += 1
route_node_specs = self._get_previous_node_specs(
target_index=index)
inputs.append(route_node_specs.name)
channels += route_node_specs.channels
assert inputs
assert channels > 0
route_node = helper.make_node(
'Concat',
axis=1,
inputs=inputs,
outputs=[layer_name],
name=layer_name,
)
self._nodes.append(route_node)
return layer_name, channels`
@tosonw 请问yolov4-tiny 您可以使用了么?
我实现了一版yolov4-tiny-tensorrt https://github.com/tjuskyzhang/yolov4-tiny-tensorrt
您好,我修改好了yolov4-tiny的cfg文件,但在转换yolov4-tiny为onnx时失败了,cfg文件如下: [net]
Testing
batch=1
subdivisions=1
Training
batch=64 subdivisions=1 width=416 height=416 channels=3 momentum=0.9 decay=0.0005 angle=0 saturation = 1.5 exposure = 1.5 hue=.1
learning_rate=0.00261 burn_in=1000 max_batches = 500200 policy=steps steps=400000,450000 scales=.1,.1
[convolutional] batch_normalize=1 filters=32 size=3 stride=2 pad=1 activation=leaky
[convolutional] batch_normalize=1 filters=64 size=3 stride=2 pad=1 activation=leaky
[convolutional] batch_normalize=1 filters=64 size=3 stride=1 pad=1 activation=leaky
[route] layers=-1 groups=2 group_id=1
[convolutional] batch_normalize=1 filters=32 size=3 stride=1 pad=1 activation=leaky
[convolutional] batch_normalize=1 filters=32 size=3 stride=1 pad=1 activation=leaky
[route] layers = -1,-2
[convolutional] batch_normalize=1 filters=64 size=1 stride=1 pad=1 activation=leaky
[route] layers = -6,-1
[maxpool] size=2 stride=2
[convolutional] batch_normalize=1 filters=128 size=3 stride=1 pad=1 activation=leaky
[route] layers=-1 groups=2 group_id=1
[convolutional] batch_normalize=1 filters=64 size=3 stride=1 pad=1 activation=leaky
[convolutional] batch_normalize=1 filters=64 size=3 stride=1 pad=1 activation=leaky
[route] layers = -1,-2
[convolutional] batch_normalize=1 filters=128 size=1 stride=1 pad=1 activation=leaky
[route] layers = -6,-1
[maxpool] size=2 stride=2
[convolutional] batch_normalize=1 filters=256 size=3 stride=1 pad=1 activation=leaky
[route] layers=-1 groups=2 group_id=1
[convolutional] batch_normalize=1 filters=128 size=3 stride=1 pad=1 activation=leaky
[convolutional] batch_normalize=1 filters=128 size=3 stride=1 pad=1 activation=leaky
[route] layers = -1,-2
[convolutional] batch_normalize=1 filters=256 size=1 stride=1 pad=1 activation=leaky
[route] layers = -6,-1
[maxpool] size=2 stride=2
[convolutional] batch_normalize=1 filters=512 size=3 stride=1 pad=1 activation=leaky
##################################
[convolutional] batch_normalize=1 filters=256 size=1 stride=1 pad=1 activation=leaky
[convolutional] batch_normalize=1 filters=512 size=3 stride=1 pad=1 activation=leaky
[convolutional] size=1 stride=1 pad=1 filters=255 activation=linear
[yolo] mask = 3,4,5 anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 classes=80 down_stride = 32 infer_thresh = 0.25 num=6 jitter=.3 scale_x_y = 1.05 cls_normalizer=1.0 iou_normalizer=0.07 iou_loss=ciou ignore_thresh = .7 truth_thresh = 1 random=0 resize=1.5 nms_kind=greedynms beta_nms=0.6
[route] layers = -4
[convolutional] batch_normalize=1 filters=128 size=1 stride=1 pad=1 activation=leaky
[upsample] stride=2
[route] layers = -1, 23
[convolutional] batch_normalize=1 filters=256 size=3 stride=1 pad=1 activation=leaky
[convolutional] size=1 stride=1 pad=1 filters=255 activation=linear
[yolo] mask = 1,2,3 anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 classes=80 down_stride = 16 infer_thresh = 0.25 num=6 jitter=.3 scale_x_y = 1.05 cls_normalizer=1.0 iou_normalizer=0.07 iou_loss=ciou ignore_thresh = .7 truth_thresh = 1 random=0 resize=1.5 nms_kind=greedynms beta_nms=0.6
报错如下: Traceback (most recent call last): File "tools/yolo_to_onnx.py", line 748, in
main()
File "tools/yolo_to_onnx.py", line 743, in main
verbose=True)
File "tools/yolo_to_onnx.py", line 345, in build_onnx_graph
conv_params)
File "tools/yolo_to_onnx.py", line 219, in load_conv_weights
conv_params, 'conv', 'weights')
File "tools/yolo_to_onnx.py", line 248, in _create_param_tensors
conv_params, param_category, suffix)
File "tools/yolo_to_onnx.py", line 280, in _load_one_param_type
buffer=self.weights_file.read(param_size * 4))
TypeError: buffer is too small for requested array
我也安装yolov3-tiny的样式把cfg的第二个yolo层的mask改为0,1,2,down_stride的大小也上下替换过,但都报错,请问这个是需要怎么修改??