Views
No views yet
512x512x388.96%97.89%[Add your final Validation Loss here]huggingface_hub library.1pip install tensorflow huggingface_hub
2import tensorflow as tf
3from huggingface_hub import from_pretrained_keras
4import numpy as np
5from PIL import Image
6
7# Load the model from your Hugging Face Hub repo
8model = from_pretrained_keras("Arko007/skin-disease-detector-ai")
9
10print("Model loaded successfully!")
11
12# Define the class names in the correct order
13CLASS_NAMES = [
14 'Acitinic Keratosis', 'Basal Cell Carcinoma', 'Dermatofibroma', 'Nevus',
15 'Pigmented Benign Keratosis', 'Seborrheic Keratosis',
16 'Squamous Cell Carcinoma', 'Vascular Lesion'
17]
18
19def preprocess_image(image_path, img_size=512):
20 """Loads and preprocesses an image for the model."""
21 img = Image.open(image_path).convert('RGB')
22 img = img.resize((img_size, img_size))
23 img_array = np.array(img)
24 img_array = np.expand_dims(img_array, axis=0)
25 img_array = tf.cast(img_array, tf.float32) / 255.0
26 return img_array
27
28def predict(image_path):
29 """Runs inference on a single image."""
30 processed_image = preprocess_image(image_path)
31 predictions = model.predict(processed_image)
32 predicted_class_index = np.argmax(predictions, axis=1)[0]
33 predicted_class_name = CLASS_NAMES[predicted_class_index]
34 confidence = np.max(predictions, axis=1)[0]
35
36 print(f"Predicted Class: {predicted_class_name}")
37 print(f"Confidence: {confidence:.2%}")
38 return predicted_class_name, confidence
39
40# Example usage:
41# predict("path/to/your/skin_image.jpg")
42
43## Training Data
44The model was trained on the "Multiple Skin Disease Detection and Classification" dataset. The original dataset of ~3,300 images was augmented 10x using the `imgaug` library to create a final training set of over 33,000 images, which helped in achieving high generalization performance.
45
46## Author
47This model was built by Arko.