VGG모델을 활용하여 이미지를 분류해 내는 것을 목표로 해보겠습니다.
https://saint-swithins-day.tistory.com/60
[TF/Keras] Ubuntu 18.04 가상환경에서 TensorFlow 설치하고 Keras 신경망 라이브러리 환경 설정하기
텐서플로우라는 단어를 들어보셨나요? 인공지능을 다루게 된다면 텐서플로우라는 툴은 쉽게 접할 수 있었을것이라고 생각합니다. 텐서플로우는 수학 및 기계학습 라이브러리 입니다. 구글 브��
saint-swithins-day.tistory.com
[TF/Keras] Keras의 VGG16 모델을 이용하여 이미지 분류하기
Image Classification using VGG16 model in Keras
1. 전체 코드
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.applications.vgg16 import preprocess_input
from keras.applications.vgg16 import decode_predictions
from keras.applications.vgg16 import VGG16
model = VGG16()
image = load_img('img.jpeg', target_size=(224, 224))
image = img_to_array(image)
image = image.reshape(1, image.shape[0], image.shape[1], image.shape[2])
image = preprocess_input(image)
yhat = model.predict(image)
label = decode_predictions(yhat)
label = label[0][0]
print('%s (%.2f%%)'%(label[1], label[2]*100))
2. 코드 분석
관련 라이브러리들을 추가해줍니다.
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.applications.vgg16 import preprocess_input
from keras.applications.vgg16 import decode_predictions
from keras.applications.vgg16 import VGG16
VGG16이라는 케라스에서 지원해준 네트워크 모델을 가져와서 model이라는 이름으로 저장합니다.
model = VGG16()
아무 이미지나 같은 폴더에 넣어줍니다. (필자의 경우 골든 소나타를 넣어주었음)
image = load_img('img.jpeg', target_size=(224, 224))
이미지의 전처리 과정을 거칩니다.
image = img_to_array(image)
image = image.reshape(1, image.shape[0], image.shape[1], image.shape[2])
image = preprocess_input(image)
이미지를 모델에 넣어줍니다.
image = preprocess_input(image)
yhat라는 변수에 예측결과를 넣어줍니다. 이후 출력합니다.
yhat = model.predict(image)
label = decode_predictions(yhat)
label = label[0][0]
print('%s (%.2f%%)'%(label[1], label[2]*100))
3. 결과
현대의 소나타가 스포츠카라고 인식이 된 것을 보면, 현대차가 굉장히 디자인을 잘했다고 평가할 수 있겠네요!
혹은 분류기가 문제가 있거나.... :)
다음에는 직접 학습 데이터를 구성하여 분류기를 만들어 보도록 하겠습니다. 감사합니다.
<참고문헌>
https://blog.naver.com/bananacco/221945844124
CNN 코드 실습 ① - Image Classification
CNN을 활용한 이미지 분류 문제를 Keras 코드로 어떻게 구현해보는지 포스팅하겠습니다.Keras work ...
blog.naver.com
https://blog.naver.com/jape908/221852375873
VGG16을 활용한 Intel Image Classification
안녕하세요 이번 글에서는 딥러닝 분야의 Image Classification을 진행해 보려고 합니다.데이터는 kaggle...
blog.naver.com
https://antilibrary.org/1975?category=690004
CNN, 케라스, 텐서플로우 벡엔드를 이용한 이미지 인식 분류기 만들기 Create your first Image Recognition
Create your first Image Recognition Classifier using CNN, Keras and Tensorflow backend Getting Started — Dog or Cat 본 튜토리얼에서 일단 주어진 이미지가 개인지 고양이인지 구분하는 이미지 분류기를..
antilibrary.org
'Autonomous Vehicle > Computer Vision' 카테고리의 다른 글
OpenCV : Euclidean Clustering White Pixels Algorithm (0) | 2020.08.26 |
---|---|
[TF/Keras] Ubuntu 18.04 가상환경에서 TensorFlow 설치하고 Keras 신경망 라이브러리 환경 설정하기 (0) | 2020.08.22 |
Windows 10 환경에서 Visual Studio 에디터의 C++ OpenCV 설치 (4) | 2020.08.12 |