Keras: Deep Learning API Python ระดับสูง จากโครงการ ONEIROS รันบน TensorFlow Scalable, Cross-platform (TPU, GPU, Web, Mobile) เข้าถึงด้วย from tensorflow import keras
Functional API
ยืดหยุ่นกว่า Sequential API รองรับ Non-linear topology, Shared layers, Multiple I/O สร้าง DAG ของเลเยอร์
ตัวอย่าง: คอมไพล์โมเดลด้วย Loss และ Weights แบบหลาย Outputs
print("Model is being compiled")
model.compile(
optimizer=keras.optimizers.RMSprop(1e-3),
loss={
"priority": keras.losses.BinaryCrossentropy(from_logits=True),
"department": keras.losses.CategoricalCrossentropy(from_logits=True),
},
loss_weights=[1.0, 0.2],
)
Code credit: TensorFlow Keras Functional Guide
ผลลัพธ์
Model is being compiled
คำอธิบาย
- ใช้เมธอด
compile()คอมไพล์โมเดล - กำหนด Loss แบบต่างกันสำหรับแต่ละ Output (Dictionary)
- กำหนด Loss Weights แบบต่างกัน เพื่อควบคุม Total Training Loss