Questions tagged [loss]
599 questions
7
votes
2 answers
How to conditionally assign values to tensor [masking for loss function]?
I want to create a L2 loss function that ignores values (=> pixels) where the label has the value 0. The tensor batch[1] contains the labels while output is a tensor for the net output, both have a shape of (None,300,300,1).
labels_mask =…

ScientiaEtVeritas
- 5,158
- 4
- 41
- 59
6
votes
2 answers
Training MSE loss larger than theoretical maximum?
I am training a keras model whose last layer is a single sigmoid unit:
output = Dense(units=1, activation='sigmoid')
I am training this model with some training data in which the expected output is always a number between 0.0 and 1.0.
I am…

oooliverrr
- 98
- 7
6
votes
1 answer
Why does Keras loss drop dramatically after the first epoch?
I'm training a U-Net CNN in Keras/Tensorflow and find that loss massively decreases between the last batch of the first epoch, and the first batch of the second epoch:
Epoch 00001: loss improved from inf to 0.07185 - categorical_accuracy:…

Tom Halmos
- 103
- 5
6
votes
2 answers
keras combining two losses with adjustable weights where the outputs do not have the same dimensionality
My question is similar to the one posed here:
keras combining two losses with adjustable weights
However, the outputs have a different dimensionality resulting in the outputs not being able to be concatenated. Hence, the solution is not applicable,…

Olivier_s_j
- 5,490
- 24
- 80
- 126
6
votes
1 answer
Keras : How to use weights of a layer in loss function?
I am implementing a custom loss function in keras. The model is an autoencoder. The first layer is an Embedding layer, which embed an input of size (batch_size, sentence_length) into (batch_size, sentence_length, embedding_dimension). Then the model…

mat112
- 71
- 6
6
votes
1 answer
How can I implement the Kullback-Leibler loss in TensorFlow?
I need to minimize KL loss in tensorflow.
I tried this function tf.contrib.distributions.kl(dist_a, dist_b, allow_nan=False, name=None), but I failed.
I tried to implement it manually:
def kl_divergence(p,q):
return p*…

Alberto Merciai
- 474
- 1
- 5
- 17
6
votes
1 answer
Difference between Tensorflow and Scikitlearn log_loss function implementation
Hi I am trying to get into tensorflow and feeling a bit dumb.
Does log_loss in TF differ from sklearn's one?
Here are some lines from my code, how I am calculating:
from sklearn.metrics import log_loss
tmp = np.array(y_test)
y_test_t =…

dchirikov
- 244
- 1
- 3
6
votes
1 answer
Tensorflow - loss starts high and does not decrease
i started writing Neuronal Networks with tensorflow and there is one Problem i seem to face in each of my example Projects.
My loss allways starts at something like 50 or higher and does not decrease or if it does, it does so slowly that after all…

J Polack
- 118
- 1
- 1
- 5
6
votes
4 answers
How do I combine tf.absolute and tf.square to create the Huber loss function in Tensorflow?
To be precise, the loss function that I'm looking for is the squared error when the absolute error is lesser than 0.5, and it is the absolute error itself, when the absolute error is greater than 0.5. In this way, the gradient from the error…

Eddy
- 121
- 1
- 6
5
votes
4 answers
calculate accuracy for each class using CNN and pytorch
I Can calculate accuracy after each epoch using this code . But, I want to calculate the accuracy for each class at the end . how can i do that?
I have two folders train and val . each folder has 7 folders of 7 different classes. the train folder is…

Shorouk Adel
- 127
- 3
- 20
5
votes
1 answer
MSELoss when mask is used
I'm trying to calculate MSELoss when mask is used. Suppose that I have tensor with batch_size of 2: [2, 33, 1] as my target, and another input tensor with the same shape. Since sequence length might differ for each instance, I have also a binary…

inverted_index
- 2,329
- 21
- 40
5
votes
2 answers
Keras: Validation accuracy stays the exact same but validation loss decreases
I know that the problem can't be with the dataset because I've seen other projects use the same dataset.
Here is my data preprocessing code:
import pandas as pd
dataset = pd.read_csv('political_tweets.csv')
dataset.head()
dataset =…

Khanrad
- 129
- 1
- 1
- 10
5
votes
1 answer
Why is my val_accuracy stagnant at 0.0000e+00 while my val_loss is increasing from the start?
I am training a classification model to classify cells, and my model is based on this paper: https://www.nature.com/articles/s41598-019-50010-9. As my dataset consists of only 10 images, I performed image augmentation to artificially increase the…

Strider1994
- 141
- 1
- 7
5
votes
2 answers
How to deal with mini-batch loss in Pytorch?
I feed mini-batch data to model, and I just want to know how to deal with the loss. Could I accumulate the loss, then call the backward like:
...
def neg_log_likelihood(self, sentences, tags, length):
self.batch_size =…

yanwii
- 170
- 2
- 12
5
votes
0 answers
Custom loss function: How to add hidden layer's output in loss function in keras with Tensorflow
In my model, the output of the hidden layer, namely 'encoded', has two channels (eg. shape: [none, 128, 128, 2]). I hope to add SSIM between these two channels in loss function:
loss = ssim(input, output) + theta*ssim(encoded(channel1),…

user2789986
- 67
- 5