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
Plot the complete to one loss function
When I plot the loss function of my code I get a nice loss plot.
If I want to plot the 1-hist.history['loss'], how can I do it?
Part of my code:
model = Sequential([
Dense(32, activation='relu', input_shape=(2,)),
Dense(32,…

Ram Rahamim
- 49
- 6
0
votes
1 answer
Testing and Confidence score of Network trained with nn.CrossEntropyLoss()
I have trained a network with the following structure:
Intent_LSTM(
(attention): Attention()
(embedding): Embedding(34601, 400)
(lstm): LSTM(400, 512, num_layers=2, batch_first=True, dropout=0.5)
(dropout): Dropout(p=0.5, inplace=False)
(fc):…

Bot_Start
- 145
- 1
- 2
- 9
0
votes
1 answer
Implementing BCEWithLogitsLoss from pytorch in keras
I have a model that I am trying to train on a dataset which has a class imbalance. The problem is a multilabel classification problem (each sample has 1 or more labels). I also have weights for each class which I have calculated for my dataset. I…

Kevin
- 3,077
- 6
- 31
- 77
0
votes
1 answer
How to use a particular pixel from the image as a loss function keras?
So I have 100x100x3 images and its a classification problem with 3 categories.
So my CNN architecture is as follows:
visible = Input(shape=(100, 100, 3))
conv_1 = Conv2D(filters=32, kernel_size=(3, 3), strides=(1, 1),…

idpd15
- 448
- 2
- 5
- 22
0
votes
1 answer
Understanding choice of loss and activation in deep autoencoder?
I am following this keras tutorial to create an autoencoder using the MNIST dataset. Here is the tutorial: https://blog.keras.io/building-autoencoders-in-keras.html.
However, I am confused with the choice of activation and loss for the simple…

Jane Sully
- 3,137
- 10
- 48
- 87
0
votes
0 answers
Tensorflow MeanSquaredError doens't work on one number
I am trying calculate the loss of a network with tensorflow mean squared error, but for some reason it doesn't work if the input tensors only have one number. How should do this instead.
Here is some code:
import tensorflow as tf
loss =…
user12069894
0
votes
1 answer
Why does loss decrease but accuracy decreases too (Pytorch, LSTM)?
I have built a model with LSTM - Linear modules in Pytorch for a classification problem (10 classes). I am training the model and for each epoch I output the loss and accuracy in the training set. The ouput is as follows:
epoch: 0 start!
Loss:…
user12546101
0
votes
2 answers
How do you gather the elements of y_pred that do not correspond to the true label in a Keras/tf2.0 custom loss function?
Below is a simple example in numpy of what I would like to do:
import numpy as np
y_true = np.array([0,0,1])
y_pred = np.array([0.1,0.2,0.7])
yc = (1-y_true).astype('bool')
desired = y_pred[yc]
>>> desired
>>> array([0.1, 0.2])
So the…

Nick Merrill
- 104
- 9
0
votes
0 answers
How do I calculate the mean squared error in a neural network with more than one output?
So from what I've understood the formula of the MSE is: MSE= 1/n * ∑(t−y)^2, where n is the number of training sets, t is my target output and y my actual output. Let's say I had 2 training sets each with 1 output:
[0;0] t=[0] y=[1]
[1;1] t=[1]…

L2CH
- 13
- 3
0
votes
1 answer
Loss function variational Autoencoder in Tensorflow example
I have a question regarding the loss function in variational autoencoder. I followed the tensorflow example https://www.tensorflow.org/tutorials/generative/cvae to create a LSTM-VAE, for sampling a sinus function.
My encoder-input is a set of…
0
votes
1 answer
Tensorflow seq2seq Model, loss value is good, but prediction is false
I'm trying to train a Seq2Seq model. It should translate sentences from a source_vocabulary to sentences in a target_vocabulary.
The loss value is 0.28, but the network doesn't predict words from the target-vocabulary. Instead the predictions of the…
0
votes
1 answer
How to make a custom loss function in Keras properly
i am making a mode that the prediction is a metrix from a conv layer.
my loss function is
def custom_loss(y_true, y_pred):
print("in loss...")
final_loss = float(0)
print(y_pred.shape)
print(y_true.shape)
for i in range(7):
…

Eshaka
- 974
- 1
- 14
- 38
0
votes
1 answer
Can we use sigmoid activation function and binary _crossentropy for one hot encoded labels
I am working on image dataset, where i have one hot encoded labels. Shape of label vector is (3500,8). When i try categorical cross entropy and softmax function in output layer my accuracy is very low. But when i use binary cross entropy and sigmoid…

Talha Anwar
- 2,699
- 4
- 23
- 62
0
votes
1 answer
How to create my own loss function in Pytorch?
I'd like to create a model that predicts parameters of a circle (coordinates of center, radius).
Input is an array of points (of arc with noise):
def generate_circle(x0, y0, r, start_angle, phi, N, sigma):
theta =…

ashy_fox
- 26
- 2
0
votes
1 answer
How to use haversine function as loss function while training model in Tensorflow?
I want to train a LSTM model to predict the position(latitude,longitude) of the ocean float. I try to use the haversine loss function, but I dont't know how to implement it.
To be exact, I use the Keras and the shape of the model output is…

Vickyyyy
- 1
- 1