Spaces:
Build error
Build error
Anthony-Ml
commited on
Commit
•
183ee03
1
Parent(s):
08afe4a
Update app.py
Browse filesreverted the code
app.py
CHANGED
@@ -61,40 +61,7 @@ def predict_image(get_image):
|
|
61 |
pred, idx, probs = learn.predict(get_image)
|
62 |
return dict(zip(categories, map(float, probs)))
|
63 |
|
64 |
-
|
65 |
-
# Load and preprocess the image
|
66 |
-
image = Image.open(image_path)
|
67 |
-
preprocess = transforms.Compose([
|
68 |
-
transforms.Resize((224, 224)),
|
69 |
-
transforms.ToTensor(),
|
70 |
-
])
|
71 |
-
input_image = preprocess(image).unsqueeze(0) # Add a batch dimension
|
72 |
-
input_image = input_image.to('cuda' if torch.cuda.is_available() else 'cpu')
|
73 |
-
|
74 |
-
# Create an instance of GradCAM
|
75 |
-
cam = GradCAM(model=model, target_layer=target_layer)
|
76 |
-
|
77 |
-
# Compute the CAM
|
78 |
-
cam_image = cam(input_tensor=input_image, target_category=target_category)
|
79 |
-
|
80 |
-
# Show the CAM on the original image
|
81 |
-
visualization = show_cam_on_image(input_image, cam_image)
|
82 |
-
#visualization.show()
|
83 |
-
|
84 |
-
|
85 |
-
with gr.Blocks() as demo:
|
86 |
-
with gr.Row():
|
87 |
-
with gr.Column():
|
88 |
-
input_img = gr.Image(label="Input Image", shape=(224, 224))
|
89 |
-
with gr.Row():
|
90 |
-
interpret = gr.Button("Interpret")
|
91 |
-
with gr.Column():
|
92 |
-
label = gr.Label(label="Predicted Class")
|
93 |
-
with gr.Column():
|
94 |
-
interpretation = gr.components.Interpretation(input_img)
|
95 |
-
interpret.click(interpretation_function(input_img,learn, "_conv_head",target_category=None), input_img, interpretation)
|
96 |
-
|
97 |
-
#interpretation="default"
|
98 |
enable_queue=True
|
99 |
|
100 |
gr.Interface(fn=predict_image, inputs=gr.Image(shape=(224,224)),
|
|
|
61 |
pred, idx, probs = learn.predict(get_image)
|
62 |
return dict(zip(categories, map(float, probs)))
|
63 |
|
64 |
+
interpretation= 'shap'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
enable_queue=True
|
66 |
|
67 |
gr.Interface(fn=predict_image, inputs=gr.Image(shape=(224,224)),
|