Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách trực quan hóa tập flower dataset với TensorFlow và Python

Trực quan hóa flower dataset nhờ thư viện matplotlib. Dùng imshow() hiển thị ảnh. Lặp qua dataset, chỉ hiện vài ảnh đầu.

Mã ví dụ

import matplotlib.pyplot as plt
print("Trực quan hóa 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("Lặp qua dataset")
print("Lấy batch ảnh")
for image_batch, labels_batch in train_ds:
    print(image_batch.shape)
    print(labels_batch.shape)
    break

Nguồn mã: TensorFlow Images Tutorial

Đầu ra

Trực quan hóa flower dataset
Lặp qua dataset
Lấy batch ảnh
(32, 180, 180, 3)
(32,)

Cách trực quan hóa tập flower dataset với TensorFlow và Python

Giải thích

  • Dùng matplotlib vẽ flower dataset.
  • Lặp 6 ảnh đầu, hiển thị với tiêu đề tên lớp.
  • Lặp lại dataset, in shape batch: (32, 180, 180, 3) và nhãn (32,).