Keras Model import error with TimeDistributed layer

Is TimeDistributedLayer supported with 1.0.0-beta7 in DL4J ?

Model code :

def bilstm_model(input_length, output_size):
    input_vec = Input((input_length, 300,), name = "w2v_input")
    model = Bidirectional (LSTM (300,return_sequences=True, kernel_initializer="glorot_uniform"),merge_mode='concat')(input_vec)
    model = TimeDistributed(Dense(100,activation='relu'))(model)
    model = Flatten()(model)
    model = Dropout(0.3)(model)
    model = Dense(output_size,activation='sigmoid',kernel_initializer="glorot_uniform", use_bias=True, bias_initializer=tf.keras.initializers.Ones())(model)
    model = Model(input_vec,model, name="bilstm_model")
    return model

model = bilstm_model(
    input_length=10, 
    output_size = 5
)

model.compile(loss=BinaryCrossentropy(), optimizer='adam', metrics=["accuracy"])

While importing the model, Getting error :

Exception in thread “main” org.deeplearning4j.nn.modelimport.keras.exceptions.InvalidKerasConfigurationException: Cannot assign arrays: arrays must both be scalars, both vectors, or shapes must be equal other than size 1 dimensions. Attempting to do x.assign(y) with x.shape=[100, 6299] and y.shape=[1000, 6299]
Tried to set weights for layer with name dense_1, of class org.deeplearning4j.nn.conf.layers.DenseLayer.
Failed to set weights for parameter W
Expected shape for this parameter: Rank: 2, DataType: FLOAT, Offset: 0, Order: f, Shape: [100,6299], Stride: [1,100],
got: Rank: 2, DataType: FLOAT, Offset: 0, Order: c, Shape: [1000,6299], Stride: [6299,1]. For more information, see https://deeplearning4j.konduit.ai/keras-import/overview
at org.deeplearning4j.nn.modelimport.keras.KerasLayer.copyWeightsToLayer(KerasLayer.java:334)
at org.deeplearning4j.nn.modelimport.keras.utils.KerasModelUtils.copyWeightsToModel(KerasModelUtils.java:75)
at org.deeplearning4j.nn.modelimport.keras.KerasModel.getComputationGraph(KerasModel.java:418)
at org.deeplearning4j.nn.modelimport.keras.KerasModel.getComputationGraph(KerasModel.java:404)
at org.deeplearning4j.nn.modelimport.keras.KerasModelImport.importKerasModelAndWeights(KerasModelImport.java:263)
at TFGraphRunner.(TFGraphRunner.java:45)
at TFGraphRunner.main(TFGraphRunner.java:151)

Please suggest if something can be corrected here. Same model without time distributed layer is importing in java.

Hi, which version of keras are you using? Is it tf.keras? How do you call model.save?
For now if this doesn’t work, you can convert the model to tensorflow and use it like that via our samediff api. You can find more about that here: