Typeerror: '>' Not Supported Between Instances Of 'nonetype' And 'float'
Solution 1:
Tensorflow 2.0
DESIRED_ACCURACY = 0.979classmyCallback(tf.keras.callbacks.Callback):
defon_epoch_end(self, epochs, logs={}) :
if(logs.get('acc') isnotNoneand logs.get('acc') >= DESIRED_ACCURACY) :
print('\nReached 99.9% accuracy so cancelling training!')
self.model.stop_training = True
callbacks = myCallback()
Solution 2:
it seems that your error is similar to Exception with Callback in Keras - Tensorflow 2.0 - Python
try replacing logs.get('acc')
with logs.get('accuracy')
Solution 3:
It works in Python2 because in Python2 you can compare None
with float
but this is not possible in Python3.
This line
logs.get('acc')
returns None
and there is your problem.
Quick solution would be to replace the condition with
if logs.get('acc') isnot None and logs.get('acc') > 0.95:
If logs.get('acc')
is None
then the above condition will be short-circuited and the second part, logs.get('acc') > 0.95
, will not be evaluated, therefore it will not cause the mentioned error.
Solution 4:
Inside your callback try this :
classmyCallback(tf.keras.callbacks.Callback):
defon_epoch_end(self, epoch, logs={}):
print("---",logs,"---")
'''
if(logs.get('acc')>=0.99):
print("Reached 99% accuracy so cancelling training!")
'''
It gave me this
--- {'loss': 0.18487292938232422, 'acc': 0.94411665} ---
I had acc
so I used, if had accuracy
I would have used accuracy
. So log and what do you have then use that.
TF goes through major changes all the time, so its ok to play safe, very safe.
Solution 5:
Use 'acc' instead of 'accuracy' and you don't need to change.
Post a Comment for "Typeerror: '>' Not Supported Between Instances Of 'nonetype' And 'float'"