@37_인공지능 사과와 오렌지 구분하기
1. 구글의 인공지능 티처블머신 tensorflow 활용해서 이미지 학습
2. 학습결과 활용하여 검증용 이미지 구분하기
1. 구글의 인공지능 티처블머신 tensorflow 활용해서 이미지 학습
https://teachablemachine.withgoogle.com/
Teachable Machine
Train a computer to recognize your own images, sounds, & poses. A fast, easy way to create machine learning models for your sites, apps, and more – no expertise or coding required.
teachablemachine.withgoogle.com
- 이미지 학습
- 마스크 쓴 이미지(mask) / 마스크 안 쓴 이미지 (unmask) 두 가지로 학습
- 학습 결과 대체로 잘 나옴
2. 학습한 결과 가져와 코드에 반영
- 이 부분은 코드를 가져다 쓰는 수준임
- 파이썬의 버전과 tensorflow의 버전이 맞아야 한다고 하는데 그냥 했음
- 교재에서는 파이썬(V_3.8.8) 과 tensorflow(V_2.3)을 사용함
- 내 경우 파이썬(V_3.9.7) 과 tensorflow(V_2.9.0)를 사용함
import tensorflow.keras
from PIL import Image, ImageOps
import numpy as np
from glob import glob
# 학습모델과 검증이미지 불러오기
model_path = r'37_AI\converted_keras\keras_model.h5'
labels_path = r'37_AI\converted_keras\labels.txt'
img_list = glob(r'37_AI\samplePic\*.jpg')
img_list.extend(glob(r'37_AI\samplePic\*.png'))
# 학습모델
model = tensorflow.keras.models.load_model(model_path)
data = np.ndarray(shape=(1,224,224,3), dtype=np.float32)
# 검증 이미지 개수만큼 검증
for img_path in img_list:
image = Image.open(img_path)
size = (224,224)
image = ImageOps.fit(image, size, Image.ANTIALIAS)
image_array = np.asarray(image)
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
data[0] = normalized_image_array
prediction = model.predict(data)
print(prediction)
with open(labels_path, 'rt', encoding='UTF8') as f:
readLines = f.readlines()
# 검증 결과 출력
if prediction[0, 0] > prediction[0,1]:
print(img_path, readLines[0])
else:
print(img_path, readLines[1])
결과.
- 버전이 안맞는지 알람들이 뜨지만, 결과는 나옴
- 검증에 사용된 이미지 (실제 이미지에서는 눈이 가려져 있지 않음)
- 위 결과에서 나온 파일명과 대조해 보면 mask, unmask가 정확히 구분된 것을 알 수 있음
엔트리에서 AI관련 콘텐츠를 만들 때 사용하는 툴이 텐서플로를 모방한 듯 보인다.
엔트리에서 콘텐츠를 만들 때 불편한 점은
실시간으로 학습결과 반영이 안되고 웹캠에서도 하나의 이미지로 받아서
구분해야 하는 점이다.
네이버는 엔트리에 투자를 더 해야할 듯.
개발은 하는 것 같은데 관리가 안됨.
최근댓글