gklz1982 / caffe-yolov2

Other
164 stars 128 forks source link

how to convert yolo.cfg to yolo.prototxt #3

Open 10183308 opened 7 years ago

10183308 commented 7 years ago

could you release the script?

thank you very much

Li-Lai commented 7 years ago

Thank you for sharing the code! ./examples/indoor/train.prototxt last layer has som 'biases:xxx' parameters, I want to know these parameters come from, could you give me some advice? biases: 0.738768 biases: 0.874946 biases: 2.42204 biases: 2.65704 biases: 4.30971 biases: 7.04493 biases: 10.246 biases: 4.59428 biases: 12.6868 biases: 11.8741

opyk commented 7 years ago

how to convert yolo.cfg to yolo.prototxt? Have you solved it? please

Li-Lai commented 7 years ago

@opyk Convert yolo.cfg to yolo.prototxt is unnecessary. Author had provide the file. I have tried the code, but cannot got good enough results.

opyk commented 7 years ago

I use convert_weights_to_caffemodel.py ,but I always fail to convert code。。。。 Is there any good way?

Li-Lai commented 7 years ago

@opyk weights is not match with cfg. Firstly,I trained my own yolo.weights through yolov2 framework. Then, I adjust author's prototxt according to my own yolo-voc.cfg. After that, I use convert_weights_to_caffemodel.py. You can try this way.

opyk commented 7 years ago

@CBIR-LL I did it this way ,I review my own prototxt ,but weights is not match with cfg,I guess my prototxt error,but I can't know how to change it。 Can I have a look at your modified prototxt file?
xinlhw@sina.com is my E-mail address 。

Li-Lai commented 7 years ago

@opyk I have send it to you. please check it.

opyk commented 7 years ago

@CBIR-LL thank you

opyk commented 7 years ago

@CBIR-LL I want to train mode, Do you know how to make labels?

Li-Lai commented 7 years ago

@opyk Authos has provide his file. Following files are my file. (label_map.txt) car 0 tv 1 (training.txt) 001002 001003 001004 001005 001006 (trainval.txt) mydata/images/001002.jpg mydata/Annotations/001002.xml mydata/images/001003.jpg mydata/Annotations/001003.xml

opyk commented 7 years ago

@CBIR-LL Using the author's test program to parse the output of 30X13X13, but it can not achieve good results Excuse me, do you have a better idea?

Li-Lai commented 7 years ago

@opyk If it's for studying, you can debug the code. If it's for engineering, just use Darknet directly! I tried it and it didn't work well, so I still use Darknet. If you have any good ideas, you can tell me.

opyk commented 7 years ago

@CBIR-LL I feel that the author's code has a problem, I use his code training, region_loss_layer layer output, avg_noobj: 0.11454, avg_obj:, -nan, avg_iou:,-nan, avg_cat:, -nan, recall:, -nan, class_count:, it is difficult to understand... Have you ever trained with his code?

Zhaixuejun commented 6 years ago

@CBIR-LL hello, I have a question, when I run the convert_weights_to_caffemodel.py with the yolo.prototxt provide by the author and the weight file, but it failed with (Error parsing text-format caffe.NetParameter: 1015:15: Message type "caffe.LayerParameter" has no field named "reorg_param".) , I don't why, can you help me?

Zhaixuejun commented 6 years ago

@opyk Do you convert the weight file to caffemodel file sucess?

Katherinexx commented 6 years ago

I have the same problem with @Zhaixuejun .

Zhaixuejun commented 6 years ago

@Katherinexx I think you should export the right path of caffe(after you cmd: make all)

Katherinexx commented 6 years ago

@Zhaixuejun Do you convert it successfully? Could you please send me the final prototxt? Thank you so much! Here are my email:xxiaoac@ust.hk

Zhaixuejun commented 6 years ago

@Katherinexx I don't catch your meaning, the prototxt file is provided in ../example/indoor/convent, you need finall caffemodel?

Katherinexx commented 6 years ago

@CBIR-LL Could you please send me a copy of your modified prototxt? Thank you so much! xxiaoac@ust.hk

Katherinexx commented 6 years ago

@Zhaixuejun I have tried the prototxt the author provided, but it doesn't work and report shape check failed error , I guess some parameters need to be modified. Do you have the prototxt that can work? Thanks.

r06631001 commented 6 years ago

I also have the same problem with Zhaixuejun. @Katherinexx Did you solve the problem? Thanks.

