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

Error while converting #13

Open
younkyul opened this issue Jan 7, 2019 · 9 comments
Open

Error while converting #13

younkyul opened this issue Jan 7, 2019 · 9 comments

Comments

@younkyul
Copy link

younkyul commented Jan 7, 2019

I got an error while converting as follows:

....
I0107 15:12:23.722321 7166 net.cpp:242] This network produces output dense_2
I0107 15:12:23.722332 7166 net.cpp:255] Network initialization done.
Traceback (most recent call last):
File "/home/sr5/younkyu.lee/keras2caffe/keras2caffe-master/convert_youn.py", line 91, in
keras2caffe.convert(keras_model, 'youn.prototxt', 'youn.caffemodel')
File "/home/sr5/younkyu.lee/keras2caffe/keras2caffe-master/keras2caffe/convert.py", line 399, in convert
caffe_model.params[layer][n].data[...] = net_params[layer][n]
ValueError: could not broadcast input array from shape (512,28800) into shape (512,1920)

Process finished with exit code 1

Please help me resolve this issue..

@uhfband
Copy link
Owner

uhfband commented Jan 7, 2019

It's hard to help without knowing of your keras model definition

@younkyul
Copy link
Author

younkyul commented Jan 7, 2019

Here is the model I used:

model = Sequential()
model.add(Convolution2D(64, (3, 3), padding='same', input_shape=X_train.shape[1:]))
model.add(Activation('relu'))
model.add(Convolution2D(64, (3, 3)), padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2), padding='same'))
model.add(Dropout(0.25))

model.add(Convolution2D(128, (3, 3)padding='same'))
model.add(Activation('relu'))
model.add(Convolution2D(128, (3, 3)), padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2), padding='same'))
model.add(Dropout(0.25))

model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(nb_classes))
model.add(Activation('softmax'))

model.compile(loss='binary_crossentropy', optimizer='adadelta', metrics=['accuracy'])

@younkyul younkyul closed this as completed Jan 7, 2019
@younkyul younkyul reopened this Jan 7, 2019
@uhfband
Copy link
Owner

uhfband commented Jan 7, 2019

What is nb_classes and input shape? I will try to reproduce this error.

@younkyul
Copy link
Author

younkyul commented Jan 7, 2019

Thank you for your help.

  • nb_classes: 2
  • input shape: (60, 60, 1)

@younkyul
Copy link
Author

younkyul commented Jan 9, 2019

Would it be because of the version of tools?
I've used:

  • Keras 2.2.4
  • Tensorflow 1.9.0
  • Caffe 1.0

@uhfband
Copy link
Owner

uhfband commented Jan 9, 2019

I had no problem converting your model with Keras 2.1.5. You should try it

@younkyul
Copy link
Author

younkyul commented Jan 9, 2019

I have tried mine with 2.1.5 and still got the same error.
Could you please share the code for building the model?

@uhfband
Copy link
Owner

uhfband commented Jan 9, 2019

import sys
sys.path.append('../../')

import keras2caffe

from keras.models import Sequential.
from keras.layers import Convolution2D, Activation, Dropout, Dense, Flatten, MaxPooling2D

nb_classes=2

model = Sequential()
#model.add(Convolution2D(64, (3, 3), padding='same', input_shape=X_train.shape[1:]))
model.add(Convolution2D(64, (3, 3), padding='same', input_shape=(60, 60, 1)))
model.add(Activation('relu'))
model.add(Convolution2D(64, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2), padding='same'))
model.add(Dropout(0.25))

model.add(Convolution2D(128, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(Convolution2D(128, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2), padding='same'))
model.add(Dropout(0.25))

model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(nb_classes))
model.add(Activation('softmax'))

model.compile(loss='binary_crossentropy', optimizer='adadelta', metrics=['accuracy'])

keras2caffe.convert(model, 'deploy.prototxt', 'weights.caffemodel')
`

@huangeason26
Copy link

i have the same problem @younkyul , and i find that if the "MaxPooling2D" contains "padding='same'" , it can convert well, but it can not work without "padding='same'"

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

3 participants