Update app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ classes = ('plane', 'car', 'bird', 'cat', 'deer',
|
|
| 19 |
model = LITResNet(classes)
|
| 20 |
model.load_state_dict(torch.load("model.pth", map_location=torch.device('cpu')), strict=False)
|
| 21 |
|
| 22 |
-
def inference(input_img, show_gradcam, num_gradcam, layer_num, opacity, show_misclassified, num_misclassified, num_top_classes):
|
| 23 |
input_img = np.array(Image.fromarray(np.array(input_img)).resize((32,32)))
|
| 24 |
org_img = input_img
|
| 25 |
|
|
@@ -32,7 +32,7 @@ def inference(input_img, show_gradcam, num_gradcam, layer_num, opacity, show_mis
|
|
| 32 |
confidences = {classes[i]: float(o[i]) for i in range(10)}
|
| 33 |
|
| 34 |
_, prediction = torch.max(outputs, 1)
|
| 35 |
-
is_misclassified = (prediction !=
|
| 36 |
|
| 37 |
if show_gradcam:
|
| 38 |
target_layers = [model.layer2[layer_num]]
|
|
@@ -58,9 +58,9 @@ title = "CIFAR10 trained on ResNet18 Model with GradCAM"
|
|
| 58 |
description = "A simple Gradio interface to infer on ResNet model, get GradCAM results, and view misclassified images"
|
| 59 |
|
| 60 |
examples = [
|
| 61 |
-
["plane.
|
| 62 |
-
["car.jpg", True, 2, -2, 0.7, True, 1, 5],
|
| 63 |
-
["bird.jpg", False, 0, -1, 0.5, False, 0, 3],
|
| 64 |
# Add more examples as needed
|
| 65 |
]
|
| 66 |
|
|
@@ -68,6 +68,7 @@ demo = gr.Interface(
|
|
| 68 |
inference,
|
| 69 |
inputs=[
|
| 70 |
gr.Image(width=256, height=256, label="Input Image"),
|
|
|
|
| 71 |
gr.Checkbox(value=True, label="Show GradCAM"),
|
| 72 |
gr.Slider(1, 5, value=1, step=1, label="Number of GradCAM Images"),
|
| 73 |
gr.Slider(-2, -1, value=-2, step=1, label="Which Layer?"),
|
|
|
|
| 19 |
model = LITResNet(classes)
|
| 20 |
model.load_state_dict(torch.load("model.pth", map_location=torch.device('cpu')), strict=False)
|
| 21 |
|
| 22 |
+
def inference(input_img, input_img_label, show_gradcam, num_gradcam, layer_num, opacity, show_misclassified, num_misclassified, num_top_classes):
|
| 23 |
input_img = np.array(Image.fromarray(np.array(input_img)).resize((32,32)))
|
| 24 |
org_img = input_img
|
| 25 |
|
|
|
|
| 32 |
confidences = {classes[i]: float(o[i]) for i in range(10)}
|
| 33 |
|
| 34 |
_, prediction = torch.max(outputs, 1)
|
| 35 |
+
is_misclassified = (prediction != classes.index(input_img_label))
|
| 36 |
|
| 37 |
if show_gradcam:
|
| 38 |
target_layers = [model.layer2[layer_num]]
|
|
|
|
| 58 |
description = "A simple Gradio interface to infer on ResNet model, get GradCAM results, and view misclassified images"
|
| 59 |
|
| 60 |
examples = [
|
| 61 |
+
["plane.jpg", "plane", True, 1, -1, 0.5, False, 0, 3],
|
| 62 |
+
["car.jpg", "car", True, 2, -2, 0.7, True, 1, 5],
|
| 63 |
+
["bird.jpg", "bird", False, 0, -1, 0.5, False, 0, 3],
|
| 64 |
# Add more examples as needed
|
| 65 |
]
|
| 66 |
|
|
|
|
| 68 |
inference,
|
| 69 |
inputs=[
|
| 70 |
gr.Image(width=256, height=256, label="Input Image"),
|
| 71 |
+
gr.Dropdown(choices=classes, label="Ground Truth Label"),
|
| 72 |
gr.Checkbox(value=True, label="Show GradCAM"),
|
| 73 |
gr.Slider(1, 5, value=1, step=1, label="Number of GradCAM Images"),
|
| 74 |
gr.Slider(-2, -1, value=-2, step=1, label="Which Layer?"),
|