hrsht-13 / Breast-Cancer-Detection

This project uses mammograms for breast cancer detection using deep learning techniques.
33 stars 19 forks source link

app.py not working need help!!!!! #4

Closed vishalvaishnav2405 closed 1 year ago

vishalvaishnav2405 commented 1 year ago

image

hrsht-13 commented 1 year ago

hey @vishalvaishnav2405 please send the complete error, as I m unable to understand where this error is thrown from.

vishalvaishnav2405 commented 1 year ago

Thank you for replying. I have being using you original code without any changes and i have run it on VScode and i still get errors kindly check the below the code . We have a deadline on 19th march for submittin gthe project, so kindly do help us in reolving the issue. if you want i can mail you the error part on the VScode if needed

import tensorflow as tf import numpy as np from PIL import Image from weights import download_weights from model import download_model import cv2 import gradio as gr

def main(): def load_model(): model=tf.keras.models.load_model("model/model.h5") initial_learning_rate = 0.0001 lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay( initial_learning_rate, decay_steps=1000, decay_rate=0.96, staircase=True)

model.compile(optimizer =tf.keras.optimizers.Adam(learning_rate=lr_schedule),
             metrics=["accuracy"],
             loss= tf.keras.losses.CategoricalCrossentropy(label_smoothing=0.1))
download_weights()
model.load_weights("weights/modeldense1.h5")
return load_model

model=load_model()

def preprocess(image): kernel = np.array([[0,-1,0], [-1,5,-1], [0,-1,0]]) im = cv2.filter2D(image, -1, kernel) return im

image=gr.components.Image(shape=(224,224)) label=gr.components.Label(num_top_classes=8)

class_name=['Benign with Density=1','Malignant with Density=1','Benign with Density=2','Malignant with Density=2','Benign with Density=3','Malignant with Density=3','Benign with Density=4','Malignant with Density=4']

def predict_img(img): img=preprocess(img) img=img/255.0 im=img.reshape(-1,224,224,3) pred=model.predict(im)[0] return {class_name[i]:float(pred[i]) for i in range(8)}

gr.Interface(fn=predict_img,inputs=image,outputs=label,capture_session=True).launch(debug='True',share=True)

if name=='main': main()

vishalvaishnav2405 commented 1 year ago

File "C:\Users\Vishal\AppData\Local\Programs\Python\Python311\Lib\site-packages\gradio\routes.py", line 374, in run_predict
output = await app.get_blocks().process_api( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Vishal\AppData\Local\Programs\Python\Python311\Lib\site-packages\gradio\blocks.py", line 1017, in process_api result = await self.call_function( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Vishal\AppData\Local\Programs\Python\Python311\Lib\site-packages\gradio\blocks.py", line 835, in call_function prediction = await anyio.to_thread.run_sync( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Vishal\AppData\Local\Programs\Python\Python311\Lib\site-packages\anyio\to_thread.py", line 31, in run_sync return await get_asynclib().run_sync_in_worker_thread( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Vishal\AppData\Local\Programs\Python\Python311\Lib\site-packages\anyio_backends_asyncio.py", line 937, in run_sync_in_worker_thread return await future ^^^^^^^^^^^^ File "C:\Users\Vishal\AppData\Local\Programs\Python\Python311\Lib\site-packages\anyio_backends_asyncio.py", line 867, in run result = context.run(func, *args) ^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\Vishal\Downloads\Breast-Cancer-Detection-Model-By-using-Deep-Learning-main\Breast-Cancer-Detection-Model-By-using-Deep-Learning-main\app.py", line 40, in predict_img img=img/255.0


TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
vishalvaishnav2405 commented 1 year ago

image