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

Setting weights in Conv2d #22

Open
hawbecker opened this issue Mar 25, 2024 · 0 comments
Open

Setting weights in Conv2d #22

hawbecker opened this issue Mar 25, 2024 · 0 comments

Comments

@hawbecker
Copy link

hawbecker commented Mar 25, 2024

This tutorial has been tremendously helpful - thank you for creating it! I'm running through notebook 6 and had been getting errors when setting the weights. It seems in this version of Conv2d there is no weights argument.

ValueError: Unrecognized keyword arguments passed to Conv2D: {'weights': [array([[[[ 0]],

        [[-1]],

        [[ 0]]],


       [[[-1]],

        [[ 5]],

        [[-1]]],


       [[[ 0]],

        [[-1]],

        [[ 0]]]])]}

I was able to set the weights by using the following code

kernel_weights = np.array([[ 0, -1, 0],[ -1,5,-1],[0,-1,0]])

# Tensorflow needs to initialize the kernel:
kernel_init = tf.constant_initializer(kernel_weights)

#define conv with specific weights
conv = tf.keras.layers.Conv2D(filters=1,kernel_size=3,input_shape=(260,260,1),
                              kernel_initializer=kernel_init,use_bias=False)

I just wanted to post this here in case anybody else had issues with it.

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

1 participant