TypeError:“>" "NoneType"和"float"的实例之间不受支持 [英] TypeError: '>' not supported between instances of 'NoneType' and 'float'

查看:113
本文介绍了TypeError:“>" "NoneType"和"float"的实例之间不受支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码,它在python 3中引发错误,这样的比较可以在python 2上进行 我该如何更改?

I have this code and it raise an error in python 3 and such a comparison can work on python 2 how can I change it?

import tensorflow as tf 
def train_set():
    class MyCallBacks(tf.keras.callbacks.Callback):
        def on_epoch_end(self,epoch,logs={}):
            if(logs.get('acc')>0.95):
                print('the training will stop !')
                self.model.stop_training=True
    callbacks=MyCallBacks()
    mnist_dataset=tf.keras.datasets.mnist 
    (x_train,y_train),(x_test,y_test)=mnist_dataset.load_data()
    x_train=x_train/255.0
    x_test=x_test/255.0
    classifier=tf.keras.Sequential([
                                    tf.keras.layers.Flatten(input_shape=(28,28)),
                                    tf.keras.layers.Dense(512,activation=tf.nn.relu),
                                    tf.keras.layers.Dense(10,activation=tf.nn.softmax)
                                    ])
    classifier.compile(
                        optimizer='sgd',
                        loss='sparse_categorical_crossentropy',
                        metrics=['accuracy']
                       )    
    history=classifier.fit(x_train,y_train,epochs=20,callbacks=[callbacks])
    return history.epoch,history.history['acc'][-1]
train_set()

推荐答案

似乎您的错误类似于

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')

这篇关于TypeError:“>" "NoneType"和"float"的实例之间不受支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