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

Tensorflow를 사용하여 성능을 위해 꽃 데이터 세트를 구성하는 방법은 무엇입니까?

<시간/>

꽃 데이터 세트는 모델이 생성될 때 특정 비율의 정확도를 제공했을 것입니다. 성능을 위해 모델을 구성해야 하는 경우 두 번째로 버퍼 프리페치를 수행한 다음 셔플하는 함수를 정의합니다. 이 함수는 모델의 성능을 향상시키기 위해 훈련 데이터 세트에서 호출됩니다.

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

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

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

print("A function is defined that configures the dataset for perfromance")
def configure_for_performance(ds):
   ds = ds.cache()
   ds = ds.shuffle(buffer_size=1000)
   ds = ds.batch(batch_size)
   ds = ds.prefetch(buffer_size=AUTOTUNE)
   return ds

print("The function is called on training dataset")
train_ds = configure_for_performance(train_ds)
print("The function is called on validation dataset")
val_ds = configure_for_performance(val_ds)

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

출력

A function is defined that configures the dataset for perfromance
The function is called on training dataset
The function is called on validation dataset

설명

  • 모델은 데이터세트로 학습해야 합니다.
  • 모델을 먼저 잘 섞은 다음 일괄 처리한 다음 이러한 일괄 처리를 사용할 수 있게 됩니다.
  • 이러한 기능은 'tf.data' API를 사용하여 추가됩니다.