1

私はテンソルフローバージョン1.12を使用しています

これは私のコードです

    train_loss_results = []
train_accuracy_results = []
num_epochs = 201

for epoch in range(num_epochs):
    epoch_loss_avg = tf.metrics.Mean()
    epoch_accuracy = tf.metrics.Accuracy()
    for x,y in train_dataset:
        loss_value,grads = grad(model,x,y)
        optimizer.apply_gradients(zip(grads,model.variables),global_step)
        epoch_loss_avg(loss_value)
        epoch_accuracy(tf.argmax(model(x), axis=1, output_type=tf.int32), y)
train_loss_results.append(epoch_loss_avg.result())
train_accuracy_results.append(epoch_accuracy.result())
if epoch % 50 == 0:
    print("Epoch {:03d}: Loss: {:.3f}, Accuracy: {:.3%}".format(epoch,
                                                                epoch_loss_avg.result(),
                                                                epoch_accuracy.result()))

これがエラーです

 AttributeError                            Traceback (most recent call last)
<ipython-input-33-6c3fabbf8b76> in <module>
      4 
      5 for epoch in range(num_epochs):
----> 6     epoch_loss_avg = tf.metrics.Mean()
      7     epoch_accuracy = tf.metrics.Accuracy()
      8     for x,y in train_dataset:


AttributeError: module 'tensorflow._api.v1.metrics' has no attribute 'Mean'

これを解決するには?

4

1 に答える 1