All Questions

Tagged with
Filter by
Sorted by
Tagged with
8 votes
1 answer
3k views

Can SigmoidFocalCrossEntropy in Tensorflow (tf-addons) be used in Multiclass Classification? ( What is the right way)?

Focal Loss given in Tensorflow is used for class imbalance. For Binary class classification, there are a lots of codes available but for Multiclass classification, a very little help is there. I ran ...
Deshwal's user avatar
  • 3,862
8 votes
1 answer
6k views

Tensorflow Keras RMSE metric returns different results than my own built RMSE loss function

This is a regression problem My custom RMSE loss: def root_mean_squared_error_loss(y_true, y_pred): return tf.keras.backend.sqrt(tf.keras.losses.MSE(y_true, y_pred)) Training code sample, ...
ma7555's user avatar
  • 370
2 votes
1 answer
451 views

How many times the loss function is triggered from .fit() method in Keras

I am trying to do some custom calculations in the custom loss function. But when I log the statements from the custom loss function, it seems that custom loss function is only called once (in the ...
Rahul's user avatar
  • 47
2 votes
1 answer
535 views

Tensorflow 2.X : Understanding hinge loss

I am learning Tensorflow 2.X. I am following this page to understand hinge loss. I went through the standalone usage code. Code is below - y_true = [[0., 1.], [0., 0.]] y_pred = [[0.6, 0.4], [0.4, 0....
Jay Prakash Thakur's user avatar
2 votes
0 answers
82 views

Negative loss values for adaptive loss in tensorflow

I have used adaptive loss implementation on a neural network, however after training a model long enough, I am getting negative loss values. Any help/suggestion would be highly appreciated! Please let ...
Rahul Sawant's user avatar
1 vote
1 answer
988 views

Keras custom loss with dynamic global variable

So, I am trying to write a custom loss function for my keras model. The loss function needs a global variable which changes after every epoch to calculate the loss, But I am not able to get the ...
Another one of them's user avatar
1 vote
2 answers
131 views

2 outputs in Keras model but only one with missing value?

I'd like to model two variables simultaneously using the same features at the input layer (a feed-forward network), but there are missing values in one of them. I'm wondering if there is a way to mask ...
SAEERON's user avatar
  • 336
1 vote
0 answers
74 views

Same Accuarcy and Loss values over the epochs

I'm working on a project to classify the hand gestures of the "rock, paper, and scissors" game. I know there's already the "rps dataset" provided by tensorflow, but due to its ...
AndreaFilippini's user avatar
1 vote
1 answer
773 views

Weights were not updated using Gradient Tape and apply_gradients()

I am building a DNN with a custom loss function and I am training this DNN using Gradient Tape in TensorFlow.kerasenter code here. The code runs without any errors, however, as far as I can check the ...
sondv89's user avatar
  • 13
1 vote
0 answers
393 views

Tensorflow custom loss function - can't get samples of y_pred and y_true in loss function

I'm running an LSTM network that works fine (TF 2.0). My problem starts when trying to modify the loss function. I planed to adjust some data manipulation over 'y_true' and 'y_pred' but since TF force ...
Ran Kremer's user avatar
1 vote
0 answers
591 views

Custom loss calculation causes RuntimeError: Attempting to capture an EagerTensor without building a function

Environment: tensorflow 2.2 on Windows 10 x64 in CPU only mode. Using tf.keras. I want to build a simple model for image to text recognition (sometimes called OCR). For this I use CRNN model ...
Pavel Chernov's user avatar
1 vote
0 answers
330 views

How to define a custom loss function for a multi-dimensional target

I'm working with Tensorflow 2.0 and I'm using a normal sequential layer. I'm trying to define a custom loss functions which does the following: takes some elements of the input computes their sum ...
Cla's user avatar
  • 181
1 vote
2 answers
612 views

tf.keras two losses, with intermediate layers as input to of one of them error:Inputs to eager execution function cannot be Keras symbolic tensors

I want to have two losses in my tensorflow keras model and one of them takes an intermediate layer as input. This code works when I use keras but when it comes to tensorflow.keras I face the ...
ehsan olyaee's user avatar
1 vote
0 answers
100 views

How to write a custom loss function for mulitple output keras model?

I have a multiple output keras model and currently I pass loss like this model.compile(optimizer='adam', loss=['mse', 'binary_crossentropy'], metrics = ['accuracy']) Instead of using two separate ...
Eka's user avatar
  • 14.6k
0 votes
1 answer
605 views

Loss function and batch size in Keras

For classification task there are several loss-function we can use. If I simply use something like model.compile{ loss=keras.losses.categorical_crossentropy, .... Does this mean loss is normalized in ...
user15494526's user avatar
0 votes
1 answer
811 views

Tensorflow 2.5.0 - TypeError: An op outside of the function building code is being passed a "Graph" tensor

I am training a convolutional Bayesian Neural network where I use tfp.layers.Convolution3DFlipout layers. My loss function is as follows: from tensorflow.keras.losses import binary_crossentropy def ...
Dushi Fdz's user avatar
  • 151
0 votes
1 answer
416 views

In model.fit in tf.keras, is there a way to pass each sample in a batch n times?

I am trying to write a custom loss function for a model that utilizes Monte Carlo (MC) dropout. I want the model to run through each sample in a batch n times before feeding the predictions to the ...
WVJoe's user avatar
  • 525
0 votes
1 answer
100 views

Customized keras loss function using min_g(g, g*)

I am dealing with a regression problem where given an image, I want to predict the value of 3 parameters (cartesian coordinates) . For the same image I can have several acceptable coordinates. To do ...
laurent Bimont's user avatar
0 votes
0 answers
21 views

Passing a group id to custom loss function in Keras R

I was hoping that someone might be able to give me a hand. I've been using keras to model a disease risk factor in 11 different populations and am trying to create a custom loss function that is aware ...
HCutler's user avatar
0 votes
1 answer
300 views

constrained optimization, adding an additional term in a custom loss function in a NN

I am struggling to add an additional constraint into my loss function (Keras, tensorflow) My original loss function is: self.__loss_fn = tf.reduce_mean( tf.square( self.__psiNNy ...
Carlos's user avatar
  • 5
0 votes
1 answer
37 views

Should I use reguaization with Loss function or NN layer?

I'm confused regarding the place of using regularization. In the theory, I saw regularization has been used with the Loss function. But in the time implementation in Keras, I saw regularization has ...
kowser66's user avatar
  • 155
0 votes
1 answer
764 views

How is MSE calculated for multi-output regression in keras?

I have a Keras deep learning model that outputs 6 variables. model = Sequential() model.add(Dense(32, input_dim=12, kernel_initializer='he_uniform', activation='relu')) model.add(Dense(256, activation=...
Glen Hamblin's user avatar
0 votes
1 answer
730 views

Custom loss function and fit data for multiple inputs and outputs in tf.Keras

I am working around with a DNN in tf.Keras, which looks like as follows: # Construct the DNN model with 2 inputs, 2 outputs and 3 hidden layers c0_input = Input(shape=(1,), name="c0") ...
sondv89's user avatar
  • 13
0 votes
1 answer
558 views

Custom Loss involving multivariate normal in keras

I need to implement a loss function whereby it takes in some true y that is a 4 dimensional vector and computes the probability of this vector under some normal distribution. I tried to build the ...
GTOgod's user avatar
  • 93
-1 votes
1 answer
215 views

why did i got 2 different losses for sparse_categorical_crossentropy and categorical_crossentropy?

I trained a model for multiclass classification. There were three classes. In the first approach, I trained a model by converting the classes into one-hot vectors and training a model with loss ...
Dhruv Agarwal's user avatar
-1 votes
1 answer
179 views

Why model's loss is always revolving around 1 in every epoch?

During training, loss of my model is revolving around "1". It is not converging. I tried various optimizer but it still showing the same pattern. I am using keras with tensorflow backend. What could ...
Rahul Anand's user avatar
-2 votes
2 answers
366 views

how to design a custom loss function to add two loss

I am using CNN to solve a regression problem in a supervised manner. i have input data(X_train) and the target data(y_train).
manas's user avatar
  • 471