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

Common Debugging Workflow เมื่อสร้างโมเดลด้วย Keras ใน Python

TensorFlow: ML Framework Google Open-source Optimization คณิตศาสตร์ซับซ้อน ใช้ NumPy, Multi-dimensional arrays (Tensors) ติดตั้ง pip install tensorflow

Keras (ภาษากรีก: "Horn") จาก ONEIROS รันบน TensorFlow Scalable, Cross-platform (TPU, GPU, Web, Mobile) เข้าถึงด้วย from tensorflow import keras

ตัวอย่าง: Incremental Stacking + Summary

print("Creating a sequential model")
model = keras.Sequential()

print("Adding layers to it")
model.add(keras.Input(shape=(250, 250, 3)))  # 250x250 RGB images
model.add(layers.Conv2D(32, 5, strides=2, activation="relu"))
model.add(layers.Conv2D(32, 3, activation="relu"))
model.add(layers.MaxPooling2D(3))

print("Data about the layers in the model")
model.summary()

print("Adding more layers to the model")
model.add(layers.Conv2D(32, 3, activation="relu"))
model.add(layers.Conv2D(32, 3, activation="relu"))
model.add(layers.MaxPooling2D(3))
model.add(layers.Conv2D(32, 3, activation="relu"))
model.add(layers.Conv2D(32, 3, activation="relu"))
model.add(layers.MaxPooling2D(2))

print("Data about the layers in the model")
model.summary()

print("Applying global max pooling")
model.add(layers.GlobalMaxPooling2D())

print("Adding a classification layer to the model")
model.add(layers.Dense(10))

Code credit: TensorFlow Keras Sequential Model Guide

ผลลัพธ์

Common Debugging Workflow เมื่อสร้างโมเดลด้วย Keras ใน Python

คำอธิบาย (Debugging Workflow)

  • สร้าง Sequential Architecture แบบ Incremental: เพิ่มเลเยอร์ทีละชั้นด้วย add()
  • พิมพ์ summary() บ่อยครั้ง เพื่อตรวจสอบ Shape และ Parameters
  • Monitor ว่า Conv2D และ MaxPooling2D Down-sample Feature Maps อย่างไร
  • ช่วย잡 Bug Shape Mismatch ได้ตั้งแต่ต้น