All Questions
462 questions
-1
votes
1
answer
45
views
implement a differentiable L0 regularizer to keras layer
What is the appropriate way to implement a differentiable variant of L0 regularizer (count the non-zero values in a Conv layer / matrix) to keras layer?
I was thinking of using r(x) = tanh(abs(f*x)) ...
2
votes
0
answers
66
views
Can't replicate the behaviour of loss calculation in keras
I am working on a semantic segmentation problem where I have an input x ( CT image) to a deep learning model of shape (batch_size,1,256,256) and an output of shape (batch_size,2,256,256) where the ...
0
votes
0
answers
43
views
keras.models.load_model() reinitalized custom lossfunction to default arguments
I am tring to make and then save a model in python file, and then train the model in another file.
This model uses a custom loss function that is in a seperate python file, so it can be imported into ...
1
vote
1
answer
98
views
In Keras, how can I save and load a neural network model that includes a custom loss function?
I am having difficulty saving and reloading a neural network model when I use a custom loss function. For example, in the code below (which integrates the suggestions of the related questions here ...
0
votes
0
answers
68
views
Custom Loss function Cannot squeeze axis=-1
I'm working on implementing a custom loss function in TensorFlow/Keras that incorporates both categorical cross-entropy loss and a penalty based on custom rules. These rules are designed to penalize ...
0
votes
1
answer
107
views
Keras 3 Custom Loss Function to mask NaN
I am trying to build a custom Loss function on Keras 3, which would be used either in jax or torch backend.
I want to mask out of y_pred and y_true all the indices where y_true is a certain value. ...
-1
votes
1
answer
210
views
How to interpret training and validation loss graph in Keras, is it a good fit? [closed]
I've trained a Keras model and obtained a graph with training and validation loss curves. The graph shows the following pattern: enter image description here
Can someone help me interpret this graph? ...
1
vote
0
answers
26
views
Implementation of a Custom Loss Function in Keras for a Multi-item Newsvendor Problem with Substitutions
I want to implement a custom loss function in Keras for a Newsvendor. Problem (Demand forecasting and problem solving integrated in one ANN). The challenging part is that I have multiple products with ...
0
votes
2
answers
72
views
Why generator loss using BinaryCrossEntropy with from_logits enabled?
From a simple vanilla GAN code I look from GitHub
I saw this generator model with activation sigmoid:
# Generator
G = tf.keras.models.Sequential([
tf.keras.layers.Dense(28*28 // 2, input_shape = (...
0
votes
0
answers
41
views
Custom fit function involving multiple outputs
class CustomModel(keras.Model):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.loss_tracker = keras.metrics.Mean(name="loss")
self.mae_metric = keras....
0
votes
1
answer
290
views
Handling Class Imbalance in Multi-class Classification with Custom Loss Function [closed]
I am working on a multi-class classification problem in Python using advanced machine learning techniques. The dataset I am dealing with has a significant class imbalance issue, where some classes are ...
2
votes
1
answer
373
views
TensorFlow Custom Loss Function Error: Node: 'gradient_tape/contrastive_loss/mul/BroadcastGradientArgs' Incompatible shapes [0,1] vs. [32,1]
I'm working on a Siamese network using TensorFlow and Keras. As the data is huge I am also trying to use the generator for batch loading. I have a custom contrastive loss function that I'm using for ...
0
votes
1
answer
710
views
Does Google Colab have its own random seed?
Does Google Colab have its own random seed that has nothing to do with TensorFlow or Numpy?
I used the set_random_seed() function of Keras Utils and unify by 777 to the seed of the Numpy, TensorFlow, ...
0
votes
1
answer
85
views
Keras custom loss with external data
Hello? I'm trying to write custom loss function with external data.
My code is like that:
classes_distributions = K.variable(np.full((A, A), 1.0 / A, dtype=float))
def my_loss(distributions):
def ...
1
vote
0
answers
45
views
Why is the loss becoming NaN during training in my Keras model?
I am training a Keras model with complex input data using the CVNN library. However, during training, the loss becomes NaN after the first epoch. Here is the relevant code:
import cvnn.layers as ...