Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Report of Possible Errors #1

Open
CristianoPatricio opened this issue Apr 20, 2021 · 1 comment
Open

Report of Possible Errors #1

CristianoPatricio opened this issue Apr 20, 2021 · 1 comment

Comments

@CristianoPatricio
Copy link

Hello,

I ran into some errors while running the code, which are summarized below:

#1 from keras.layers.merge import _Merge ImportError: cannot import name '_Merge' from 'keras.layers.merge' python

Since Merge is not supported in Keras +2, I have made some modifications to the RandomWeightedAverage() class:

Old code:

from keras.layers.merge import _Merge
import keras.backend as K

class RandomWeightedAverage(_Merge):
    """Provides a (random) weighted average between real and generated image samples"""
    def _merge_function(self, inputs):
        alpha = K.random_uniform((1024, 1))
        return (alpha * inputs[0]) + ((1 - alpha) * inputs[1])

Funtional code:

import keras.backend as K
import tensorflow as tf

class RandomWeightedAverage(tf.keras.layers.Layer):
    def call(self, inputs, **kwargs):
        alpha = K.random_uniform((1024, 1))
        return (alpha * inputs[0]) + ((1 - alpha) * inputs[1])

Then, you need to do a little change in line 48 of the CLSWGAN.py file:

FROM

interpolated_features = RandomWeightedAverage()([real_features, fake_features])

TO

interpolated_features = RandomWeightedAverage()(inputs=[real_features, fake_features])

#2 AttributeError: Can't set the attribute "name"

Another error is related to the attribute "name" in line 69 of the CLSWGAN.py file. The solution is as simple as add a "_" before the attribute "name":

classificationLayer._name = 'modelClassifier'

#3 ValueError: Tried to convert 'x' to a tensor and failed. Error: None values not supported

This error was mentioned in the jacobgil/keras-grad-cam#17 (comment) issue, and appears to have been fixed by adding a piece of code to the LossFunctions.py file, namely the _compute_gradients(tensor, var_list) function and a small change to line 15.

import tensorflow as tf

def _compute_gradients(tensor, var_list):
    grads = tf.gradients(tensor, var_list)
    return [grad if grad is not None else tf.zeros_like(var) for var, grad in zip(var_list, grads)]

def gradient_penalty_loss(y_true, y_pred, averaged_samples):
    """
    Computes gradient penalty based on prediction and weighted real / fake samples
    """
    gradients = _compute_gradients(y_pred, [averaged_samples])[0]
    (...)
@CristianoPatricio CristianoPatricio changed the title Report of Possible Bugs Report of Possible Errors Apr 20, 2021
@ShayanRamazi
Copy link
Owner

tanks for your report @CristianoPatricio

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants