Colaboratory에서 사전 학습된 모델을 사용하여 사전 이미지의 레이블을 예측합니다.
최종 노트북

공동체에서 노트북 만들기
공동체,
ファイル
> Python 3 の新しいノートブック
에서 새로운 노트북을 만듭니다.
編集
> ノートブックの設定
을 선택하면 다음과 같은 팝업이 표시되므로
ハードウェア アクセラレート
의 드롭다운 메뉴에서 GPU
를 선택합니다.
사전 학습된 모델 로드
Tensorflow 버전 설정
!pip list | grep tensorflow
위를 실행하면 버전이
1.15.0
임을 알 수 있습니다.
!pip install -U tensorflow
위를 실행하면 다음과 같은 오류가 발생하지만 이번 범위 내에서 문제가 없었습니다.

다시
pip list
버전을 확인해 봅시다.
ResNet 로드
단지 이것뿐입니다.
import tensorflow as tf
resnet = tf.keras.applications.ResNet50V2(include_top=True, weights="imagenet")
입력 및 출력 형식을 확인합니다.
입력 이미지가
224x224
임을 알 수 있습니다.resnet.input_shape
resnet.output_shape

입력에 사용할 자화상을 업로드하고 가져오기
왼쪽 창의
ファイル
에서 이미지를 업로드합니다.여기서
dog.jpg
라는 이름입니다.그런 다음 이미지를 읽고 ResNet 입력을 위해 변형합니다.
import numpy as np
from PIL import Image
img = Image.open("dog.jpg")
input = np.array(img.convert("RGB").resize((224, 224)))
input.shape

라벨 예측
전처리를 할 필요가 있는 것 같습니다.
入力した画像の数xラベル数
로 표시됩니다.preprocessed = tf.keras.applications.resnet_v2.preprocess_input(np.array([input]))
output = resnet.predict(preprocessed)
output.shape

결과를 디코딩합니다.
result = tf.keras.applications.resnet_v2.decode_predictions(output, top=10)[0]
result

teddy
가 톱에서 예측되고 있습니다. toy_poodle
가 성공적으로 예측되었습니다. shopping_cart
가 예상됩니까? pick
모르겠지만, 픽과 함께 기타의 현이 찍혀있는 이미지가 많은 것 같기 때문에, 장바구니와 같은 이유입니까? 입력 화상과 비교하면, 대체로 납득할 수 있는 결과였습니다.

Reference
이 문제에 관하여(Colaboratory에서 사전 학습된 모델을 사용하여 사전 이미지의 레이블을 예측합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/sosuke/items/3334309cf9bfea9dcd1c텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)