keras2caffe icon indicating copy to clipboard operation
keras2caffe copied to clipboard

Error while converting

Open younkyul opened this issue 6 years ago • 9 comments

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..

younkyul avatar Jan 07 '19 06:01 younkyul

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

uhfband avatar Jan 07 '19 08:01 uhfband

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 avatar Jan 07 '19 08:01 younkyul

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

uhfband avatar Jan 07 '19 11:01 uhfband

Thank you for your help.

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

younkyul avatar Jan 07 '19 11:01 younkyul

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

  • Keras 2.2.4
  • Tensorflow 1.9.0
  • Caffe 1.0

younkyul avatar Jan 09 '19 07:01 younkyul

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

uhfband avatar Jan 09 '19 08:01 uhfband

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

younkyul avatar Jan 09 '19 08:01 younkyul

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') `

uhfband avatar Jan 09 '19 08:01 uhfband

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'"

huangeason26 avatar Nov 13 '19 10:11 huangeason26