Wednesday, June 2, 2021

Error in apply gradient : ValueError: too many values to unpack (expected 2)

 Use zip

Wrong : gen_optimizer.apply_gradients(gen_gradient , generator.trainable_variables)

This will give error :


/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/optimizer_v2/utils.py in filter_empty_gradients(grads_and_vars)
     65   filtered = []
     66   vars_with_empty_grads = []
---> 67   for grad, var in grads_and_vars:
     68     if grad is None:
     69       vars_with_empty_grads.append(var)

ValueError: too many values to unpack (expected 2)


The reason is zip is not used

Correct : 
 gen_optimizer.apply_gradients(zip(gen_gradient , generator.trainable_variables))

No comments:

Post a Comment

How to check local and global angular versions

 Use the command ng version (or ng v ) to find the version of Angular CLI in the current folder. Run it outside of the Angular project, to f...