본문 바로가기

입력 이미지(input image)를 정규화(normalize)하는 이유

As you may already know, data that goes into neural networks should usually be normalized in some way to make it more amenable to processing by the network. (It is uncommon to feed raw pixels into a convnet.)

 

-> input image를 normalize하면 네트워크가 데이터를 처리하기가 더 쉬워진다고 합니다. 실제로 raw pixel을 그대로 CNN에 넣는 일은 드물다고 하네요. 

 

from tensorflow.keras.preprocessing.image import ImageDataGenerator

# All images will be rescaled by 1./255
train_datagen = ImageDataGenerator(rescale=1/255)

# Flow training images in batches of 128 using train_datagen generator
train_generator = train_datagen.flow_from_directory(
        './horse-or-human/',  # This is the source directory for training images
        target_size=(300, 300),  # All images will be resized to 150x150
        batch_size=128,
        # Since we use binary_crossentropy loss, we need binary labels
        class_mode='binary')

 

이미지 전처리는 4번째 줄에서 확인할 수 있습니다.

 

Pytorch의 경우 torchvision.transforms.ToTensor()를 사용하면 자동으로 1/255를 해줬는데 텐서플로는 ImageGenerator에서 rescale을 해줘야 하네요.

참고


 

GitHub - https-deeplearning-ai/tensorflow-1-public

Contribute to https-deeplearning-ai/tensorflow-1-public development by creating an account on GitHub.

github.com

 

torchvision.transforms — Torchvision 0.11.0 documentation

torchvision.transforms Transforms are common image transformations. They can be chained together using Compose. Most transform classes have a function equivalent: functional transforms give fine-grained control over the transformations. This is useful if y

pytorch.org

 

'TIL' 카테고리의 다른 글

HDFS 휴지통 복구, HDFS 파일 복구, HDFS 폴더 복구  (0) 2022.07.21
Conv1D, Conv2D, Conv3D 차이  (0) 2021.11.22
include_top의 의미  (0) 2021.11.17
ValueError: output array is read-only  (0) 2021.11.08
sigmoid보다 tanh를 쓰는 이유  (0) 2021.08.19