kundajelab / deeplift

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

Dimension error in a multi-input, multi-channel CNN #133

Closed sanju99 closed 1 year ago

sanju99 commented 2 years ago

Hello, I am using DeepLIFT on a genomics dataset. I have trained a multi-channel (12 channels) multi-input CNN on a multiple sequence alignment (MSA) and an additional numerical vector. The MSA is passed through 4 convolutions and 2 max pooling layers, is flattened, then concatenated with the numerical vector. This concatenated input is passed through 2 dense layers. I am training using TensorFlow v1 and auto converting it to a DeepLIFT model.

When I run the get_target_contribs_func function on this model, I get the following error: ValueError: Dimensions must be equal, but are 20576 and 20608 for 'add_131' (op: 'AddV2') with input shapes: [?,20576], [?,20608]. I am using a functional model and computing scores for 2 input layers (MSA inputs and the numerical vector). The layer that is throwing an error is the flatten layer after the convolutions and should have a dimension of 20576. When trained with other models with different numbers of channels, I notice the same discrepancy of 32. My hunch is that it might be because the last convolutional layer has 32 filters, but I’m not sure why there would be a dimension error at all.

A multi-channel single-input model and a single-channel multi-input model both run without any errors, so it seems restricted to the multi-channel multi-input case. The autoconversion step and verifying that the predictions are the same between the original and converted models run without any problems.

Have you noticed dimension errors with such multi-channel multi-input cases?

AvantiShri commented 1 year ago

Hello sanju - deeplift was developed with what is now a very old version of tensorflow and keras and was not designed for tf.keras; I recommend using the other implementations of deeplift that are described in the FAQ

On Mon, 24 Oct 2022 at 20:55, sanju99 @.***> wrote:

Hello, I am using DeepLIFT on a genomics dataset. I have trained a multi-channel (12 channels) multi-input CNN on a multiple sequence alignment (MSA) and an additional numerical vector. The MSA is passed through 4 convolutions and 2 max pooling layers, is flattened, then concatenated with the numerical vector. This concatenated input is passed through 2 dense layers. I am training using TensorFlow v1 and auto converting it to a DeepLIFT model.

When I run the get_target_contribs_func function on this model, I get the following error: ValueError: Dimensions must be equal, but are 20576 and 20608 for 'add_131' (op: 'AddV2') with input shapes: [?,20576], [?,20608]. I am using a functional model and computing scores for 2 input layers (MSA inputs and the numerical vector). The layer that is throwing an error is the flatten layer after the convolutions and should have a dimension of 20576. When trained with other models with different numbers of channels, I notice the same discrepancy of

  1. My hunch is that it might be because the previous pooling layer has 32 filters, but I’m not sure why there would be a dimension error at all.

A multi-channel single-input model and a single-channel multi-input model both run without any errors, so it seems restricted to the multi-channel multi-input case.

Have you noticed errors with such multi-channel multi-inputs cases?

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

sanju99 commented 1 year ago

Hello, thank you for the quick response! I will look into other implementations for tensorflow 2.