반응형
numpy array로 되어있는 데이터를 증강하는 방법
# 데이터 불러오기
(X_train, y_train), (X_test, y_test) = cifar10.load_data()
# 피처스케일링
X_train = X_train / 255.0
X_test = X_test / 255.0
y_train = to_categorical( y_train, 10)
y_test = to_categorical( y_test, 10 )
# 모델링 (모델링 함수 적용)
model = build_model()
# 컴파일
model.compile('rmsprop', 'categorical_crossentropy', ['accuracy'])
# 데이터를 증강해서 학습시킬것이다. 넘파이 어레이로 되어있는 데이터를 증강하는 방법
# 라이브러리 임포트
from tensorflow.keras.preprocessing.image import ImageDataGenerator
# 학습에 사용할 넘파이 어레이를 위에서 이미 피쳐스케일링 했으므로, rescale 파라미터는 필요없다.
train_datagen = ImageDataGenerator(rotation_range = 15, width_shift_range = 0.1, height_shift_range = 0.1, shear_range = 0.2, zoom_range = 0.2, horizontal_flip = True)
# flow_from_directory가 아닌 flow까지만 적용하고, X_train과, y_train를 적용한다.
train_generator = train_datagen.flow( X_train, y_train )
반응형
'Deep Learning > Tensorflow' 카테고리의 다른 글
| Tensorflow - Fine Tuning (0) | 2022.06.16 |
|---|---|
| Tensorflow - Transfer Learning (0) | 2022.06.16 |
| Tensorflow - 파일을 Traning과 Test 디렉토리로 나눠서 저장하는 방법 (0) | 2022.06.15 |
| Tensorflow - ImageDataGenerator를 이용해서 데이터 증강하는 법 (0) | 2022.06.15 |
| Tensorflow - os.mkdir 이용하여, 파일 저장할 다음 디렉토리 만들기 (0) | 2022.06.15 |