주뇽's 저장소
NVIDIA 딥러닝 기초 9. 이미지개선 본문
728x90
반응형
from tensorflow import keras
base_model = keras.applications.VGG16(
weights='imagenet',
input_shape=(224, 224, 3),
include_top= False)
# Freeze base model
base_model.trainable = False
# Create inputs with correct shape
inputs = keras.Input(shape=(224, 224, 3))
x = base_model(inputs, training=False)
# Add pooling layer or flatten layer
x = keras.layers.GlobalAveragePooling2D()(x)
# Add final dense layer
outputs = keras.layers.Dense(1, activation = 'softmax')(x)
# Combine inputs and outputs to create model
model = keras.Model(inputs, outputs)
model.compile(loss='categorical_crossentropy', metrics=['accuracy'])
from tensorflow.keras.preprocessing.image import ImageDataGenerator
# create a data generator
datagen = ImageDataGenerator(
samplewise_center=True, # set each sample mean to 0
rotation_range=10, # randomly rotate images in the range (degrees, 0 to 180)
zoom_range = 0.1, # Randomly zoom image
width_shift_range=0.1, # randomly shift images horizontally (fraction of total width)
height_shift_range=0.1, # randomly shift images vertically (fraction of total height)
horizontal_flip=True, # randomly flip images
vertical_flip=False) # we don't expect Bo to be upside-down so we will not flip vertically
# load and iterate training dataset
train_it = datagen.flow_from_directory('data/fruits/train/',
target_size=(224, 224),
color_mode='rgb',
class_mode="categorical")
# load and iterate validation dataset
valid_it = datagen.flow_from_directory('data/fruits/valid/',
target_size=(224, 224),
color_mode='rgb',
class_mode="categorical")
model.fit(train_it,
validation_data=valid_it,
steps_per_epoch=train_it.samples/train_it.batch_size,
validation_steps=valid_it.samples/valid_it.batch_size,
epochs=10)
'DeepLearning' 카테고리의 다른 글
[Google Colab] 구글 드라이브 공유 파일 코랩에서 읽기(gdown) (0) | 2023.12.02 |
---|---|
NVIDIA 딥러닝 기초 8.시퀀스 데이터 (1) | 2023.07.02 |
NVIDIA 딥러닝 기초 7.전이학습 (0) | 2023.07.02 |