loss-function

tensorflow MDA custom loss and ValueError: No gradients provided for any variable

tensorflow MDA custom loss and ValueError: No gradients provided for any variable Question: I would like to use the MDA (mean direction accuracy) as a custom loss function for a tensorflow neural network. I am trying to implement this as described in here: Custom Mean Directional Accuracy loss function in Keras def mda(y_true, y_pred): s …

Total answers: 3

How to debug a custom loss function during model fitting?

How to debug a custom loss function during model fitting? Question: I would like to see what is happening in my loss function during model fitting. However, I cannot figure out how to do that. This is what I am trying but it does not work: def custom_loss(label : tf.Tensor, pred : tf.Tensor) -> tf.Tensor: …

Total answers: 1

How to save/load a model checkpoint with several losses in Pytorch?

How to save/load a model checkpoint with several losses in Pytorch? Question: Using Ubuntu 20.04, Pytorch 1.10.1. I am trying to solve a music generation task with a transformer architecture and multi-embeddings, for processing tokens with several characteristics. In each training iteration, I have to calculate the loss of each token characteristic and store it …

Total answers: 2

Why is my loss function increasing with each epoch?

Why is my loss function increasing with each epoch? Question: I’m new to ML, so I’m sorry if this is some stupid question anyone could have figured out. I am using TensorFlow and Keras here. So here’s my code: import tensorflow as tf import numpy as np from tensorflow import keras model = keras.Sequential([ keras.layers.Dense(units=1, …

Total answers: 2

how to add tensorflow loss functions?

how to add tensorflow loss functions? Question: I can not add these two losses as follows real_loss = tf.losses.BinaryCrossentropy(tf.ones_like(train_images[0]),train_images[0]) fake_loss = tf.losses.BinaryCrossentropy(tf.zeros_like(train_images[0]),train_images[0]) fake_loss+real_loss the error is: TypeError: unsupported operand type(s) for +: ‘BinaryCrossentropy’ and ‘BinaryCrossentropy’ Asked By: Ali N777 || Source Answers: You can just add them as multiple losses in model.compile model.compile(loss = [loss1,loss2], …

Total answers: 1

Define custom loss (perceptual loss) in CNN autoencoder with pre-train vgg19 tensorflow,Keras

Define custom loss (perceptual loss) in CNN autoencoder with pre-train vgg19 tensorflow,Keras Question: i want to define perceptual_loss in autoencoder that build in keras. my autoencoder is look like this : Encoder: input_encoder = Input((32,32,3),name = ‘encoder_input’) encoder = Conv2D(16,(3,3),activation = ‘relu’,name = ‘encoder_layer1’)(input_encoder) encoder = Flatten(name = ‘encoder_layer2’)(encoder) latent_encoding = Dense(128 , activation = …

Total answers: 2

Size of y_true in custom loss function of Keras

Size of y_true in custom loss function of Keras Question: I am trying to write a custom loss function for U-net in Keras and the objective of it is to compute not only the mean square error (MSE) of the predicted image and the true image, but also the MSE of their gradients. I am …

Total answers: 1