본문 바로가기

Deep Learning/Tensorflow

Tensorflow - Colab에 file upload해서 모델에 적용하는 함수

반응형
# 구글 코랩에 파일 업로드해서 모델에 적용하는 함수

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한 파일에 적용해 예측할 수 있다.

반응형