Which keras import version can be run perfect

Which keras version can run perfect in 1.0.0-beta7.I try some of keras verision to import,but python keras predict is different from dl4j import predict

@1329154840 could you be more specific? If you have a file you tried to import and it failed, could just tell us what it is directly? We have a ton of unit tests (hundreds of model files) that work on both keras 1 and 2, as well as tf keras.

We can help you with your specific problem if you tell us a bit more.

keras 2.2.4

Exception in DL4J
Exception in thread “main” org.deeplearning4j.exception.DL4JInvalidConfigException: Invalid configuration for layer (idx=-1, name=conv2d_1, type=ConvolutionLayer) for height dimension: Invalid input configuration for kernel height. Require 0 < kH <= inHeight + 2*padH; got (kH=5, inHeight=1, padH=0)
Input type = InputTypeConvolutional(h=1,w=187,c=1), kernel = [5, 5], strides = [1, 1], padding = [0, 0], layer size (output channels) = 32, convolution mode = Same
at org.deeplearning4j.nn.conf.layers.InputTypeUtil.getOutputTypeCnnLayers(InputTypeUtil.java:328)
at org.deeplearning4j.nn.conf.layers.ConvolutionLayer.getOutputType(ConvolutionLayer.java:184)
at org.deeplearning4j.nn.modelimport.keras.layers.convolutional.KerasConvolution2D.getOutputType(KerasConvolution2D.java:150)
at org.deeplearning4j.nn.modelimport.keras.KerasModel.inferOutputTypes(KerasModel.java:304)
at org.deeplearning4j.nn.modelimport.keras.KerasSequentialModel.(KerasSequentialModel.java:147)
at org.deeplearning4j.nn.modelimport.keras.KerasSequentialModel.(KerasSequentialModel.java:58)
at org.deeplearning4j.nn.modelimport.keras.utils.KerasModelBuilder.buildSequential(KerasModelBuilder.java:322)
at org.deeplearning4j.nn.modelimport.keras.KerasModelImport.importKerasSequentialModelAndWeights(KerasModelImport.java:180)
at h5.main(h5.java:40)

Could you paste the text so I don’t have to use OCR to get the code out to run this model? :slight_smile: Thanks!

def CNN( X_train, X_val,X_test, y_train,y_val,y_test,maxlen):
#th (dim_ordering=‘th’): [samples][channels][rows][cols]
#tf (dim_ordering=‘tf’): [samples][rows][cols][channels]
X_train = X_train.reshape(-1, 1, 1, maxlen)
X_val = X_val.reshape(-1, 1, 1, maxlen)
X_test = X_test.reshape(-1, 1,1, maxlen)
model = Sequential()
# Conv layer 1 output shape (787,32, 1, max_len)
model.add(Convolution2D(
batch_input_shape=(None, 1, 1, maxlen),
filters=32,
kernel_size=[1,5],
strides=1,
padding=‘same’, # Padding method
data_format=‘channels_first’,
))
model.add(Activation(‘relu’))
# Pooling layer 1 (max pooling) output shape (787,32, 1, max_len)
model.add(MaxPooling2D(
pool_size=(1,2),
strides=1,
padding=‘same’, # Padding method
data_format=‘channels_first’,
))
# Conv layer 2 output shape (787,64, 1, max_len)
model.add(Convolution2D(64, 5, strides=1, padding=‘same’, data_format=‘channels_first’))
model.add(Activation(‘relu’))
# Pooling layer 2 (max pooling) output shape (787,64, 1, max_len)
model.add(MaxPooling2D((1,5), 1,padding= ‘same’, data_format=‘channels_first’))
# Fully connected layer 1 input shape (64 * 1 * max_len) , output shape (64max_len=64187=11968)
model.add(Flatten())
model.add(Dense(512))
model.add(Activation(‘relu’))
model.add(Dense(1))
adam = Adam(lr=1e-4)
# We add metrics to get more results you want to see
model.compile(optimizer=adam,loss=‘mean_squared_error’, metrics=[‘accuracy’])
print(‘Training ------------’)
early_stopping = keras.callbacks.EarlyStopping(monitor=‘val_loss’,patience=10,verbose=1,mode=‘auto’)
model.fit(X_train, y_train, epochs=100, batch_size=256, callbacks=[early_stopping],validation_data=(X_val, y_val))
print(’\nTesting ------------’)
# Evaluate the model with the metrics we defined earlier
loss= model.evaluate(X_test, y_test)
print(’\ntest loss: ', loss)
model.save(‘C:/Users/86188/Desktop/cnn_pwa_model_0.h5’)
return model.predict(X_test)

Thanks! I have your model running locally. I’m not seeing that with the latest version.
I fixed a lot of the ordering issues here:

Those will be in snapshots soon.

Could you tell me what length you used for your model?

The model of length is 187

Just confirmed that this has already been fixed in the latest version. You’ll have to wait till we merge the latest changes master back to eclipse/deeplearning4j.
(See: https://github.com/KonduitAI/deeplearning4j)

We’ll do that after a few more changes. Then the fix will be available via snapshots.