kundajelab / deeplift

Public facing deeplift repo
MIT License
821 stars 162 forks source link

KeyError: 'batchnormalizationv1' #81

Open Gasp34 opened 5 years ago

Gasp34 commented 5 years ago

Hey :) I'm trying to use kc.convert_model_from_saved_files but I have this keyerror :

  File "C:\Users\XXXXXXX\Anaconda3\lib\site-packages\deeplift\conversion\kerasapi_conversion.py", line 349, in layer_name_to_conversion_function
    return name_dict[layer_name.lower()]

KeyError: 'batchnormalizationv1'

The model is not complicated and it works without the batchnormalization layers.

def create_model():
    from tensorflow.keras.layers import Conv1D, Dense, MaxPooling1D, Flatten, Dropout, BatchNormalization, Activation
    from tensorflow.keras.models import Sequential
    from tensorflow.keras.optimizers import SGD

    model = Sequential()
    model.add(Conv1D(filters=300, kernel_size=19, padding='same', # activation='relu', # , activation='relu'
                 input_shape=(251, 4)))
    model.add(BatchNormalization())
    model.add(Activation('relu'))
    model.add(MaxPooling1D(pool_size=3, strides=3, padding='same'))

    model.add(Conv1D(filters=200, kernel_size=11, padding='same')) # , activation='relu'
    model.add(BatchNormalization())
    model.add(Activation('relu'))
    model.add(MaxPooling1D(pool_size=4, strides=4, padding='same'))

    model.add(Conv1D(filters=200, kernel_size=7, padding='same')) # , activation='relu'
    model.add(BatchNormalization())
    model.add(Activation('relu'))
    model.add(MaxPooling1D(pool_size=4, strides=4, padding='same'))

    model.add(Flatten())
    model.add(Dense(1000, activation='relu')) # kernel_regularizer=keras.regularizers.l2(0.001),
    model.add(Dropout(0.03)) # change dropout rate to 0.03

    model.add(Dense(1000, activation='relu')) 
    model.add(Dropout(0.03)) # change dropout rate to 0.03

    ## Change this number to adapt to the number of classes
    model.add(Dense(81)) # softmax vs. sigmoid? , activation='sigmoid'

    sgd = SGD(lr=0.002, decay=0, momentum=0.98, nesterov=True) # decay=1e-6,

    model.compile(loss=pearson_loss, optimizer=sgd, metrics=['mse']) 

    return model

model = create_model()
model.save(checkpoint_path + model_name+'.h5')

keras_model_weights = folder + 'results/keras/' + model_name + '.h5'
deeplift_model = kc.convert_model_from_saved_files(h5_file=keras_model_weights)

Can someone help me with this please ? :)

AvantiShri commented 5 years ago

What's your Keras version?

On Tue, 4 Jun 2019 at 11:32, Gasp34 notifications@github.com wrote:

Hey :) I'm trying to use kc.convert_model_from_saved_files but I have this keyerror : 'batchnormalizationv1'

The model is not complicated and it works without the batchnormalization layers.

def create_model(): from tensorflow.keras.layers import Conv1D, Dense, MaxPooling1D, Flatten, Dropout, BatchNormalization, Activation from tensorflow.keras.models import Sequential from tensorflow.keras.optimizers import SGD

model = Sequential()
model.add(Conv1D(filters=300, kernel_size=19, padding='same', # activation='relu', # , activation='relu'
             input_shape=(251, 4)))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling1D(pool_size=3, strides=3, padding='same'))

model.add(Conv1D(filters=200, kernel_size=11, padding='same')) # , activation='relu'
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling1D(pool_size=4, strides=4, padding='same'))

model.add(Conv1D(filters=200, kernel_size=7, padding='same')) # , activation='relu'
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling1D(pool_size=4, strides=4, padding='same'))

model.add(Flatten())
model.add(Dense(1000, activation='relu')) # kernel_regularizer=keras.regularizers.l2(0.001),
model.add(Dropout(0.03)) # change dropout rate to 0.03

model.add(Dense(1000, activation='relu'))
model.add(Dropout(0.03)) # change dropout rate to 0.03

## Change this number to adapt to the number of classes
model.add(Dense(81)) # softmax vs. sigmoid? , activation='sigmoid'

sgd = SGD(lr=0.002, decay=0, momentum=0.98, nesterov=True) # decay=1e-6,

model.compile(loss=pearson_loss, optimizer=sgd, metrics=['mse'])

return model

model = create_model() model.save(checkpoint_path + model_name+'.h5')

keras_model_weights = folder + 'results/keras/' + model_name + '.h5' deeplift_model = kc.convert_model_from_saved_files(h5_file=keras_model_weights)

Can someone help me with this please ? :)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kundajelab/deeplift/issues/81?email_source=notifications&email_token=AARSFBVYYUSFK74QAAD3IXDPY2YMFA5CNFSM4HS7Z5V2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GXTFZIA, or mute the thread https://github.com/notifications/unsubscribe-auth/AARSFBVVIDWU7WV5ZMCULJDPY2YMFANCNFSM4HS7Z5VQ .

Gasp34 commented 5 years ago

It is 2.2.4

Gasp34 commented 5 years ago

Fixed by removing all the "tenserflow." in the import : from keras.models import Sequential instead of from tensorflow.keras.models import Sequential