У меня есть этот код, и он вызывает ошибку в python 3, и такое сравнение может работать на python 2, как я могу его изменить
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()