Update app.py
Browse files
app.py
CHANGED
|
@@ -4,12 +4,23 @@ from tensorflow.keras.preprocessing import image
|
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image
|
| 6 |
from keras import layers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
# Load your trained Xception model
|
| 9 |
-
model = tf.keras.models.load_model("xception-head")
|
| 10 |
|
| 11 |
# Define the labels for your classification
|
| 12 |
-
class_labels = ['
|
| 13 |
|
| 14 |
def classify_image(img):
|
| 15 |
# Preprocess the image to fit the model input shape
|
|
@@ -31,12 +42,11 @@ def classify_image(img):
|
|
| 31 |
# Gradio interface
|
| 32 |
demo = gr.Interface(
|
| 33 |
fn=classify_image,
|
| 34 |
-
title="Human
|
| 35 |
-
description = "Predict the
|
| 36 |
inputs=gr.Image(type="pil"),
|
| 37 |
outputs=[gr.Label(num_top_classes=len(class_labels)), gr.Number()],
|
| 38 |
live=True,
|
| 39 |
-
article = "Author: <a href=\"https://www.linkedin.com/in/anna-maria-nau/\">Anna-Maria Nau</a>"
|
| 40 |
)
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image
|
| 6 |
from keras import layers
|
| 7 |
+
from transformers import TFAutoModelForImageClassification
|
| 8 |
+
from transformers import AutoImageProcessor
|
| 9 |
+
|
| 10 |
+
# Load model#'model = tf.keras.models.load_model("xception-head")
|
| 11 |
+
|
| 12 |
+
# Replace with your Hugging Face model repository name
|
| 13 |
+
model_name = "icputrd/Inception-V3-Human-Bodypart-Classifier"
|
| 14 |
+
|
| 15 |
+
# Load the pre-trained TensorFlow model from Hugging Face
|
| 16 |
+
model = TFAutoModelForImageClassification.from_pretrained(model_name)
|
| 17 |
+
|
| 18 |
+
# Load the associated image processor (for preprocessing input images)
|
| 19 |
+
image_processor = AutoImageProcessor.from_pretrained(model_name)
|
| 20 |
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Define the labels for your classification
|
| 23 |
+
class_labels = ['arm', 'hand', 'foot', 'legs','fullbody','head','backside', 'torso', 'stake', 'plastic'] # Replace with your actual class names
|
| 24 |
|
| 25 |
def classify_image(img):
|
| 26 |
# Preprocess the image to fit the model input shape
|
|
|
|
| 42 |
# Gradio interface
|
| 43 |
demo = gr.Interface(
|
| 44 |
fn=classify_image,
|
| 45 |
+
title="Human Bodypart Image Classification",
|
| 46 |
+
description = "Predict the bodypart of huma. This is a demo of our human bodypart image <a href=\"https://huggingface.co/icputrd/Inception-V3-Human-Bodypart-Classifier">classifier</a>.",
|
| 47 |
inputs=gr.Image(type="pil"),
|
| 48 |
outputs=[gr.Label(num_top_classes=len(class_labels)), gr.Number()],
|
| 49 |
live=True,
|
|
|
|
| 50 |
)
|
| 51 |
|
| 52 |
if __name__ == "__main__":
|