Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

การประเมินโมเดลด้วย TensorFlow Estimator และ Python


แนวคิด

ใช้ evaluate method ใน classifier module ประเมินโมเดล

ใช้ Keras Sequential API, CNN, TensorFlow Text, Google Colab, Estimator, Iris dataset เหมือนเดิม

ตัวอย่างโค้ด

eval_result = classifier.evaluate(input_fn=lambda: input_fn(test, test_y, training=False))
print('\nTest dataset accuracy is: {accuracy:0.3f}\n'.format(**eval_result))

Credit: TensorFlow Tutorials

ผลลัพธ์

INFO:tensorflow:Calling model_fn.
WARNING:tensorflow:Layer dnn is casting an input tensor from dtype float64 to the layer's dtype of float32...
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Starting evaluation at 2020-09-10T01:40:47Z
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Restoring parameters from /tmp/tmpbhg2uvbr/model.ckpt-5000
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
INFO:tensorflow:Inference Time : 0.21153s
INFO:tensorflow:Finished evaluation at 2020-09-10-01:40:47
INFO:tensorflow:Saving dict for global step 5000: accuracy = 0.96666664, average_loss = 0.42594802, global_step = 5000, loss = 0.42594802
INFO:tensorflow:Saving 'checkpoint_path' summary for global step 5000: /tmp/tmpbhg2uvbr/model.ckpt-5000
Test dataset accuracy is: 0.967

คำอธิบาย

  • หลังเทรนแล้ว ต้องการดูประสิทธิภาพ
  • ไม่ต้องส่งพารามิเตอร์ให้ evaluate
  • input_fn สำหรับ eval ให้แค่ 1 epoch
  • eval_result dictionary มี average_loss, loss, global_step