Team Ai
Apppublic

vaishanthr/Image-Classifier-TensorFlow

sourceHugging Facemitupdated 3y agoView on Hugging Face
1likes
resnet_model.py25 linesDownload Raw Back to root
1import tensorflow as tf2from tensorflow import keras3from tensorflow.keras import layers4 5class ResNetClassifier:6  def __init__(self):7    self.model = keras.applications.ResNet50(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((224, 224))12    img_array = keras.preprocessing.image.img_to_array(img)13    img_array = tf.expand_dims(img_array, 0)14    img_array = keras.applications.resnet50.preprocess_input(img_array)15    return img_array16 17  def classify_image(self, image):18    # Preprocess the image19    img_array = self.preprocess_image(image)20 21    # Classify the image22    predictions = self.model.predict(img_array)23    predicted_classes = keras.applications.imagenet_utils.decode_predictions(predictions, top=3)[0]24 25    return predicted_classes