Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

加载 ncnn 模型失败 #5

Closed
popper0912 opened this issue Dec 17, 2018 · 4 comments
Closed

加载 ncnn 模型失败 #5

popper0912 opened this issue Dec 17, 2018 · 4 comments

Comments

@popper0912
Copy link

使用 Darknet 训练模型后,转化为 ncnn 模型,最后使用 ncnn 加载 .param 文件,返回 -1 ,加载失败。不知道何原因?使用caffe 训练的模型,转化后,可以加载成功。

@xiangweizeng
Copy link
Owner

应该是转换参数有问题, 找到出现错误的操作, 检查一下转换后的参数吧,如果方便可以提供下网络模型文件

@popper0912
Copy link
Author

应该是转换参数有问题, 找到出现错误的操作, 检查一下转换后的参数吧,如果方便可以提供下网络模型文件

我使用的是 yolov3-tiny 版的模型训练的自己的数据,darkNet cfg 文件如下:
[net]

Testing

batch=1
subdivisions=1

Training

#batch=64
#subdivisions=8
width=224
height=224
channels=1
momentum=0.9
decay=0.0005
angle=0
saturation = 1.0
exposure = 1.0
hue=0
flip=0

learning_rate=0.01
burn_in=1000
max_batches = 800000
policy=steps
steps=6000,20000,50000,100000
scales=.1,.1,.1,.1

[convolutional]
batch_normalize=1
filters=16
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=1

[convolutional]
batch_normalize=1
filters=1024
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=27
activation=linear

[yolo]
mask = 3,4,5
anchors = 21.2742,29.3429, 25.5435,43.5164, 28.0206,60.4466, 39.7142,54.9552, 33.7873,72.1623, 47.8516,66.9072, 45.8434,86.9286, 57.4758,106.0652, 110.5009,147.0255
classes=4
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=0

[route]
layers = -4