Katherinexx commented 6 years ago

@r06631001 Maybe you should modify the caffe path in .bashrc.

mychina75 commented 6 years ago

Hi, guys. I failed to convert model file.

  1. use the prototxt file provide by author: examples/indoor/convert/yolo.prototxt,
  2. weight file download from https://pjreddie.com/darknet/yolo/. yolo-voc.weights YOLOv2 | VOC 2007+2012 | 2007 | 76.8 | 34.90 Bn | 67 | cfg | weights
  3. python convert_weights_to_caffemodel.py yolo.prototxt yolo-voc.weights yolo.caffemodel got following error: Traceback (most recent call last): File "convert_weights_to_caffemodel.py", line 70, in net.params[pr][0].data[...] = np.reshape(netWeights[count:count + weightSize], dims) File "/data/anaconda2/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 232, in reshape return _wrapfunc(a, 'reshape', newshape, order=order) File "/data/anaconda2/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc return getattr(obj, method)(*args, **kwds) ValueError: cannot reshape array of size 11957629 into shape (1024,3072,3,3)

any suggestion?

windghoul commented 6 years ago

@Zhaixuejun I have the same problem.Do you have some ways to sol out?Thanks

nalan210 commented 6 years ago

@mychina75 Have you solve the problem of converting the yolo weights model into caffemodel? When I run the following command:
python convert_weights_to_caffemodel.py yolo.prototxt yolo.weights yolo.caffemodel I always get the error "Error parsing text-format caffe.NetParameter: 1060:15: Message type "caffe.LayerParameter" has no field named "reorg_param." Can you tell me how you solve it?

nalan210 commented 6 years ago

I have reviewed the Caffe layer list and found that the Rerog and RegionLoss layer is not appeared in the list. So I guess that these two layers should be transferred into other layers which is contained in the Caffe layer. @Zhaixuejun @mychina75 @windghoul

Zhaixuejun commented 6 years ago

The author has achieved the layers, Rerog and Region layers, in Caffe. @nalan210

nalan210 commented 6 years ago

@Zhaixuejun Sorry to disturb you again that I am still confused. As you say the author has achieved the layers including Rerog and Region layer, do you mean that the Caffe itself or the author gklz1982 who provided these codes?

wk738126046 commented 6 years ago

the same problem with you @nalan210 , Have you solve it ? caffe.LayerParameter" has no field named "reorg_param."

dedoogong commented 6 years ago

I have the same problem in converting the yolo.weights(coco-80class) model with the yolo.prototxt as below error conv21(conv) Traceback (most recent call last): File "convert_weights_to_caffemodel.py", line 74, in net.params[pr][0].data[...] = np.reshape(netWeights[count:count + weightSize], dims) File "/usr/local/lib/python2.7/dist-packages/numpy/core/fromnumeric.py", line 257, in reshape return _wrapfunc(a, 'reshape', newshape, order=order) File "/usr/local/lib/python2.7/dist-packages/numpy/core/fromnumeric.py", line 52, in _wrapfunc return getattr(obj, method)(*args, kwds) ValueError: cannot reshape array of size 12265129 into shape (1024,3072,3,3)**

first, yolo prototxt's count(67465630) and yolo weights' netshape( 50983561 ) doesn't match. yolo weights are downloaded from official darknet site and it's trained on coco db.

plus, I don't understand why label dim is 30*5... just 5 would be enough for one box. there is 30 boxes?

dedoogong commented 6 years ago

