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

การฝึกโมเดล Fashion MNIST ด้วย TensorFlow


บทนำ

TensorFlow เฟรมเวิร์ก ML จาก Google โค้ดเปิด ใช้กับ Python ใช้ในงานวิจัยและการผลิต

การติดตั้ง

pip install tensorflow

Tensor และชุดข้อมูล Fashion MNIST

เทนเซอร์ = อาร์เรย์หลายมิติ สำหรับ Data flow graph Fashion MNIST: ภาพเสื้อผ้า 70,000+ ภาพ 10 หมวดหมู่ 28x28 pixels

ตัวอย่าง: การ Fit และ Evaluate โมเดล

print("กำลัง Fit โมเดลกับข้อมูล")
model.fit(train_images, train_labels, epochs=15)

print("กำลังคำนวณความแม่นยำ")
test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)
print('\nTest accuracy:', test_acc)

ที่มาโค้ด: TensorFlow Classification Tutorial

ผลลัพธ์

กำลัง Fit โมเดลกับข้อมูล
Epoch 1/15 - loss: 0.6337 - accuracy: 0.7799
Epoch 2/15 - loss: 0.3806 - accuracy: 0.8622
...
Epoch 15/15 - loss: 0.2057 - accuracy: 0.9224
กำลังคำนวณความแม่นยำ
Test accuracy: 0.8805999755859375

คำอธิบาย

  • ฝึกโมเดลด้วย model.fit ใส่ train_images, train_labels, epochs=15
  • โมเดลเรียนรู้ mapping ภาพ -> ป้ายกำกับ
  • test_images เก็บข้อมูลทดสอบ
  • เปรียบเทียบการทำนายกับป้ายกำกับจริงใน test set
  • model.evaluate ให้ accuracy และ loss บนข้อมูลทดสอบ