Code Monkey home page Code Monkey logo

Comments (5)

NBCBM avatar NBCBM commented on April 27, 2024

''' import tensorflow as tf
from keras.losses import Loss
class DeterminantZeroLoss(Loss):
def init(self, name="determinant_zero_loss"):
super().init(name=name)

def call(self, y_true, y_pred):
    try:
        # Calculate the determinant of the predicted matrix
        det = tf.linalg.det(y_pred)
    except tf.errors.InvalidArgumentError as e:
        # Handle the case where the matrix inversion fails
        # You can print the error message or take any other appropriate action
        print("Matrix inversion failed:", e)
        # Return a large loss value to indicate the failure
        return 1e6

    # Penalize when the determinant is close to zero
    loss = tf.abs(det)

    return loss

'''
hope it helps

from tensorflow.

Sur3 avatar Sur3 commented on April 27, 2024

except tf.errors.InvalidArgumentError as e:

Sadly that didn't catch the error, but I found out the error seems to only occur if I use
kernel_initializer=tf.keras.initializers.Zeros()
in one of the layers as well as the determinant=0 loss.

PS:

    return 1e6
# Penalize when the determinant is close to zero
loss = tf.abs(det)

You seem to have missunderstood that, when the matrix is not invertible the determinant should be zero, therefore the loss should be low, if the determinant is close to zero that is good and not penalized ;)

from tensorflow.

SuryanarayanaY avatar SuryanarayanaY commented on April 27, 2024

Hi @Sur3 ,

Could you able to submit a reproducible code snippet to debug this? Thanks!

from tensorflow.

github-actions avatar github-actions commented on April 27, 2024

This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.

from tensorflow.

Sur3 avatar Sur3 commented on April 27, 2024

Sorry I didn't find time to produce a full code example yet, maybe next week.

from tensorflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.