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

Tensorflow를 사용하여 꽃 데이터 세트를 로드하고 작업하려면 어떻게 해야 하나요?

<시간/>

수천 개의 꽃 이미지가 포함된 꽃 데이터 세트를 사용할 것입니다. 5개의 하위 디렉토리를 포함하며 모든 클래스에 대해 하나의 하위 디렉토리가 있습니다.

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

꽃 데이터 세트가 'get_file' 메소드를 사용하여 다운로드되면 작업을 위해 환경에 로드됩니다. 로더 매개변수는 명시적으로 언급되고 로드된 데이터는 훈련 및 검증 세트로 분할됩니다.

Google Colaboratory를 사용하여 아래 코드를 실행하고 있습니다. Google Colab 또는 Colaboratory는 브라우저를 통해 Python 코드를 실행하는 데 도움이 되며 구성이 필요 없고 GPU(그래픽 처리 장치)에 대한 무료 액세스가 필요합니다. Colaboratory는 Jupyter Notebook을 기반으로 구축되었습니다.

print("Loading parameters for the loader")
batch_size = 32
img_height = 180
img_width = 180

print("Preprocessing the image dataset using Keras")
print("Splitting dataset into training and validation set ")

train_ds = tf.keras.preprocessing.image_dataset_from_directory(
   data_dir,
   validation_split=0.2,
   subset="training",
   seed=123,
   image_size=(img_height, img_width),
   batch_size=batch_size)

print("Splitting dataset into training and validation set ")
val_ds = tf.keras.preprocessing.image_dataset_from_directory(
   data_dir,
   validation_split=0.2,
   subset="validation",
   seed=123,
   image_size=(img_height, img_width),
   batch_size=batch_size)

print("Printing the class names present in sub-directories")
class_names = train_ds.class_names
print(class_names)

코드 크레딧:https://www.tensorflow.org/tutorials/load_data/images

출력

Loading parameters for the loader
Preprocessing the image dataset using Keras
Splitting dataset into training and validation set
Found 3670 files belonging to 5 classes.
Using 2936 files for training.
Splitting dataset into training and validation set
Found 3670 files belonging to 5 classes.
Using 734 files for validation.
Printing the class names present in sub-directories
['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']

설명

  • 매개변수가 정의됩니다.
  • 데이터 세트는 학습 세트와 검증 세트로 나뉩니다.
  • 모든 이미지가 분류된 클래스 이름은 콘솔에 표시됩니다.