Custom loss function NOT found
See original GitHub issueI’ve defined several custom loss functions:
dice_loss = dice_loss(num_classes=args.num_classes,name='dice_loss')
tversky_loss = tversky_loss(beta=0.7,num_classes = args.num_classes,name='tversky_loss)
and my build model function is like this:
def build_model(hp):
model = models.segmentationModel(output_channels=args.num_classes)
model.build(input_shape=((1,256,256,3)))
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=hp.Choice('learning_rate', [1e-2, 1e-3, 1e-4])),
loss = hp.Choice('loss', ['dice_loss', 'tversky_loss']),
metrics=[tf.keras.metrics.SparseCategoricalAccuracy(name='sparse_categorical_accuracy', dtype=None),UpdatedMeanIoU(name='Mean_IOU',num_classes=args.num_classes)])
return model
When I execute this code, I get this error:
ValueError: Unknown loss function:dice_loss
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Simple Enclosed Custom loss function not working
I have worked with custom functions in the past and just today this shocked me. Why isn't it working? how can I make...
Read more >Custom loss function not working properly - TensorFlow Forum
I am training a convolutional neural network which predicts one label. I want to ignore loss resulted from some predictions during training.
Read more >How To Build Custom Loss Functions In Keras For Any Use ...
This means that the custom loss function you designed, is not suitable for the dataset, and the business problem you are trying to...
Read more >How to create a custom loss function in Keras | by Dhiraj K
Learn how to define and implement a custom loss function for training a machine learning model in ... Don't worry about missing out...
Read more >Custom Loss Function in TensorFlow | by Marco Sanguineti
The choice of an objective function is not arbitrary and can sometimes ... We can find this loss function pre-implemented (tf.keras.losses.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dhaneshr I think you might have to try something similar to what is mentioned here when loading custom objects.
Keras would not know from the strings
dice_loss
andtversky_loss
that you mean your custom implementations.Something like this might help:
Hi again Mandar,
I ended up implementing the 2nd option which seems to be working so far. Here is my code: