If Y_pred
is very far off from Y
, the Loss value will be very high. However, if both values are almost similar, the Loss value will be very low. Hence we need to keep a loss function which can penalize a model effectively while it is training on a dataset.
When a neural network is trying to predict a discrete value, we can consider it to be a classification model. This could be a network trying to predict what kind of animal is present in an image, or whether an email is a spam or not.
Questions tagged [loss-function]
1727 questions
0
votes
1 answer
A generalized quadratic loss for deep neural network for multi-class classification
I'm evaluating the possibility to introduce a new loss for the subject described above.
Let be the number of examples, the number of classes,
the classifier output on example and the binary indicator (0 or 1) if class label is the correct…

Filippo Portera
- 81
- 7
0
votes
0 answers
How to use a kernel filter in tensorflow loss?
I'm trying to use a kernel filter in my custom loss, to help to identify pixels continuity (lines).
I want to apply this kernel to value line-like shapes and depreciate blocks of pixels.
For example, I want to use kernels for image processing, like…

Felipe Reis
- 41
- 1
- 7
0
votes
1 answer
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
When I run the program I get this error:
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
However I had set gen_y = torch.tensor(gen_y,requires_grad=True), but this has not helped, gen_y.grad_fn is None. And I…

obel
- 1
- 1
- 1
0
votes
0 answers
Custom loss function in keras throws an error
I am trying to use a Custom Loss Function to prevent False Positives. I found this post Custom loss function in Keras to penalize false negatives, which is very similar to mine, but when I implement these functions, the model returns me the next…

Cristina V
- 117
- 7
0
votes
2 answers
Pytorch BCELoss not accepting lists
My convLSTM model returns a list of hidden states (17 total, size (1,3,128,128)) and my target is a list of 17 images( all tensors size: (3,128,128)
When the loss function is called, I get the following error:
File…

3venthoriz0n
- 117
- 2
- 12
0
votes
1 answer
Tensorflow take mean of the elements of a masked tensor
To handle variable length input sequence, all the input sequences are padded to same length. This effects in calculating the value of loss. So a mask tensor is multiplied with the loss tensor to make the loss generated by padded elements 0. But in…

Prabhakar Tayenjam
- 129
- 2
- 8
0
votes
1 answer
Keras - Implementation of custom loss function with multiple outputs
I am trying to replicate (a way smaller version) of the AlphaGo Zero system. However, in the network model, I am having a problem. The loss function I am supposed to implement is the following:
Where:
z is the label (a real value between -1 and 1)…

ihavenoidea
- 629
- 1
- 7
- 26
0
votes
0 answers
Hausdorff loss for U-Net segmentation Keras
I wanted to use the hausdorff I found here (https://github.com/N0vel/weighted-hausdorff-distance-tensorflow-keras-loss) as loss in my U-Net, but when I try to do so I get the following error:
ValueError: Dimensions must be equal, but are 3 and 2 for…

Hagear
- 3
- 2
0
votes
1 answer
writing specific loss function for UNET
I am trying to write my own loss function for the UNET. In this function I want to assign the all differences bigger than 10 between y_true and y_pred to 10 and all differences smaller than 1 to 1. is there any convenient way of comparing and…

narmin
- 39
- 5
0
votes
1 answer
How to use different activations in output layer in Keras in R
I want to combine more types of activations in output layer in Keras interface for R. Also, I want to use different loss functions for different outputs. Lets say I want to have first two neurons linear with MSE loss, second 2 neurons sigmoid with…

pikachu
- 690
- 1
- 6
- 17
0
votes
1 answer
What loss function to use if the output layer (label) is composed of one-hot vectors and zero vectors?
I am trying to design a classification model based on Deep Learning with TensorFlow and Keras. In my model, the label is a sequence with variable length, for example: ABC, CADB or ABCDB.
For simplicity, in the output layer I use a fixed…

BioCoder
- 597
- 1
- 5
- 14
0
votes
2 answers
Tensor construction with a loop over number of batches
I want to create a tensor which is some kind of a transformation matrix (rotation matrix for instance)
My model predicts 2 parameters: x1 and x2
so the output is a tensor of (B, 2), when B is number of batches.
however, when I write my loss, I have…

Jenia Golbstein
- 374
- 2
- 12
0
votes
1 answer
Custom loss is missing an operation for gradient
I'm not too sure how to deal with this and why I am getting this error.
raise ValueError('An operation has `None` for gradient. '
ValueError: An operation has `None` for gradient. Please make sure that all of your ops have a gradient…

MNM
- 2,673
- 6
- 38
- 73
0
votes
1 answer
Average error and standard deviation of error within epoch not correctly updating - PyTorch
I am attempting to use Stochastic Gradient Descent but I am unsure as to why my error/loss is not decreasing. The information I am using from the train dataframe is the index (each sequence) and the binding affinity, and the goal is to predict the…

Fareed Mabrouk
- 67
- 1
- 9
0
votes
0 answers
Keras Create New Loss Function
I am looking to design a custom loss function for Keras model. The model itself is neural network that accepts a set of images and is supposed to run a regression to get an output, which is a value. Due to the physical conditions of the problem, I…

statwanderer
- 113
- 6