728x90
반응형
성능향상
vggnet 방식 : 깊은 신경망 사용
이미지 제너레이터 : 하나의 이미지를 변형하여 사용, 증식 // 수집데이터가 적은 경우 성능향상에 좋음
from tensorflow.keras.preprocessing.image import load_img, img_to_array, ImageDataGenerator
import matplotlib.pyplot as plt
import numpy as np
train_datagen = ImageDataGenerator(horizontal_flip= True, # 수평방향뒤집기
vertical_flip = True, # 수직방향뒤집기
shear_range = 0.5, # 시계반대방향 이미지 밀기, 0.5 정도
brightness_range = [0.5, 1.0], # 이미지 밝기
zoom_range =0.2, # 이미지 확대/축소
width_shift_range = 0.1, # 가로방향 이동
height_shift_range = 0.1, # 세로방향 이동
rotation_range = 30, # 이미지 회전
fill_mode = 'nearest') # 이미지 변환시 픽셀 채울수 있는 방법
import tensorflow as tf
image_path = tf.keras.utils.get_file('cat.jpg', 'http://bit.ly/33U6mH9')
image = plt.imread(image_path)
plt.imshow(image)
# 제네레이터 이미지 변환
image = image.reshape((1,) + image.shape)
train_generator = train_datagen.flow(image, batch_size = 1) # 한개씩 꺼내줌
fig = plt.figure(figsize=(5,5))
fig.suptitle('augmented image')
for i in range(9) :
data = next(train_generator)
image = data[0]
plt.subplot(3,3,i+1)
plt.xticks([])
plt.yticks([])
plt.imshow(np.array(image, dtype = np.uint8), cmap='gray')
plt.show()
반응형
'Data_Science > Data_Analysis_Py' 카테고리의 다른 글
52. ImageDataGenerator || 이미지 조회 (0) | 2021.12.07 |
---|---|
51. cifar10 || imageDataGenerator (0) | 2021.12.07 |
49. cifar10 || convolution (0) | 2021.11.26 |
48. Fashion MNIST || convolution (0) | 2021.11.26 |
47. Cat image, convolution 설명 (0) | 2021.11.25 |