BhumikaMak commited on
Commit
ef20834
·
1 Parent(s): 53bfd89

Fix: No module named utils.google_utils.

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -47,7 +47,7 @@ def load_yolo_model(version="yolov5"):
47
  elif version == "yolov5":
48
  model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True) # Load yolov5 small model
49
  elif version == "yolov8":
50
- model = torch.hub.load('ultralytics/yolov5:v7.0', 'yolov5', pretrained=True) # YOLOv8 is part of yolov5 repo starting v7.0
51
  else:
52
  raise ValueError(f"Unsupported YOLO version: {version}")
53
 
@@ -73,8 +73,10 @@ def process_image(image, yolo_versions=["yolov5"]):
73
  for yolo_version in yolo_versions:
74
  # Load the model based on YOLO version
75
  model = load_yolo_model(yolo_version)
76
- target_layers = [model.model.model[-2]] # Assumes last layer is used for Grad-CAM
77
-
 
 
78
  # Run YOLO detection
79
  results = model(rgb_img)
80
  boxes, colors, names = parse_detections(results)
@@ -99,19 +101,20 @@ def process_image(image, yolo_versions=["yolov5"]):
99
 
100
  return result_images
101
 
 
102
  interface = gr.Interface(
103
  fn=process_image,
104
  inputs=[
105
  gr.Image(type="pil", label="Upload an Image"),
106
  gr.CheckboxGroup(
107
- choices=["yolov3", "yolov5", "yolov8", "yolov10"],
108
  value=["yolov5"], # Set the default value (YOLOv5 checked by default)
109
  label="Select Model(s)",
110
  )
111
  ],
112
  outputs = gr.Gallery(label="Results", elem_id="gallery", rows=2, height=500),
113
  title="Visualising the key image features that drive decisions with our explainable AI tool.",
114
- description="XAI: Upload an image to visualize object detection of your models.."
115
  )
116
 
117
  if __name__ == "__main__":
 
47
  elif version == "yolov5":
48
  model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True) # Load yolov5 small model
49
  elif version == "yolov8":
50
+ model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True) # YOLOv8 can be accessed via yolov5 repo
51
  else:
52
  raise ValueError(f"Unsupported YOLO version: {version}")
53
 
 
73
  for yolo_version in yolo_versions:
74
  # Load the model based on YOLO version
75
  model = load_yolo_model(yolo_version)
76
+
77
+ # In YOLOv5, the last convolutional layer in the backbone is typically the one to use
78
+ target_layers = [model.model.model[-2]] # Assuming last layer of the model is a Conv layer
79
+
80
  # Run YOLO detection
81
  results = model(rgb_img)
82
  boxes, colors, names = parse_detections(results)
 
101
 
102
  return result_images
103
 
104
+ # Define the Gradio interface
105
  interface = gr.Interface(
106
  fn=process_image,
107
  inputs=[
108
  gr.Image(type="pil", label="Upload an Image"),
109
  gr.CheckboxGroup(
110
+ choices=["yolov3", "yolov5", "yolov8"],
111
  value=["yolov5"], # Set the default value (YOLOv5 checked by default)
112
  label="Select Model(s)",
113
  )
114
  ],
115
  outputs = gr.Gallery(label="Results", elem_id="gallery", rows=2, height=500),
116
  title="Visualising the key image features that drive decisions with our explainable AI tool.",
117
+ description="XAI: Upload an image to visualize object detection of your models."
118
  )
119
 
120
  if __name__ == "__main__":