Python/Deep Learning

[CNN] VGGNet 알고리즘

유달잇 2021. 6. 6. 23:16
728x90

 

VGGNet에 대해 알아보자.


 

1. VGGNet 이란?


2014년 세계 이미지 분류 대회(ImageNet Large Scale Visual Recognition Challenge)에서 준우승한 CNN 모델이다. 

간단한 구조로 좋은 성능을 내는 모델로 많이 응용되어 쓰이고 있다.

 

 

2. VGGNet 구성


총 6가지 구성의 VGGNet 모델이 있다. 그중 VGG16(D)과 VGG19(E)를 주로 사용한다.

VGGNet 모델에서는 3x3 필터를 사용하여 연산시 발생하는 파라미터의 개수가 줄어드는 효과를 볼 수 있다.

이로 인해 속도가 빨라지고 ReLU 함수가 들어갈 수 있는 곳이 많아진다는 장점이 있다.

 

 

3. VGG16 Architecture


 

 

 

4. VGG16 구현


  
  import tensorflow as tf
  from tensorflow.keras.applications import VGG16
  
  model = VGG16()
  
  model.summary()
   

>> 결과

Tensor flow, Keras, Pytorch를 라이브러리를 통해 쉽게 불러올 수 있으며
위는 tensorflow 라이브러리를 사용하여 VGG16 모델을 불러왔다.

 

 

5. VGG16모델 사용해보기


  
  import cv2
  from tensorflow.keras.applications import VGG16
  from tensorflow.python.keras.preprocessing.image import img_to_array
  from tensorflow.python.keras.applications.vgg16 import preprocess_input, decode_predictions

  # VGG16 모델 
  model = VGG16()

  # 이미지 불러오기 
  image = cv2.imread("/gdrive/My Drive/Colab Notebooks/dog.jpg")

  # 이미지 전처리(자료형 변경)
  image = img_to_array(image)
  image = image.reshape((1, image.shape[0],image.shape[1],image.shape[2]))

  # 모델에 넣어준다.
  image = preprocess_input(image)  
  print(image.shape)

  # 예측(predict)
  res = model.predict(image)
  # 디코딩
  label = decode_predictions(res)
  print(label)
  label = label[0][0]

  # 출력
  print()
  print("%s (%.2f%%)" % (label[1], label[2]*100))
  print()
  for i in label:
    print(i)

  

>> 사용한 이미지

>> 결과


이미지 크기는 224 X 224로 따로 resize 전처리를 해주지 않았다.

만약 224 X 224크기가 아니라면 resize 전처리가 필요하다.

VGG16 모델 사용 결과 개 사진을 넣었는데 개의 종류인 포메라니안을 예측하는 것을 볼 수 있다.

추후에는 VGG16 모델을 전이학습을 통해 응용을 해 볼 것이다.

 

 

 

출처 : VGGNet 논문

 

 

728x90
댓글
250x250
최근에 올라온 글
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Total
Today
Yesterday