Jireh-Jam / R-MNet-Inpainting-keras

R-MNET: A Perceptual Adversarial Network for Image Inpainting model in Keras
23 stars 6 forks source link

Losses #8

Open mdelhussieny opened 2 years ago

mdelhussieny commented 2 years ago

I have several comments on your work first: Wasserstein loss always return zero in case of fake images as fake (np.zeros) from the discriminator so it cannot distinguish the fake from the real.

second: your reverse mask loss always get zero

def generator_loss(self, y_true,y_pred):
    ones = K.ones_like(y_pred[:,:,:,1])
    mask = K.stack([ones]*self.channels, axis=-1)
    input_img = Lambda(lambda x : x[:,:,:,0:3])(y_true)
    output_img = Lambda(lambda x : x[:,:,:,0:3])(y_pred)
    reversed_mask = Lambda(self.reverse_mask,output_shape=(self.img_shape_mask))(mask) # always be zero
    vgg = VGG19(include_top=False, weights='imagenet', input_shape=self.img_shape)
    loss_model = Model(inputs=vgg.input, outputs=vgg.get_layer('block3_conv3').output)
    loss_model.trainable = False
    p_loss = K.mean(K.square(loss_model(output_img) - loss_model(input_img)))
    masking = Multiply()([reversed_mask,input_img])
    predicting = Multiply()([reversed_mask, output_img])
    reversed_mask_loss = (K.mean(K.square(loss_model(predicting) - loss_model(masking))))
    new_loss = 0.6*(p_loss) + 0.4*reversed_mask_loss
    return new_loss 
Jireh-Jam commented 2 years ago

Hi, This will not work with TF 2.0. I guess you might be using TF2.0. I am yet to do the model to work with this version of TensorFlow. However, use TF 1.14 and Keras 2.2.4 for the model. It will output the correct losses. I appreciate if you work on it. I have other jobs at the moment and will get to this soon.

Jireh-Jam commented 2 years ago

TF 2.0 if effective if you use Gradient Tape. So this is something in the feature in a separate branch for the model to work.

mdelhussieny commented 2 years ago

ones = K.ones_like(y_pred[:,:,:,1]) will give you tensor of ones, reversed_mask = Lambda(self.reverse_mask,output_shape=(self.img_shape_mask))(mask) will give you tensor of zeros. So masking = Multiply()([reversed_mask,input_img]), predicting = Multiply()([reversed_mask, output_img]) will be zero. that is my point nothing related to TF version

Jireh-Jam commented 2 years ago

Yes, the pull request you added for the loss is the original loss I used during training. But now with TF 2.0 D loss is zero. However with TF 1.14, everything works fine.