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

การสร้าง (Instantiate) Estimator ด้วย TensorFlow และ Python


แนวคิด

สร้าง Estimator ด้วย DNNClassifier ใน tf.estimator

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

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

print("Build a DNN that has 2 hidden layers with 30 and 10 hidden nodes each")
classifier = tf.estimator.DNNClassifier(
    feature_columns=my_feature_columns,
    hidden_units=[30, 10],
    n_classes=3)

Credit: TensorFlow Tutorials

ผลลัพธ์

Build a DNN that has 2 hidden layers with 30 and 10 hidden nodes each
INFO:tensorflow:Using default config.
WARNING:tensorflow:Using temporary folder as model directory: /tmp/tmpdh8866zb
INFO:tensorflow:Using config: {...}

คำอธิบาย

  • ปัญหา Iris เป็น classification problem
  • TensorFlow มี pre-made classifier Estimators:
    • tf.estimator.DNNClassifier สำหรับโมเดลลึก multi-class
    • tf.estimator.DNNLinearCombinedClassifier wide & deep
    • tf.estimator.LinearClassifier linear models
  • สำหรับ Iris ใช้ tf.estimator.DNNClassifier