BhumikaMak commited on
Commit
86915f5
·
1 Parent(s): d545606

Fix: resolved model access methodology

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -74,7 +74,12 @@ def process_image(image, yolo_versions=["yolov5"]):
74
  for yolo_version in yolo_versions:
75
  # Load the model based on YOLO version
76
  model = load_yolo_model(yolo_version)
77
- target_layers = [model.model[-1]] # Fix: Access the correct last layer in YOLOv8
 
 
 
 
 
78
 
79
  # Run YOLO detection
80
  results = model([rgb_img])
 
74
  for yolo_version in yolo_versions:
75
  # Load the model based on YOLO version
76
  model = load_yolo_model(yolo_version)
77
+
78
+ # YOLOv8: Extract last layer by model.model[-1] would not work; use the following:
79
+ if isinstance(model.model, torch.nn.Sequential):
80
+ target_layers = [model.model[-1]] # This assumes model layers are in a Sequential container
81
+ else:
82
+ target_layers = [model.model[-2]] # Use an appropriate layer
83
 
84
  # Run YOLO detection
85
  results = model([rgb_img])