loss-function

Channel wise CrossEntropyLoss for image segmentation in pytorch

人走茶凉 提交于 2020-07-05 12:08:45
问题 I am doing an image segmentation task. There are 7 classes in total so the final outout is a tensor like [batch, 7, height, width] which is a softmax output. Now intuitively I wanted to use CrossEntropy loss but the pytorch implementation doesn't work on channel wise one-hot encoded vector So I was planning to make a function on my own. With a help from some stackoverflow, My code so far looks like this from torch.autograd import Variable import torch import torch.nn.functional as F def cross

Channel wise CrossEntropyLoss for image segmentation in pytorch

时光总嘲笑我的痴心妄想 提交于 2020-07-05 12:08:14
问题 I am doing an image segmentation task. There are 7 classes in total so the final outout is a tensor like [batch, 7, height, width] which is a softmax output. Now intuitively I wanted to use CrossEntropy loss but the pytorch implementation doesn't work on channel wise one-hot encoded vector So I was planning to make a function on my own. With a help from some stackoverflow, My code so far looks like this from torch.autograd import Variable import torch import torch.nn.functional as F def cross

Why am I getting None gradient error in keras custom loss function?

泄露秘密 提交于 2020-06-29 06:41:08
问题 I am trying to train a convolutional auto encoder, along with the bounding box for penalizing the inside the boundign box region, for anomaly detection. My custom loss function and supporting functions are below. def assymetric_loss(input_bboxes): def custom_loss(input_images,recons_images): losses=[] for i in range(20): input_image=input_images[i] recons_image=recons_images[i] bbox=input_bboxes[i] #check_null=tf.equal(tf.size(bbox) , 0) x = tf.Variable(-1.0, dtype=tf.float32) check_equal=tf

Keras custom loss as a function of multiple outputs

风流意气都作罢 提交于 2020-05-26 04:28:41
问题 I built a custom architecture with keras (a convnet). The network has 4 heads, each outputting a tensor of different size. I am trying to write a custom loss function as a function of this 4 outputs. I have been implementing cusutom losses before, but it was either a different loss for each head or the same loss for each head. In this case, I need to combine the 4 outputs to calculate the loss. I am used to the following: def custom_loss(y_true, y_pred): return something model.compile

Keras custom loss as a function of multiple outputs

我的梦境 提交于 2020-05-26 04:27:40
问题 I built a custom architecture with keras (a convnet). The network has 4 heads, each outputting a tensor of different size. I am trying to write a custom loss function as a function of this 4 outputs. I have been implementing cusutom losses before, but it was either a different loss for each head or the same loss for each head. In this case, I need to combine the 4 outputs to calculate the loss. I am used to the following: def custom_loss(y_true, y_pred): return something model.compile

RMSE/ RMSLE loss function in Keras

[亡魂溺海] 提交于 2020-05-24 17:20:38
问题 I try to participate in my first Kaggle competition where RMSLE is given as the required loss function. For I have found nothing how to implement this loss function I tried to settle for RMSE . I know this was part of Keras in the past, is there any way to use it in the latest version, maybe with a customized function via backend ? This is the NN I designed: from keras.models import Sequential from keras.layers.core import Dense , Dropout from keras import regularizers model = Sequential()

My model doesn't seem to work, as accuracy and loss are 0

会有一股神秘感。 提交于 2020-05-17 06:42:26
问题 I tried to design an LSTM network using keras but the accuracy is 0.00 while the loss value is 0.05 the code which I wrote is below. model = tf.keras.models.Sequential() model.add(tf.keras.layers.Flatten()) model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu)) model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu)) model.add(tf.keras.layers.Dense(1, activation = tf.nn.relu)) def percentage_difference(y_true, y_pred): return K.mean(abs(y_pred/y_true - 1) * 100) model.compile

My model doesn't seem to work, as accuracy and loss are 0

落花浮王杯 提交于 2020-05-17 06:42:13
问题 I tried to design an LSTM network using keras but the accuracy is 0.00 while the loss value is 0.05 the code which I wrote is below. model = tf.keras.models.Sequential() model.add(tf.keras.layers.Flatten()) model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu)) model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu)) model.add(tf.keras.layers.Dense(1, activation = tf.nn.relu)) def percentage_difference(y_true, y_pred): return K.mean(abs(y_pred/y_true - 1) * 100) model.compile

How load a Keras model with custom loss function?

本秂侑毒 提交于 2020-04-18 05:43:55
问题 I have created the following custom loss function: RMSE = function(y_true,y_pred) { k_sqrt(k_mean(k_square(y_pred - y_true))) } And it works fine when I save the model. However, when I load the model back using: load_model_hdf5(filepath= "modelpath") I get the following error: Error in py_call_impl(callable, dots$args, dots$keywords): valueError: Unknown loss function:RMSE Maybe this question has something in common with this one I made before. How do I avoid keep getting this error? 回答1:

how important is the loss difference between training and validation data at the beginning when training a neuronal network?

只愿长相守 提交于 2020-03-25 15:49:49
问题 Short question: Is the difference between validation and training loss at the beginning of the training (first epochs) a good indicator for the amount of data that should be used? E.g would it be a good method to increase the amount of data until the difference at the beginning is as small as possible? It would save me time and computation. backround: I am working on a neuronal network that overfits very fast. The best result after applying many different techniques like dropouts, batch