TensorFlow: ML Framework Google Open-source Optimization คณิตศาสตร์ซับซ้อน Tensor = Multi-dimensional array (Rank, Type, Shape) ติดตั้ง pip install tensorflow
Keras: Deep Learning API Python จาก ONEIROS รันบน TensorFlow Scalable, Cross-platform (TPU, GPU, Web, Mobile) เข้าถึงด้วย from tensorflow import keras
ตัวอย่าง: Feature Extraction จากทุกเลเยอร์
print("Sequential model created")
initial_model = keras.Sequential(
[
keras.Input(shape=(250, 250, 3)),
layers.Conv2D(32, 5, strides=2, activation="relu"),
layers.Conv2D(32, 3, activation="relu"),
layers.Conv2D(32, 3, activation="relu"),
]
)
print("Feature extraction from the model")
feature_extractor = keras.Model(
inputs=initial_model.inputs,
outputs=[layer.output for layer in initial_model.layers],
)
print("The feature extractor method is called on test data")
x = tf.ones((1, 250, 250, 3))
features = feature_extractor(x)
Code credit: TensorFlow Keras Sequential Model Guide
ผลลัพธ์
Sequential modal created Feature extraction form the model The feature extractor method is called on test data
คำอธิบาย
- สร้าง Architecture → Train → Evaluate → Save/Restore
- ใช้ Multiple GPUs เร่งการเทรน
- Sequential Model พัฒนาแล้วพฤติกรรมเหมือน Functional API Model
- ทุกเลเยอร์มี Input/Output → ดึง Features จากทุกเลเยอร์ได้ด้วย List Comprehension