satvs commited on
Commit
5123d79
·
1 Parent(s): c5dac7c

Preparing submission

Browse files
Files changed (1) hide show
  1. tasks/image.py +3 -12
tasks/image.py CHANGED
@@ -107,27 +107,18 @@ async def evaluate_image(request: ImageEvaluationRequest):
107
 
108
  # Load model
109
  model_path = Path("tasks", "models")
110
- # If CUDA is available, load FP16 pytorch
111
- # if is_available():
112
- # print("CUDA available, loading FP16 pytorch model")
113
  model_name = "pruned_fp16.pt"
 
114
  model = YOLO(Path(model_path, model_name), task="detect")
115
- # device_name = device("cuda")
116
  device_name = device("cuda" if is_available() else "cpu")
117
  IMGSIZE = 1280
118
- # # If not, load FP16 ONNX model
119
- # else:
120
- # print("CUDA not, available, loading ONNX model")
121
- # model_name = "640_fp16_cpu.onnx"
122
- # model = YOLO(Path(model_path, model_name), task="detect")
123
- # device_name = device("cpu")
124
- # IMGSIZE = 640 # required to make CPU inference a bit fast
125
 
126
  predictions = []
127
  true_labels = []
128
  pred_boxes = []
129
  true_boxes_list = [] # List of lists, each inner list contains boxes for one image
130
 
 
131
  for example in test_dataset:
132
  # Parse true annotation (YOLO format: class_id x_center y_center width height)
133
  annotation = example.get("annotations", "").strip()
@@ -135,7 +126,7 @@ async def evaluate_image(request: ImageEvaluationRequest):
135
  true_labels.append(int(has_smoke))
136
 
137
  # Make prediction
138
- results = model.predict(example["image"], device=device_name, conf=THRESHOLD, verbose=False, imgsz=IMGSIZE)[0]
139
  pred_has_smoke = len(results) > 0
140
  predictions.append(int(pred_has_smoke))
141
 
 
107
 
108
  # Load model
109
  model_path = Path("tasks", "models")
 
 
 
110
  model_name = "pruned_fp16.pt"
111
+ print(f"Loading model {model_name}")
112
  model = YOLO(Path(model_path, model_name), task="detect")
 
113
  device_name = device("cuda" if is_available() else "cpu")
114
  IMGSIZE = 1280
 
 
 
 
 
 
 
115
 
116
  predictions = []
117
  true_labels = []
118
  pred_boxes = []
119
  true_boxes_list = [] # List of lists, each inner list contains boxes for one image
120
 
121
+ print(f"Inference start on device: {device_name}")
122
  for example in test_dataset:
123
  # Parse true annotation (YOLO format: class_id x_center y_center width height)
124
  annotation = example.get("annotations", "").strip()
 
126
  true_labels.append(int(has_smoke))
127
 
128
  # Make prediction
129
+ results = model.predict(example["image"], device=device_name, conf=THRESHOLD, verbose=True, imgsz=IMGSIZE)[0]
130
  pred_has_smoke = len(results) > 0
131
  predictions.append(int(pred_has_smoke))
132