Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python을 사용하여 꽃 데이터 세트를 시각화하는 데 Tensorflow를 어떻게 사용할 수 있습니까?

<시간/>

꽃 데이터 세트는 'matplotlib' 라이브러리의 도움으로 시각화할 수 있습니다. 'imshow' 메서드는 콘솔에 이미지를 표시하는 데 사용됩니다. 전체 데이터 세트가 반복되고 처음 몇 개의 이미지만 표시됩니다.

자세히 알아보기: TensorFlow란 무엇이며 Keras가 TensorFlow와 함께 신경망을 생성하는 방법은 무엇입니까?

수천 개의 꽃 이미지가 포함된 꽃 데이터 세트를 사용할 것입니다. 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,)

Python을 사용하여 꽃 데이터 세트를 시각화하는 데 Tensorflow를 어떻게 사용할 수 있습니까?

설명

  • 꽃 데이터세트는 matplotlib 라이브러리를 사용하여 시각화됩니다.
  • 처음 6개의 이미지가 반복되어 콘솔에 표시됩니다.
  • 다시 데이터 세트가 반복되고 이미지의 크기가 콘솔에 표시됩니다.