-
Notifications
You must be signed in to change notification settings - Fork 19.4k
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
constraint parameter for add_weight of layers.class does not accept functions. #20067
Comments
Hi @mannypaeza , The issue with the class MaskedConstraint(tf.keras.constraints.Constraint):
def __init__(self, R):
R = tf.cast(R, dtype=tf.float32)
self.R_exp = tf.expand_dims(tf.expand_dims(R, -1), -1)
def __call__(self, x):
Rt = tf.tile(self.R_exp, [1, 1, 1, x.shape[-1]])
Z = tf.zeros_like(x)
return tf.where(Rt>0, x, Z) Now, it appears that we could easily allow all callables, not just |
Hello! I ended up forgetting that I wrote this issue, and I was able to figure it out on my own (in the same way you had it, except in pytorch). thanks for the help, anyways! |
@mannypaeza it's a beautiful code, are these things called ring convolutions? Can't find any paper or good source about it. You are selecting the yellow area of the kernel right? Has this any specific use cases? also ig you are using torch but using |
@ghsanti yes, this is a ring convolutional model. For use case, it can be used for analyzing microendoscopic |
I am trying to convert a constraint function from Keras 2 to Keras 3. In Keras 2 API (with tensorflow), the code below works with constraint=masked_constraint(self.mask) in self.add_weight outputting a function.
( Photo of the model showing the function object in breakpoint()).
However, in Keras 3 (using pytorch for this), this function does not work. I tried to rewrite it as a Keras.constraints.Constraint class and it also fails to achieve my objective. Below is the following code (with both the function and class code written below).
Here is the error produced by my terminal for both functions:
With this, what are the other work around for this. (Note, x in the code is defined as follows):
x_in = Input(shape=shape) radius_min = int(gSig*r_factor) radius_max = radius_min + width ks = 2*radius_max + 1 conv1 = Masked_Conv2D(output_dim=n_channels, kernel_size=(ks, ks), radius_min=radius_min, radius_max=radius_max, initializer=initializer, use_bias=use_bias) x = conv1(x_in)
The text was updated successfully, but these errors were encountered: