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

SpectralConv2D Implementation #2

Open
kelvinkoh0308 opened this issue Aug 25, 2020 · 0 comments
Open

SpectralConv2D Implementation #2

kelvinkoh0308 opened this issue Aug 25, 2020 · 0 comments

Comments

@kelvinkoh0308
Copy link

Hi
I think there is something wrong in you SpectralConv2D

`def compute_spectral_norm(self):
for _ in range(self.power_iterations):
k = tf.reshape(self.kernel, (-1, self.filters))

        new_v = l2normalize(tf.matmul(k, self.u))
        new_u = l2normalize(tf.matmul(tf.transpose(k), self.v))
        
    sigma = tf.matmul(tf.matmul(tf.transpose(new_v), k), new_u)
    new_kernel = tf.divide(self.kernel, sigma)

    return new_v, new_u, self.kernel


def call(self, inputs):
    new_v, new_u, new_kernel = self.compute_spectral_norm()
    outputs = self._convolution_op(inputs, new_kernel)

    if self.use_bias:
        if self.data_format == 'channels_first':
                outputs = tf.nn.bias_add(outputs, self.bias, data_format='NCHW')
        else:
            outputs = tf.nn.bias_add(outputs, self.bias, data_format='NHWC')
    if self.activation is not None:
        return self.activation(outputs)

    return outputs + [new_v, new_u, new_kernel]`

Inside the compute_spectral_norm, you did not update anything and return back the old kernel.
Inside the call function, the
if self.activation is not None:
will always be true (even though we pass None to the activation function, tensorflow internally will treat this as a linear function) thus this will just become a normal convolution.

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