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

any way to do causal pad in Flux ? #2505

Open
neoareslinux opened this issue Oct 25, 2024 · 4 comments
Open

any way to do causal pad in Flux ? #2505

neoareslinux opened this issue Oct 25, 2024 · 4 comments

Comments

@neoareslinux
Copy link

Motivation and description

does Cov support causal pad ? I want build causal dilated convolutional network model, but i cannot find any document to guid me to do this with Flux.

Possible Implementation

No response

@CarloLucibello
Copy link
Member

Do you have some pytorch reference code?
I don't see it as an option in pytorch's Conv1d

Maybe just first process the input using NNlib.pad_constant?

@neoareslinux
Copy link
Author

Do you have some pytorch reference code? I don't see it as an option in pytorch's Conv1d

Maybe just first process the input using NNlib.pad_constant?

keras code, I have not used pytorch, i learn DL in keras framework and now want to migrate to julia&Flux.

def get_model(input_length, num_features):
    model = keras.Sequential()

    model.add(layers.Conv1D(filters=20, kernel_size=2, dilation_rate=1, padding='causal', activation='relu', 
                 input_shape=(input_length, num_features)))
    model.add(layers.Conv1D(filters=20, kernel_size=2, dilation_rate=2, padding='causal', activation='relu'))
    model.add(layers.Conv1D(filters=20, kernel_size=2, dilation_rate=4, padding='causal', activation='relu'))
    model.add(layers.Conv1D(filters=20, kernel_size=2, dilation_rate=8, padding='causal', activation='relu'))
    model.add(layers.Conv1D(filters=20, kernel_size=2, dilation_rate=1, padding='causal', activation='relu'))
    model.add(layers.Conv1D(filters=20, kernel_size=2, dilation_rate=2, padding='causal', activation='relu'))
    model.add(layers.Conv1D(filters=20, kernel_size=2, dilation_rate=4, padding='causal', activation='relu'))
    model.add(layers.Conv1D(filters=20, kernel_size=2, dilation_rate=8, padding='causal', activation='relu'))

    # Flatten the output
    model.add(layers.Flatten())

    # Add a dense layer for binary classification
    model.add(layers.Dense(1, activation='sigmoid'))

    # Compile the model
    model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
    return model

@CarloLucibello
Copy link
Member

I don't know what Keras does.
Looking at this
https://gist.github.com/paultsw/7a9d6e3ce7b70e9e2c61bc9287addefc
it seems like you just have to handle the padding appropriately.

@neoareslinux
Copy link
Author

I don't know what Keras does. Looking at this https://gist.github.com/paultsw/7a9d6e3ce7b70e9e2c61bc9287addefc it seems like you just have to handle the padding appropriately.

thanks, maybe related to #258

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