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

การดึงฟีเจอร์ (Feature Extraction) ด้วยโมเดล Pre-trained ใน TensorFlow


แนวคิด

ใช้ Feature Extractor model ที่กำหนดไว้ผ่าน hub.KerasLayer เพื่อดึงฟีเจอร์จากภาพ

แนวคิด Transfer Learning, TensorFlow Hub, Google Colab เหมือนเดิม

ตัวอย่างโค้ด

print("Extracting features")
feature_extractor_model = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4"
feature_extractor_layer = hub.KerasLayer(
    feature_extractor_model, input_shape=(224, 224, 3), trainable=False)
feature_batch = feature_extractor_layer(image_batch)
print(feature_batch.shape)

Credit: TensorFlow Tutorials

ผลลัพธ์

Extracting features
(32, 1280)

คำอธิบาย

  • ดึงฟีเจอร์จากภาพด้วย feature_extractor_layer
  • แสดงมิติของฟีเจอร์ที่ได้ (batch 32, feature vector 1280)