Instructions to use pavankm96/brain_tumor_det with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use pavankm96/brain_tumor_det with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://pavankm96/brain_tumor_det") - Notebooks
- Google Colab
- Kaggle
| import gradio as gr | |
| import numpy as np | |
| import tensorflow as tf | |
| # Load your model | |
| model = tf.keras.models.load_model("model/Brain_tumor_pred.h5") # Ensure this is the correct path to your model | |
| def predict(image): | |
| # Preprocess the image for prediction | |
| image = tf.image.resize(image, [224, 224]) # Change to your model's expected size | |
| image = np.expand_dims(image, axis=0) # Add batch dimension | |
| predictions = model.predict(image) # Get model predictions | |
| # Assuming your model outputs probabilities for binary classification | |
| # The first output is the probability of class 0 (no tumor), | |
| # and the second output is the probability of class 1 (tumor) | |
| no_tumor_confidence = predictions[0][0] # Probability of no tumor | |
| tumor_confidence = predictions[0][1] # Probability of tumor | |
| # Create a response with confidence scores | |
| if tumor_confidence > no_tumor_confidence: | |
| result = { | |
| "prediction": "Tumor Detected", | |
| "confidence": float(tumor_confidence) | |
| } | |
| else: | |
| result = { | |
| "prediction": "No Tumor Detected", | |
| "confidence": float(no_tumor_confidence) | |
| } | |
| return result | |
| # Create a Gradio interface | |
| iface = gr.Interface(fn=predict, inputs="image", outputs="json") | |
| # Launch the Gradio interface | |
| iface.launch() | |