แนวคิด
ใช้ train method เทรนโมเดล
ใช้ Keras Sequential API, CNN, TensorFlow Text, Google Colab, Estimator, Iris dataset เหมือนเดิม
ตัวอย่างโค้ด
print("The model is being trained")
classifier.train(input_fn=lambda: input_fn(train, train_y, training=True), steps=5000)
Credit: TensorFlow Tutorials
ผลลัพธ์ (บางส่วน)
WARNING:tensorflow:From ... Variable.initialized_value ... deprecated ... INFO:tensorflow:Calling model_fn. WARNING:tensorflow:Layer dnn is casting an input tensor from dtype float64 to float32... INFO:tensorflow:Done calling model_fn. INFO:tensorflow:Create CheckpointSaverHook. INFO:tensorflow:Graph was finalized. INFO:tensorflow:Running local_init_op. INFO:tensorflow:Done running local_init_op. INFO:tensorflow:Calling checkpoint listeners before saving checkpoint 0... INFO:tensorflow:Saving checkpoints for 0 into /tmp/tmpbhg2uvbr/model.ckpt. INFO:tensorflow:loss = 1.1140382, step = 0 INFO:tensorflow:global_step/sec: 312.415 INFO:tensorflow:loss = 0.8781501, step = 100 (0.321 sec) ... (loss ลดลงเรื่อยๆ จน step 5000) INFO:tensorflow:Loss for final step: 0.36297452. <tensorflow_estimator.python.estimator.canned.dnn.DNNClassifierV2 at 0x7fc9983ed470>
คำอธิบาย
- สร้าง Estimator object แล้วเรียกเมธอดต่างๆ
- เทรนโมเดล
- ประเมินโมเดลที่เทรนแล้ว
- ใช้ทำนาย
- เทรนซ้ำได้โดยเรียก
Estimator.trainอีกครั้ง