[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky

[upsample]
stride=2

[route]
layers = -1, 8

[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky

[convolutional]
size=1
stride=1
pad=1
filters=27
activation=linear

[yolo]
mask = 0,1,2
anchors = 21.2742,29.3429, 25.5435,43.5164, 28.0206,60.4466, 39.7142,54.9552, 33.7873,72.1623, 47.8516,66.9072, 45.8434,86.9286, 57.4758,106.0652, 110.5009,147.0255
classes=4
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=0

===========================================================
转化后的ncnn 模型 param 参数如下:
7767517
50 52
Input data 0 1 data 0=224 1=224 2=3
Convolution conv_0 1 1 data conv_0 0=16 1=3 2=1 3=1 4=1 5=0 6=432
BatchNorm conv_0_batch_norm 1 1 conv_0 conv_0_batch_norm 0=16 1=0.00001
ReLU conv_0_activation 1 1 conv_0_batch_norm conv_0_activation 0=0.1
Pooling maxpool_1 1 1 conv_0_activation maxpool_1 0=0 1=2 2=2 3=0 5=1 13=0 14=1 15=1
Convolution conv_2 1 1 maxpool_1 conv_2 0=32 1=3 2=1 3=1 4=1 5=0 6=4608
BatchNorm conv_2_batch_norm 1 1 conv_2 conv_2_batch_norm 0=32 1=0.00001
ReLU conv_2_activation 1 1 conv_2_batch_norm conv_2_activation 0=0.1
Pooling maxpool_3 1 1 conv_2_activation maxpool_3 0=0 1=2 2=2 3=0 5=1 13=0 14=1 15=1
Convolution conv_4 1 1 maxpool_3 conv_4 0=64 1=3 2=1 3=1 4=1 5=0 6=18432
BatchNorm conv_4_batch_norm 1 1 conv_4 conv_4_batch_norm 0=64 1=0.00001
ReLU conv_4_activation 1 1 conv_4_batch_norm conv_4_activation 0=0.1
Pooling maxpool_5 1 1 conv_4_activation maxpool_5 0=0 1=2 2=2 3=0 5=1 13=0 14=1 15=1
Convolution conv_6 1 1 maxpool_5 conv_6 0=128 1=3 2=1 3=1 4=1 5=0 6=73728
BatchNorm conv_6_batch_norm 1 1 conv_6 conv_6_batch_norm 0=128 1=0.00001
ReLU conv_6_activation 1 1 conv_6_batch_norm conv_6_activation 0=0.1
Pooling maxpool_7 1 1 conv_6_activation maxpool_7 0=0 1=2 2=2 3=0 5=1 13=0 14=1 15=1
Convolution conv_8 1 1 maxpool_7 conv_8 0=256 1=3 2=1 3=1 4=1 5=0 6=294912
BatchNorm conv_8_batch_norm 1 1 conv_8 conv_8_batch_norm 0=256 1=0.00001
ReLU conv_8_activation 1 1 conv_8_batch_norm conv_8_activation 0=0.1
Split conv_8_activation_split 1 2 conv_8_activation conv_8_activation_split_0 conv_8_activation_split_1
Pooling maxpool_9 1 1 conv_8_activation_split_0 maxpool_9 0=0 1=2 2=2 3=0 5=1 13=0 14=1 15=1
Convolution conv_10 1 1 maxpool_9 conv_10 0=512 1=3 2=1 3=1 4=1 5=0 6=1179648
BatchNorm conv_10_batch_norm 1 1 conv_10 conv_10_batch_norm 0=512 1=0.00001
ReLU conv_10_activation 1 1 conv_10_batch_norm conv_10_activation 0=0.1
Pooling maxpool_11 1 1 conv_10_activation maxpool_11 0=0 1=2 2=1 3=0 5=1 13=0 14=1 15=1
Convolution conv_12 1 1 maxpool_11 conv_12 0=1024 1=3 2=1 3=1 4=1 5=0 6=4718592
BatchNorm conv_12_batch_norm 1 1 conv_12 conv_12_batch_norm 0=1024 1=0.00001
ReLU conv_12_activation 1 1 conv_12_batch_norm conv_12_activation 0=0.1
Convolution conv_13 1 1 conv_12_activation conv_13 0=256 1=1 2=1 3=1 4=0 5=0 6=262144
BatchNorm conv_13_batch_norm 1 1 conv_13 conv_13_batch_norm 0=256 1=0.00001
ReLU conv_13_activation 1 1 conv_13_batch_norm conv_13_activation 0=0.1
Split conv_13_activation_split 1 2 conv_13_activation conv_13_activation_split_0 conv_13_activation_split_1
Convolution conv_14 1 1 conv_13_activation_split_0 conv_14 0=512 1=3 2=1 3=1 4=1 5=0 6=1179648
BatchNorm conv_14_batch_norm 1 1 conv_14 conv_14_batch_norm 0=512 1=0.00001
ReLU conv_14_activation 1 1 conv_14_batch_norm conv_14_activation 0=0.1
Convolution conv_15 1 1 conv_14_activation conv_15 0=27 1=1 2=1 3=1 4=0 5=1 6=13824
DarknetActivation conv_15_activation 1 1 conv_15 conv_15_activation 0=3
Concat route_17 1 1 conv_13_activation_split_1 route_17 0=0
Convolution conv_18 1 1 route_17 conv_18 0=128 1=1 2=1 3=1 4=0 5=0 6=32768
BatchNorm conv_18_batch_norm 1 1 conv_18 conv_18_batch_norm 0=128 1=0.00001
ReLU conv_18_activation 1 1 conv_18_batch_norm conv_18_activation 0=0.1
Interp upsample_19 1 1 conv_18_activation upsample_19 0=1 1=2.f 2=2.f
Concat route_20 2 1 upsample_19 conv_8_activation_split_1 route_20 0=0
Convolution conv_21 1 1 route_20 conv_21 0=256 1=3 2=1 3=1 4=1 5=0 6=884736
BatchNorm conv_21_batch_norm 1 1 conv_21 conv_21_batch_norm 0=256 1=0.00001
ReLU conv_21_activation 1 1 conv_21_batch_norm conv_21_activation 0=0.1
Convolution conv_22 1 1 conv_21_activation conv_22 0=27 1=1 2=1 3=1 4=0 5=1 6=6912
DarknetActivation conv_22_activation 1 1 conv_22 conv_22_activation 0=3
Yolov3Detection yolo_23 2 1 conv_15_activation conv_22_activation yolo_23 0=4 1=6 2=0 3=0.25f 4=0.45f 5=224 6=224 -23307=12,39.714199,54.955200,33.787300,72.162300,47.851601,66.907204,21.274200,29.342899,25.543501,43.516399,28.020599,60.446602

我尝试注释掉 DarknetActivation 这一层 加载便成功了 不知道如何解决,请教一下

@xiangweizeng
Copy link
Owner

DarknetActivation 是自定义的网络层, 你需要将其注册到ncnn network中, 具体的你可以参考example/yolo.cpp

  CustomizedNet yolo;
  register_darknet_layer(yolo);
  yolo.load_param(param);

@popper0912
Copy link
Author

DarknetActivation 是自定义的网络层, 你需要将其注册到ncnn network中, 具体的你可以参考example/yolo.cpp

  CustomizedNet yolo;
  register_darknet_layer(yolo);
  yolo.load_param(param);

谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants