Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Approach to NaN handling in TFJS #255

Open
Mattk70 opened this issue Feb 14, 2024 · 0 comments
Open

Approach to NaN handling in TFJS #255

Mattk70 opened this issue Feb 14, 2024 · 0 comments

Comments

@Mattk70
Copy link
Contributor

Mattk70 commented Feb 14, 2024

This is unlikely to be a big issue in the context of the TFJS example, but perhaps a similar issue affects the python version too? This snippet is from main.js in the TFJS example:

                // Normalize values between -1 and 1
                input = tf.sub(input, tf.min(input, -1, true));
                input = tf.div(input, tf.max(input, -1, true).add(0.000001));
                input = tf.sub(input, 0.5);
                input = tf.mul(input, 2.0);

When you add a small number to the divisor to avoid an infinity value, you will get a large number, which is not between 1 and -1. In tensorflowjs, you should use tf.divNoNan() so n/0 returns 0. I believe the python version of tensorflow has an equivalent tf.math.divide_no_nan() function.

It's an edge case, but has caused headaches for me when analysing audio with a fade effect.

@Mattk70 Mattk70 changed the title Approach to NaN handling in TFJS is not optimal Approach to NaN handling in TFJS Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant