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

วิธีใช้ Keras คอมไพล์ Sequential Model ที่สร้างแล้วด้วย Python

Keras (ภาษากรีก: "Horn") จากโครงการ ONEIROS Deep Learning API Python ระดับสูง รันบน TensorFlow Scalable, Cross-platform เข้าถึงด้วย from tensorflow import keras

TensorFlow: ML Framework Google Open-source ใช้กับ Python Research และ Production

Functional API

ยืดหยุ่นกว่า Sequential API รองรับ Non-linear topology, Shared layers, Multiple I/O สร้าง DAG ของเลเยอร์

ตัวอย่าง: คอมไพล์ Sequential Model

print("Model is being compiled")
model.compile(
    optimizer=keras.optimizers.RMSprop(1e-3),
    loss=[
        keras.losses.BinaryCrossentropy(from_logits=True),
        keras.losses.CategoricalCrossentropy(from_logits=True),
    ],
    loss_weights=[1.0, 0.2],
)

Code credit: TensorFlow Keras Functional Guide

ผลลัพธ์

Model is being compiled

คำอธิบาย

  • โมเดลที่สร้างแล้ว คอมไพล์ด้วย compile()
  • กำหนด Loss หลายตัว (List) ตรงตามลำดับ Outputs
  • กำหนด Loss Weights ควบคุม Total Training Loss