CoolFace
Apppublic

vaishanthr/Image-Classifier-TensorFlow

sourceHugging Facemitupdated 3y agoView on Hugging Face
1likes
inception_v3_model.py26 linesDownload Raw Back to root
1import tensorflow as tf2from tensorflow import keras3from tensorflow.keras import layers4 5class InceptionV3Classifier:6  def __init__(self):7    self.model = keras.applications.InceptionV3(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)8  9  def preprocess_image(self, image):10    img = keras.preprocessing.image.array_to_img(image)11    img = img.resize((299, 299))12    img_array = keras.preprocessing.image.img_to_array(img)13    img_array = tf.expand_dims(img_array, 0)14    img_array = keras.applications.vgg16.preprocess_input(img_array)15    return img_array16 17  def classify_image(self, image):18 19    # Preprocess the image20    img_array = self.preprocess_image(image)21 22    # Classify the image23    predictions = self.model.predict(img_array)24    predicted_classes = keras.applications.imagenet_utils.decode_predictions(predictions, top=3)[0]25 26    return predicted_classes