ชุดข้อมูลดอกไม้สามารถมองเห็นได้ด้วยความช่วยเหลือของไลบรารี 'matplotlib' วิธี 'imshow' ใช้เพื่อแสดงภาพบนคอนโซล ชุดข้อมูลทั้งหมดถูกทำซ้ำ และจะแสดงเพียงภาพแรกเท่านั้น
อ่านเพิ่มเติม: TensorFlow คืออะไรและ Keras ทำงานร่วมกับ TensorFlow เพื่อสร้าง Neural Networks อย่างไร
เราจะใช้ชุดข้อมูลดอกไม้ซึ่งมีรูปภาพดอกไม้หลายพันดอก ประกอบด้วยไดเร็กทอรีย่อย 5 ไดเร็กทอรี และมีไดเร็กทอรีย่อยหนึ่งไดเร็กทอรีสำหรับทุกคลาส
เรากำลังใช้ Google Colaboratory เพื่อเรียกใช้โค้ดด้านล่าง Google Colab หรือ Colaboratory ช่วยเรียกใช้โค้ด Python บนเบราว์เซอร์และไม่ต้องมีการกำหนดค่าใดๆ และเข้าถึง GPU ได้ฟรี (หน่วยประมวลผลกราฟิก) Colaboratory ถูกสร้างขึ้นบน Jupyter Notebook
import matplotlib.pyplot as plt
print("Visualizing the flower dataset")
plt.figure(figsize=(10, 10))
for images, labels in train_ds.take(1):
for i in range(6):
ax = plt.subplot(3, 3, i + 1)
plt.imshow(images[i].numpy().astype("uint8"))
plt.title(class_names[labels[i]])
plt.axis("off")
print("Iterating over dataset")
print("Retrieving batches of images")
for image_batch, labels_batch in train_ds:
print(image_batch.shape)
print(labels_batch.shape)
break เครดิตโค้ด:https://www.tensorflow.org/tutorials/load_data/images
ผลลัพธ์
Visualizing the flower dataset Iterating over dataset Retrieving batches of images (32, 180, 180, 3) (32,)

คำอธิบาย
- ชุดข้อมูลดอกไม้แสดงภาพโดยใช้ไลบรารี matplotlib
- รูปภาพ 6 รูปแรกถูกทำซ้ำและแสดงบนคอนโซล
- อีกครั้ง ชุดข้อมูลถูกทำซ้ำ และขนาดของรูปภาพจะแสดงบนคอนโซล