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

TensorFlow: สำรวจ Flower Dataset ด้วย Keras Sequential API และ PIL

สำรวจข้อมูล flower dataset: นับจำนวนภาพ แสดงภาพตัวอย่างจากแต่ละคลาส

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


image_count = len(list(data_dir.glob('*/*.jpg')))
print("จำนวนภาพใน dataset:", image_count)

print("ตัวอย่างภาพ:")
print("ROSES")
roses = list(data_dir.glob('roses/*'))
PIL.Image.open(str(roses[1]))

print("TULIPS")
tulips = list(data_dir.glob('tulips/*'))
PIL.Image.open(str(tulips[0]))

ผลลัพธ์

จำนวนภาพใน dataset: 3670
ตัวอย่างภาพ:
ROSES
TULIPS

TensorFlow: สำรวจ Flower Dataset ด้วย Keras Sequential API และ PIL TensorFlow: สำรวจ Flower Dataset ด้วย Keras Sequential API และ PIL

คำอธิบาย

  • data_dir.glob('*/*.jpg'): หาไฟล์ .jpg ทุกไฟล์ใน subfolder ทั้งหมด
  • data_dir.glob('roses/*'): หาไฟล์ในโฟลเดอร์ roses
  • PIL.Image.open(): เปิดภาพด้วย Pillow (PIL) แสดงใน notebook
  • ขั้นตอนนี้ทำก่อนสร้าง model เพื่อทำความเข้าใจข้อมูล (EDA)