Image Classification
Keras
TF-Keras
English
mobilevit
tensorflow
computer-vision
medical-imaging
brain-tumor
Eval Results (legacy)
Instructions to use abdo1176/brain-model-test with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use abdo1176/brain-model-test with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://abdo1176/brain-model-test") - Notebooks
- Google Colab
- Kaggle
Upload usage_example.py with huggingface_hub
Browse files12345678910111213141516171819202122232425262728293031323334353637383940
import tensorflow as tfimport numpy as npfrom PIL import Imagefrom huggingface_hub import hf_hub_downloadimport json
# Download model and class names from Hugging Facemodel_path = hf_hub_download(repo_id="abdo1176/brain-model-test", filename="model.keras")class_names_path = hf_hub_download(repo_id="abdo1176/brain-model-test", filename="class_names.json")
# Load model and class namesmodel = tf.keras.models.load_model(model_path)with open(class_names_path, 'r') as f: class_names = json.load(f)
def preprocess_image(image_path): """Preprocess image for model prediction""" image = Image.open(image_path).convert('RGB') image = image.resize((224, 224)) image = np.array(image) / 255.0 image = np.expand_dims(image, axis=0) return image
def predict_brain_tumor(image_path): """Predict brain tumor from MRI image""" image = preprocess_image(image_path) predictions = model.predict(image) predicted_idx = np.argmax(predictions[0]) confidence = float(predictions[0][predicted_idx]) return { "predicted_class": class_names[predicted_idx], "confidence": confidence, "all_predictions": {class_names[i]: float(predictions[0][i]) for i in range(len(class_names))} }
# Example usage:# result = predict_brain_tumor("path/to/your/mri_image.jpg")# print(f"Prediction: {result['predicted_class']} (Confidence: {result['confidence']:.2%})")usage_example.pyAdded+40