kiurtis commited on
Commit
51fe6d6
·
1 Parent(s): 1f5fdca

fix(model): fix yolo v8

Browse files
Files changed (3) hide show
  1. Dockerfile +2 -0
  2. requirements.txt +2 -1
  3. tasks/image.py +11 -3
Dockerfile CHANGED
@@ -4,6 +4,8 @@
4
  FROM python:3.9
5
 
6
  RUN useradd -m -u 1000 user
 
 
7
  USER user
8
  ENV PATH="/home/user/.local/bin:$PATH"
9
 
 
4
  FROM python:3.9
5
 
6
  RUN useradd -m -u 1000 user
7
+ RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y
8
+
9
  USER user
10
  ENV PATH="/home/user/.local/bin:$PATH"
11
 
requirements.txt CHANGED
@@ -11,4 +11,5 @@ librosa==0.10.2.post1
11
  numpy==1.26.4
12
  ultralytics==8.3.68
13
  ultralytics-thop==2.0.14
14
- opencv-python==4.11.0.86
 
 
11
  numpy==1.26.4
12
  ultralytics==8.3.68
13
  ultralytics-thop==2.0.14
14
+ #opencv-python==4.11.0.86
15
+ python-dotenv==1.0.0
tasks/image.py CHANGED
@@ -5,6 +5,7 @@ import numpy as np
5
  from sklearn.metrics import accuracy_score, precision_score, recall_score
6
  import random
7
  import os
 
8
 
9
  from .utils.evaluation import ImageEvaluationRequest
10
  from .utils.emissions import tracker, clean_emissions_data, get_space_info
@@ -14,7 +15,7 @@ load_dotenv()
14
 
15
  router = APIRouter()
16
 
17
- DESCRIPTION = "Random Baseline"
18
  ROUTE = "/image"
19
 
20
  def parse_boxes(annotation_string):
@@ -120,7 +121,9 @@ async def evaluate_image(request: ImageEvaluationRequest):
120
  pred_boxes = []
121
  true_boxes_list = [] # List of lists, each inner list contains boxes for one image
122
 
123
- for example in test_dataset:
 
 
124
  # Parse true annotation (YOLO format: class_id x_center y_center width height)
125
  annotation = example.get("annotations", "").strip()
126
  has_smoke = len(annotation) > 0
@@ -137,9 +140,14 @@ async def evaluate_image(request: ImageEvaluationRequest):
137
  image_true_boxes = parse_boxes(annotation)
138
  true_boxes_list.append(image_true_boxes)
139
 
140
- pred_box_list = get_boxes_list(model_preds)[0] # With one bbox to start with (as in the random baseline)
 
 
 
 
141
  pred_boxes.append(pred_box_list)
142
 
 
143
 
144
  #--------------------------------------------------------------------------------------------
145
  # YOUR MODEL INFERENCE STOPS HERE
 
5
  from sklearn.metrics import accuracy_score, precision_score, recall_score
6
  import random
7
  import os
8
+ from ultralytics import YOLO
9
 
10
  from .utils.evaluation import ImageEvaluationRequest
11
  from .utils.emissions import tracker, clean_emissions_data, get_space_info
 
15
 
16
  router = APIRouter()
17
 
18
+ DESCRIPTION = "Simple YOLOv8n model"
19
  ROUTE = "/image"
20
 
21
  def parse_boxes(annotation_string):
 
121
  pred_boxes = []
122
  true_boxes_list = [] # List of lists, each inner list contains boxes for one image
123
 
124
+ n_examples = len(test_dataset)
125
+ for i, example in enumerate(test_dataset):
126
+ print(f"Running {i+1} of {n_examples}")
127
  # Parse true annotation (YOLO format: class_id x_center y_center width height)
128
  annotation = example.get("annotations", "").strip()
129
  has_smoke = len(annotation) > 0
 
140
  image_true_boxes = parse_boxes(annotation)
141
  true_boxes_list.append(image_true_boxes)
142
 
143
+ try:
144
+ pred_box_list = get_boxes_list(model_preds)[0] # With one bbox to start with (as in the random baseline)
145
+ except:
146
+ print("No boxes found")
147
+ pred_box_list = [0, 0, 0, 0] # Hacky way to make sure that compute_max_iou doesn't fail
148
  pred_boxes.append(pred_box_list)
149
 
150
+
151
 
152
  #--------------------------------------------------------------------------------------------
153
  # YOUR MODEL INFERENCE STOPS HERE