|
from tensorflow.keras.applications import ResNet50 |
|
from tensorflow.keras.preprocessing import image |
|
from tensorflow.keras.applications.resnet50 import preprocess_input |
|
import numpy as np |
|
|
|
from sklearn.ensemble import RandomForestClassifier |
|
import gradio as gr |
|
from joblib import load |
|
|
|
|
|
|
|
base_model = ResNet50(weights='imagenet', include_top=False) |
|
|
|
|
|
def extract_resnet_features(img_path): |
|
img = image.load_img(img_path, target_size=(224, 224)) |
|
x = image.img_to_array(img) |
|
x = np.expand_dims(x, axis=0) |
|
x = preprocess_input(x) |
|
features = base_model.predict(x) |
|
features_flattened = features.flatten() |
|
return features_flattened |
|
|
|
|
|
|
|
rf_classifier = load('random_forest_model2.joblib') |
|
|
|
|
|
def predict(image): |
|
|
|
features = extract_resnet_features(image) |
|
|
|
|
|
prediction = rf_classifier.predict([features])[0] |
|
|
|
return prediction |
|
|
|
|
|
iface = gr.Interface(fn=predict, inputs="image", outputs="text", title="Brain Tumor Classification") |
|
iface.launch() |