Pretrained CNN - VGG16, InceptionV3

2024. 10. 24. 16:02·KT AIVLE School/시각지능 딥러닝

 

- 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
'KT AIVLE School/시각지능 딥러닝' 카테고리의 다른 글
  • YOLO
  • Object Detection (객체 탐지)
  • 100중 분류
  • Transfer Learning
Rabet
Rabet
  • 블로그 메뉴

    • 관리자
    • 글쓰기
  • Rabet
    卯
    Rabet
  • 전체
    오늘
    어제
    • Root (139)
      • KT AIVLE School (85)
        • Start (4)
        • Python프로그래밍 & 라이브러리 (6)
        • 데이터 처리 및 분석 (7)
        • 데이터 분석 및 의미 찾기 (7)
        • 웹크롤링 (10)
        • 머신러닝 (10)
        • 딥러닝 (6)
        • 시각지능 딥러닝 (10)
        • 언어지능 딥러닝 (6)
        • JAVA (4)
        • SQL (2)
        • 가상화 클라우드 (5)
        • 프로젝트 (8)
      • QA (2)
        • 오류사항 (1)
      • 웹공부 (14)
        • SPRING (11)
        • React (1)
      • 코딩 알고리즘 스터디 (23)
      • 코딩테스트 (9)
        • JAVA (8)
        • HTML (1)
      • CS공부 (3)
      • 자격증공부 (3)
        • 정보처리기사 (1)
        • 컴퓨터활용능력 1급 (1)
        • AICE Associate (1)
        • CSTS (0)
  • 인기 글

  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.2
Rabet
Pretrained CNN - VGG16, InceptionV3
상단으로

티스토리툴바