PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label tensorflow2.0. Show all posts
Showing posts with label tensorflow2.0. Show all posts

Thursday, April 28, 2022

[FIXED] How to suppress specific warning in Tensorflow (Python)

 April 28, 2022     python, suppress-warnings, tensorflow, tensorflow2.0, warnings     No comments   

Issue

I have a model that, based on certain conditions, has some unconnected gradients, and this is exactly what I want. But Tensorflow is printing out a Warning every time it encounters the unconnected gradient.

WARNING:tensorflow:Gradients do not exist for variables

Is there any way to only suppress this specific warning? I don't want to blindly suppress all warnings since there might be unexpected (and potentially useful) warnings in the future as I'm still working on my model.


Solution

Kinda hacky way:

gradients = tape.gradient(loss, model.trainable_variables)
optimizer.apply_gradients([
    (grad, var) 
    for (grad, var) in zip(gradients, model.trainable_variables) 
    if grad is not None
])


Answered By - Jared Nielsen
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing