kundajelab / deeplift

Public facing deeplift repo
MIT License
823 stars 164 forks source link

Deeplift with Cifar10 #124

Open GizemAyas517 opened 3 years ago

GizemAyas517 commented 3 years ago

Hello,

Before getting into my question, just wanted to say I really enjoyed reading the paper and also exploring the codebase. Many thanks for deeplift!

I've been trying to use deeplift with cifar10 but I've came across a problem:

the model and cifar10 dataset I've been using: https://machinelearningmastery.com/object-recognition-convolutional-neural-networks-keras-deep-learning-library/

I save the trained model with the command below: model.save('my_cifar_model.h5', save_format='h5')

when I run this command everything seems fine: import keras saved_model_file = "my_cifar_model.h5" model = keras.models.load_model(saved_model_file) model.summary()

However when I try to create a deeplift reveal cancel model:

`import deeplift from deeplift.layers import NonlinearMxtsMode from deeplift.conversion import kerasapi_conversion as kc

revealcancel_model = kc.convert_model_from_saved_files( h5_file=saved_model_file, nonlinear_mxts_mode=NonlinearMxtsMode.RevealCancel) ` I get this error: TypeError: can only concatenate str (not "KeysViewHDF5") to str What do you think I can do to solve it? Are there any deeplift examples with cifar10?

Thanks!

sidvijay10 commented 2 years ago

did you end up fixing this issue?

N1Keey commented 2 years ago

I Have the same problem.. Also trying to apply deeplift on a model which was trained with the cifar10 dataset. I use the same model from the Tutorial: Model: "sequential"

Layer (type) Output Shape Param

conv2d (Conv2D) (None, 32, 32, 32) 896

conv2d_1 (Conv2D) (None, 32, 32, 32) 9248

max_pooling2d (MaxPooling2D (None, 16, 16, 32) 0
)

dropout (Dropout) (None, 16, 16, 32) 0

conv2d_2 (Conv2D) (None, 16, 16, 64) 18496

conv2d_3 (Conv2D) (None, 16, 16, 64) 36928

max_pooling2d_1 (MaxPooling (None, 8, 8, 64) 0
2D)

dropout_1 (Dropout) (None, 8, 8, 64) 0

conv2d_4 (Conv2D) (None, 8, 8, 128) 73856

conv2d_5 (Conv2D) (None, 8, 8, 128) 147584

max_pooling2d_2 (MaxPooling (None, 4, 4, 128) 0
2D)

dropout_2 (Dropout) (None, 4, 4, 128) 0

flatten (Flatten) (None, 2048) 0

dense (Dense) (None, 128) 262272

dropout_3 (Dropout) (None, 128) 0

dense_1 (Dense) (None, 10) 774

================================================================= Total params: 550,054 Trainable params: 550,054 Non-trainable params: 0


The code for the DeepLIFT implementation is from the MNIST-example: Code:

import deeplift
from deeplift.layers import NonlinearMxtsMode
from deeplift.conversion import kerasapi_conversion as kc
deeplift_model =\
    kc.convert_model_from_saved_files(
        h5_file='model4cifar10.h5',
        nonlinear_mxts_mode=deeplift.layers.NonlinearMxtsMode.DeepLIFT_GenomicsDefault) 

And I get the exact same errormessage.

AvantiShri commented 2 years ago

Hello all (sorry for the late reply, I've been navigating some health issues): deeplift was developed with what is now a very old version of tensorflow and keras, and was not designed to work with tf.keras; I recommend using one of the more recent implementations of deeplift mentioned in the FAQ, as those are being actively maintained. They don't have the revealcancel rule, but unfortunately I don't have the bandwidth to maintain this project since I've graduated

On Tue, 9 Aug 2022 at 14:47, Nico @.***> wrote:

I Have the same problem.. Also trying to apply deeplift on a model which was trained with the cifar10 dataset. I use this model: Model: "sequential"

Layer (type) Output Shape Param #

conv2d (Conv2D) (None, 32, 32, 32) 896

conv2d_1 (Conv2D) (None, 32, 32, 32) 9248

max_pooling2d (MaxPooling2D (None, 16, 16, 32) 0 )

dropout (Dropout) (None, 16, 16, 32) 0

conv2d_2 (Conv2D) (None, 16, 16, 64) 18496

conv2d_3 (Conv2D) (None, 16, 16, 64) 36928

max_pooling2d_1 (MaxPooling (None, 8, 8, 64) 0 2D)

dropout_1 (Dropout) (None, 8, 8, 64) 0

conv2d_4 (Conv2D) (None, 8, 8, 128) 73856

conv2d_5 (Conv2D) (None, 8, 8, 128) 147584

max_pooling2d_2 (MaxPooling (None, 4, 4, 128) 0 2D)

dropout_2 (Dropout) (None, 4, 4, 128) 0

flatten (Flatten) (None, 2048) 0

dense (Dense) (None, 128) 262272

dropout_3 (Dropout) (None, 128) 0

dense_1 (Dense) (None, 6) 774

================================================================= Total params: 550,054 Trainable params: 550,054 Non-trainable params: 0

The code for the DeepLIFT implementation is from the MNIST-example: https://github.com/kundajelab/deeplift/blob/master/examples/mnist/MNIST_replicate_figures.ipynb Code:

import deeplift from deeplift.layers import NonlinearMxtsMode from deeplift.conversion import kerasapi_conversion as kc deeplift_model =\ kc.convert_model_from_saved_files( h5_file='model4cifar10.h5', nonlinear_mxts_mode=deeplift.layers.NonlinearMxtsMode.DeepLIFT_GenomicsDefault)

And I get the exact same errormessage.

— Reply to this email directly, view it on GitHub https://github.com/kundajelab/deeplift/issues/124#issuecomment-1209126702, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARSFBXRHB7K6SGAMGSVRD3VYIOY3ANCNFSM5EZGAX6A . You are receiving this because you are subscribed to this thread.Message ID: @.***>