반응형
# 구글 코랩에 파일 업로드해서 모델에 적용하는 함수
import numpy as np
from google.colab import files
from tensorflow.keras.preprocessing import image
uploaded = files.upload()
for fn in uploaded.keys() :
path = '/content/' + fn
img = image.load_img(path, target_size=(300,300))
x = image.img_to_array(img) / 255.0
print(x.shape)
x = np.expand_dims(x, axis = 0)
print(x.shape)
images = np.vstack( [x] )
classes = model.predict( images, batch_size = 10 )
print(classes)
if classes[0] > 0.5 :
print(fn + " is a human")
else :
print(fn + " is a horse")

파일 선택을 누른 후 적용시켜주면

학습한 내용을 upload한 파일에 적용해 예측할 수 있다.
반응형
'Deep Learning > Tensorflow' 카테고리의 다른 글
| Tensorflow - ImageDataGenerator를 이용해서 데이터 증강하는 법 (0) | 2022.06.15 |
|---|---|
| Tensorflow - os.mkdir 이용하여, 파일 저장할 다음 디렉토리 만들기 (0) | 2022.06.15 |
| Tensorflow - 이미지 파일을 학습데이터로 만드는 방법 (0) | 2022.06.15 |
| Tensorflow - Colab에서 인터넷에있는 파일을 다운로드 하는 방법 (0) | 2022.06.15 |
| Tensorflow - 파일을 다운받고 압축푸는 방법 (0) | 2022.06.15 |