uhfband / keras2caffe

Keras to Caffe model converter tool
MIT License
67 stars 22 forks source link

the "pad" param is float which unaccept in caffe #5

Open ireqhawk opened 6 years ago

ireqhawk commented 6 years ago

hello uhfband,thanks for your work.when i run the convert_VGG16 demo,i got the error: File "/media/ireqhawk/文件/ireqhawk/project/AdienceDBClassfi/AdienceDBClassfi/demo.py", line 184, in <module> main() File "/media/ireqhawk/文件/ireqhawk/project/AdienceDBClassfi/AdienceDBClassfi/demo.py", line 147, in main keras2caffe.convert(keras_model, 'VGG16.prototxt', 'VGG16.caffemodel') File "/media/ireqhawk/文件/ireqhawk/project/AdienceDBClassfi/AdienceDBClassfi/keras2caffe/convert.py", line 375, in convert net_proto = input_str + '\n' + 'layer {' + 'layer {'.join(str(caffe_net.to_proto()).split('layer {')[2:]) File "/home/ireqhawk/bin/caffe/python/caffe/net_spec.py", line 193, in to_proto top._to_proto(layers, names, autonames) File "/home/ireqhawk/bin/caffe/python/caffe/net_spec.py", line 96, in _to_proto return self.fn._to_proto(layers, names, autonames) File "/home/ireqhawk/bin/caffe/python/caffe/net_spec.py", line 159, in _to_proto _param_names[self.type_name] + '_param'), k, v) File "/home/ireqhawk/bin/caffe/python/caffe/net_spec.py", line 73, in assign_proto getattr(proto, name).extend(val) TypeError: 1.5 has type float, but expected one of: int, long it becuase the convert code cal a float "pad" param,if i just fllor the pad val,i will got uneuqal shape on save caffemodel,any advise. my enviroment: caffe 1.0.0 keras 2.1.2 tensorflow 1.4.1

thank you!

uhfband commented 6 years ago

Hi! How do you create keras model in your code? What input shape? e.g keras_model = VGG16(input_shape=(224, 224, 3), weights='imagenet', include_top=True)

ireqhawk commented 6 years ago

i create a wide residual net,with depth 16,width 8,except the "pad" param,i find it will be some problem in average_pooling2d layer,it is signed in this project's readme file,so i delete the average_pooling2d layer.but when convert the weights to caffemodel file,some layer get unsuitable shape.i could not find why. i wonder maybe i misunderstanding this project?maybe is just be workful in the examle nets? thanks for your help!

uhfband commented 6 years ago

What is kernel size, stride, input and output shape in your average_pooling2d layer?

marianogaragiola commented 6 years ago

Hi, I'm having the same problem with a keras squeezenet, any idea on how to solve it?

uhfband commented 6 years ago

@marianogaragiola, what implementation of Squeezenet are you using?

marianogaragiola commented 6 years ago

Is the keras_squeezenet version. I solved the problem casting to int the value of the variable, seems to working fine but I'm not so sure is the correct way to do it.

uhfband commented 6 years ago

@marianogaragiola I had modified the padding calculation, it should work properly now

marianogaragiola commented 6 years ago

Ok, thanks. I will use the new version and test it.