TensorFlow: ML Framework Google Open-source Research/Production
Keras (ภาษากรีก: "Horn") จาก ONEIROS Deep Learning API Python ระดับสูง รันบน TensorFlow Scalable, Cross-platform (TPU, GPU, Web, Mobile) เข้าถึงด้วย from tensorflow import keras
ตัวอย่าง: Transfer Learning กับ Xception
print("A convolutional model with pre-trained weights is loaded")
base_model = keras.applications.Xception(
weights='imagenet',
include_top=False,
pooling='avg'
)
print("This model is freezed")
base_model.trainable = False
print("A sequential model is used to add a trainable classifier on top of the base")
model = keras.Sequential([
base_model,
layers.Dense(1000),
])
print("Compile the model")
print("Fit the model to the test data")
model.compile(...)
model.fit(...)
Code credit: TensorFlow Keras Sequential Model Guide
ผลลัพธ์
A convolutional model with pre-trained weights is loaded Downloading data from https://storage.googleapis.com/tensorflow/kerasapplications/xception/xception_weights_tf_dim_ordering_tf_kernels_notop.h5 83689472/83683744 [==============================] - 1s 0us/step This model is freezed A sequential model is used to add a trainable classifier on top of the base Compile the model Fit the model to the test data
คำอธิบาย
- ใช้ Sequential Model Stack ร่วมกับ Pre-trained Model เพื่อ Initialize Classification Layers
- Freeze Base Model (
trainable = False) - เพิ่ม Classifier (Dense) ด้านบน
- Compile และ Fit กับ Training Data