Hifza's picture
Duplicate from Hifza/Brain_tumor_Project
55a2566
raw
history blame contribute delete
954 Bytes
import cv2
import numpy as np
import time
import os
from PIL import Image
import gradio as gr
ch_detection_model1 = cv2.dnn.readNet('tumor_classifier_mixed_datasets.onnx')
def main_func(im):
im=cv2.resize(im,(224,224))
im=cv2.cvtColor(im, cv2.COLOR_RGB2BGR)
im = (im.astype(np.float32)) / 255.0
im=im[np.newaxis, ...]
#print(im.shape)
ch_detection_model1.setInput(im)
outputs=ch_detection_model1.forward(ch_detection_model1.getUnconnectedOutLayersNames())
outputs=np.array(outputs)
outputs=outputs.reshape(-1)
if outputs[0]>0.49:
results=("predicted as Tumor with probability :"+str(outputs[0]))
return results
if outputs[0]<0.50:
results=("There is No-Tumor with probability :"+str(1-outputs[0]))
return results
def final_func():
gr.Interface(fn=main_func,
inputs=gr.Image(),
outputs='text',examples=["Y10.jpg","Y109.jpeg","20 no.jpg"]).launch()
if __name__ == "__main__":
final_func()