This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow import keras | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import os | |
import zipfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
history = model.fit(train_generator, epochs=25, steps_per_epoch=10, validation_data = validation_generator, verbose = 1, validation_steps=3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
history = model.fit(train_generator, epochs=25, steps_per_epoch=10, validation_data = validation_generator, verbose = 1, validation_steps=3) | |
tf.keras.layers.Dense(512, activation='relu'), | |
tf.keras.layers.Dense(7, activation='softmax') | |
]) | |
model.summary() | |
model.compile(loss = 'categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = tf.keras.models.Sequential([ | |
tf.keras.layers.Conv2D(64, (3,3), activation='relu', input_shape=(227, 227, 3)), | |
tf.keras.layers.MaxPooling2D(2, 2), | |
tf.keras.layers.Conv2D(64, (3,3), activation='relu'), | |
tf.keras.layers.MaxPooling2D(2,2), | |
tf.keras.layers.Conv2D(128, (3,3), activation='relu'), | |
tf.keras.layers.MaxPooling2D(2,2), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## CNN 다중 분류 이미지 sample test | |
import keras_preprocessing | |
from keras_preprocessing import image | |
from keras_preprocessing.image import ImageDataGenerator | |
training_datagen = ImageDataGenerator( | |
rescale = 1./255, | |
rotation_range=40, | |
width_shift_range=0.2, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## CNN 다중 분류 이미지 sample test | |
import keras_preprocessing | |
from keras_preprocessing import image | |
from keras_preprocessing.image import ImageDataGenerator | |
training_datagen = ImageDataGenerator( | |
rescale = 1./255, | |
rotation_range=40, | |
width_shift_range=0.2, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# validation image show | |
for i, img_path in enumerate(val_file[:16]): | |
sp = plt.subplot(nrows, ncols, i + 1) | |
sp.axis('Off') | |
img = mpimg.imread(validation_dir + img_path) | |
plt.imshow(img) | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
import matplotlib.image as mpimg | |
# 이미지를 matplotlib를 사용해서 4 * 4 형태의 격자로 출력 예정 | |
nrows = 4 | |
ncols = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig = plt.gcf() | |
fig.set_size_inches(ncols * 4, nrows * 4) | |
for folder_name in os.listdir(train_dir): | |
for i, img_path in enumerate(train_file[folder_name][:4]): | |
sp = plt.subplot(nrows, ncols, i + 1) | |
sp.axis('Off') | |
img = mpimg.imread(train_dir + folder_name + "/" + img_path) | |
plt.imshow(img) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# train/test 경로에 따른 이미지 파일 확인 | |
# training image 폴더명 : 파일명 형태로 정리 | |
train_file = {} | |
val_file = os.listdir(validation_dir) | |
for folder in os.listdir(train_dir): | |
train_file[folder] = os.listdir(train_dir + folder) | |
print(len(os.listdir(validation_dir))) | |
print(os.listdir(train_dir)) |