강얼쥐와 함께 즐겁게 읽는 AI

고양이야 선녀야? (feat. tensorflow)

영웅*^%&$ 2022. 12. 31. 11:57
728x90

import tensorflow as tf
import keras

model = keras.applications.MobileNet()

def preprocess_input(image):
    image = tf.image.resize(image, (224, 224))
    image = image / 255.0
    return image

def classify_image(image):
    input_image = preprocess_input(image)
    prediction = model.predict(input_image)
  
    if prediction[0][0] > 0.5:
        print("Cat detected!")
    else:
        print("No cat detected.")

image = keras.preprocessing.image.load_img("path/to/image.jpg", target_size=(224, 224))
classify_image(image) 

728x90