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

การสร้าง Normalization Layer ด้วย TensorFlow และ Python


แนวคิด

แปลงชื่อคลาสเป็น NumPy array แล้วสร้าง Normalization Layer ด้วย Rescaling จาก tf.keras.layers.experimental.preprocessing

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

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

print("It contains 5 classes")
class_names = np.array(train_ds.class_names)
print(class_names)
print("A normalization layer is built")
normalization_layer = tf.keras.layers.experimental.preprocessing.Rescaling(1./255)
train_ds = train_ds.map(lambda x, y: (normalization_layer(x), y))

Credit: TensorFlow Tutorials

ผลลัพธ์

It contains 5 classes
['daisy' 'dandelion' 'roses' 'sunflowers' 'tulips']
A normalization layer is built

คำอธิบาย

  • TFHub ต้องการ input เป็น float ในช่วง [0, 1]
  • ใช้ Rescaling layer เพื่อปรับค่า
  • Buffered prefetching ช่วยโหลดข้อมูลจากดิสก์โดยไม่บล็อก I/O