Views
No views yet
1import tensorflow as tf
2from huggingface_hub import hf_hub_download
3import numpy as np
4from PIL import Image
5
6# Download the model
7model_path = hf_hub_download(
8 repo_id="shifaazzz/mobilenet-v2-custom",
9 filename="model.h5"
10)
11
12# Load the model
13model = tf.keras.models.load_model(model_path, compile=False)
14
15# Recompile if needed
16model.compile(
17 optimizer='adam',
18 loss='categorical_crossentropy',
19 metrics=['accuracy']
20)
21
22# Load and preprocess an image
23img = Image.open("your_image.jpg").resize((224, 224))
24img_array = np.array(img) / 255.0 # Normalize
25img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
26
27# Make prediction
28predictions = model.predict(img_array)
29predicted_class = np.argmax(predictions[0])
30confidence = predictions[0][predicted_class]
31
32print(f"Predicted Class: {predicted_class}")
33print(f"Confidence: {confidence:.2%}")1# Load without compilation
2model = tf.keras.models.load_model(model_path, compile=False)LOADING_INSTRUCTIONS.md file in this repository for more details.model.h5 - The trained model (recommended)saved_model/ - TensorFlow SavedModel format (if available)model_weights.h5 - Model weights only (if available)model_architecture.json - Model architecture in JSON format (if available)config.json - Model configurationrequirements.txt - Python dependencies0: Class_Name_0
1: Class_Name_1
2: Class_Name_2
...