Views
No views yet
pip install huggingface_hub tensorflow pillow numpy1from huggingface_hub import hf_hub_download
2import tensorflow as tf
3import numpy as np
4from PIL import Image
5
6# Download model
7model_path = hf_hub_download(
8 repo_id="your-username/brain-mri-classifier",
9 filename="efficient_net_B0.h5"
10)
11
12# Load model
13model = tf.keras.models.load_model(model_path)
14
15# Preprocess image
16def preprocess_image(image_path):
17 image = Image.open(image_path).convert('RGB')
18 image = image.resize((150, 150))
19 image_array = np.array(image)
20 image_array = np.expand_dims(image_array, axis=0)
21 return image_array
22
23# Make prediction
24image_array = preprocess_image("path/to/brain_scan.jpg")
25predictions = model.predict(image_array)
26class_names = ["CONTROL", "AD", "PD"]
27predicted_class = class_names[np.argmax(predictions)]
28confidence = np.max(predictions) * 100
29
30print(f"Prediction: {predicted_class}")
31print(f"Confidence: {confidence:.2f}%")@misc{brain-mri-classifier,
title={Brain MRI Classification Model for Neurological Disease Detection},
author={Medical AI Team},
year={2024},
publisher={Hugging Face},
url={https://huggingface.co/your-username/brain-mri-classifier}
}