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

KeyError: 'batchnormalizationv1' #81

Open
Gasp34 opened this issue Jun 4, 2019 · 3 comments
Open

KeyError: 'batchnormalizationv1' #81

Gasp34 opened this issue Jun 4, 2019 · 3 comments

Comments

@Gasp34
Copy link

Gasp34 commented Jun 4, 2019

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
Copy link
Collaborator

AvantiShri commented Jun 4, 2019 via email

@Gasp34
Copy link
Author

Gasp34 commented Jun 4, 2019

It is 2.2.4

@Gasp34
Copy link
Author

Gasp34 commented Jun 4, 2019

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

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

2 participants