- VGG16
# VGG에서 가장 가벼운 모델 VGG16
from keras.applications.vgg16 import VGG16, preprocess_input, decode_predictions
import numpy as np
import matplotlib.pyplot as plt
vgg_model = VGG16(include_top=True, # VGG16 모델의 아웃풋 레이어까지 전부 불러오기
weights='imagenet', # ImageNet 데이터를 기반으로 학습된 가중치 불러오기
input_shape=(224,224,3) # 모델에 들어가는 데이터의 형태
)
# 연결
from google.colab import drive
drive.mount('/content/drive')
데이터 불러오기
import glob
from keras.preprocessing import image
files = glob.glob('/content/drive/MyDrive/파일이름/*')
images = []
for path in files :
img = image.load_img(path, color_mode='rgb', target_size=(224,224) ) # load되는 데이터 크기
# img = img.resize((224,224)) # model데이터 크기
img = image.img_to_array(img)
img = preprocess_input(img) # 이미지 전처리 진행
images.append(img)
images = np.array(images)
features = vgg_model.predict(images)
predictions = decode_predictions(features, top=3) # 예측 레이블로 변환
for i in range(images.shape[0]) :
print(predictions[i])
plt.imshow(image.load_img(files[i]))
plt.show()
notebook은 맞췄지만 사과는 석류로 착각하는 모습이 보였다.
- InceptionV3
keras.backend.clear_session()
base_model = InceptionV3(weights='imagenet', # ImageNet 데이터를 기반으로 미리 학습된 가중치 불러오기
include_top=False, # InceptionV3 모델의 아웃풋 레이어는 제외하고 불러오기
input_shape= (299,299,3)) # 입력 데이터의 형태
new_output = GlobalAveragePooling2D()(base_model.output)
new_output = Dense(3, # class 3개 아웃풋 레이어 설정
activation = 'softmax')(new_output)
model = keras.models.Model(base_model.inputs, new_output)
model.summary()
for idx, layer in enumerate(model.layers) :
if idx < 213 :
layer.trainable = False
else :
layer.trainable = True
'KT AIVLE School > 시각지능 딥러닝' 카테고리의 다른 글
YOLO (0) | 2024.10.25 |
---|---|
Object Detection (객체 탐지) (0) | 2024.10.25 |
100중 분류 (1) | 2024.10.24 |
Transfer Learning (3) | 2024.10.23 |
Image Precessing & Augmentation - notMNIST (0) | 2024.10.23 |