I tried to use all deploy or test prototxts to see the conversion working fine or not, and the result was strange. in case of yolo.prototxt, the total param size is calculated as 67465630(bigger than 50983561) , but in all other cases including gnet_region_test_darknet_deploy.prototxt, gnet_region_test_darknet_v3.prototxt, train_test_yolo.prototxt, the expected sizes are all 48591262(smaller than the actual weight's total param size, 50983561) Of course I changed the last filter number/class number to 425 and 80 in advance. But, I found that there is no difference between yolo.prototxt and other prototxts regarding the params of all layers. Even though that, it calculates blob/tensor size of concat/reorg layers differently. in case of yolo.prototxt, it thinks the 3 layers (all have 1024 filters) are concatenated into one(so 3072 filters to 1024 filters). But, in other prototxt cases, it just treat it like 1:1 concatenation(1024 to 1024)....This difference made the different results ( 67465630 vs 48591262 ) Sooo strange...

dedoogong commented 6 years ago

Ha! it's really weird! suddnely all prototoxt failed with the same over param size, 67465630. I didn't changed anytying;;;;

dedoogong commented 6 years ago

Darknet saves weights only for conv(batchnorm included) regarding yolov2( no fc, no local, no stand-alone batchnorm layers).

void save/load_convolutional_weights(layer l, FILE fp) fwrite/fread(l.biases, sizeof(float), l.n, fp); // l.n == filter count == num_output fwrite/fread(l.scales, sizeof(float), l.n, fp); fwrite/fread(l.rolling_mean, sizeof(float), l.n, fp); fwrite/fread(l.rolling_variance, sizeof(float), l.n, fp); fwrite/fread(l.weights, sizeof(float), num, fp); // c/groupsnsizesize, groups==1 => num_inputnum_outputkernel_size^2

and first 4 major/minior,revision, net->seen are saved in front of all weights.

dedoogong commented 6 years ago

I found that, the covertor py is almost same as yolov1 convertor py from , https://github.com/xingwangsfu/caffe-yolo/blob/master/create_yolo_caffemodel.py and I logged the actual saved sizes of each layer as below; So, converter should read/save the values exactly same size and order as the original weights. l.biases : 32 l.scales + l.rolling_mean + l.rolling_variance : 96 l.weights : 864 l.biases : 64 l.scales + l.rolling_mean + l.rolling_variance : 192 l.weights : 18432 l.biases : 128 l.scales + l.rolling_mean + l.rolling_variance : 384 l.weights : 73728 l.biases : 64 l.scales + l.rolling_mean + l.rolling_variance : 192 l.weights : 8192 l.biases : 128 l.scales + l.rolling_mean + l.rolling_variance : 384 l.weights : 73728 l.biases : 256 l.scales + l.rolling_mean + l.rolling_variance : 768 l.weights : 294912 l.biases : 128 l.scales + l.rolling_mean + l.rolling_variance : 384 l.weights : 32768 l.biases : 256 l.scales + l.rolling_mean + l.rolling_variance : 768 l.weights : 294912 l.biases : 512 l.scales + l.rolling_mean + l.rolling_variance : 1536 l.weights : 1179648 l.biases : 256 l.scales + l.rolling_mean + l.rolling_variance : 768 l.weights : 131072 l.biases : 512 l.scales + l.rolling_mean + l.rolling_variance : 1536 l.weights : 1179648 l.biases : 256 l.scales + l.rolling_mean + l.rolling_variance : 768 l.weights : 131072 l.biases : 512 l.scales + l.rolling_mean + l.rolling_variance : 1536 l.weights : 1179648 l.biases : 1024 l.scales + l.rolling_mean + l.rolling_variance : 3072 l.weights : 4718592 l.biases : 512 l.scales + l.rolling_mean + l.rolling_variance : 1536 l.weights : 524288 l.biases : 1024 l.scales + l.rolling_mean + l.rolling_variance : 3072 l.weights : 4718592 l.biases : 512 l.scales + l.rolling_mean + l.rolling_variance : 1536 l.weights : 524288 l.biases : 1024 l.scales + l.rolling_mean + l.rolling_variance : 3072 l.weights : 4718592 l.biases : 1024 l.scales + l.rolling_mean + l.rolling_variance : 3072 l.weights : 9437184 l.biases : 1024 l.scales + l.rolling_mean + l.rolling_variance : 3072 l.weights : 9437184 l.biases : 64 l.scales + l.rolling_mean + l.rolling_variance : 192 l.weights : 32768 l.biases : 1024 l.scales + l.rolling_mean + l.rolling_variance : 3072 l.weights : 11796480 l.biases : 425 l.weights : 435200

yanzi6969 commented 6 years ago

@CBIR-LL @opyk I have trained the weights under darknet ,and used tiny-yolo.cfg.Now I want to convert the cfg to prototxt,how can I do that?

yanzi6969 commented 6 years ago

@mychina75 I used yolo.weights , and got the same problem with you ,did you solve the problem?

yanzi6969 commented 6 years ago

@dedoogong Did you slove the convert problem?

lvboodvl commented 6 years ago

I have a question about the difference between yolo2.cfg and caffe proto. In yolov2.cfg, the last block contains activation layer "linear", where this layer may not be considered in caffe proto, does this layer contain some extra params ?

Serge3006 commented 6 years ago

@lvboodvl in caffe you don't need and extra layer for the linear layer that appear in darknet. The linear layer in this case is the identity function.