MCPcopy Create free account
hub / github.com/PolyU-ChenLab/UniPixel / eval_queue

Function eval_queue

unipixel/eval/eval_groundmore.py:242–337  ·  view source on GitHub ↗
(q, rank, out_dict, pred_path, video_root)

Source from the content-addressed store, hash-verified

240
241
242def eval_queue(q, rank, out_dict, pred_path, video_root):
243 while not q.empty():
244 video, exp_idx = q.get()
245
246 expressions = metadata[video]["questions"]
247 expression_list = list(expressions.keys())
248
249 clip_start = video[-9:].split("_")[0][:2] + ":" + video[-9:].split("_")[0][2:]
250 # clip_end = video[-9:].split("_")[1][:2] + ":" + video[-9:].split("_")[1][2:]
251
252 # read all the anno meta
253 meta = {}
254 meta["video_id"] = video
255 meta["exp"] = expressions[expression_list[exp_idx]]["question"]
256 meta["ans"] = expressions[expression_list[exp_idx]]["answer"]
257 meta["obj_id"] = int(expressions[expression_list[exp_idx]]["obj_id"])
258 meta["q_type"] = expressions[expression_list[exp_idx]]["q_type"]
259 meta["exp_id"] = expression_list[exp_idx]
260
261 start = expressions[expression_list[exp_idx]]["action_start"]
262 end = expressions[expression_list[exp_idx]]["action_end"]
263 action_start = (time_str_to_seconds(start) - time_str_to_seconds(clip_start)) * 6 # fps=6
264 action_end = (time_str_to_seconds(end) - time_str_to_seconds(clip_start)) * 6 - 1
265
266 meta["action_start"] = action_start
267 meta["action_end"] = action_end
268 # meta["frame_dir"] = frame_start.zfill(4) + "_" + frame_end.zfill(4)
269
270 # 2. For each expression
271 video_id = meta["video_id"]
272 exp_id = meta["exp_id"]
273 obj_id = meta["obj_id"]
274 q_type = meta["q_type"]
275
276 # action start and end is used to obtain gt masks in temporal dimension
277 action_start = meta["action_start"]
278 action_end = meta["action_end"]
279
280 frame_dir = os.path.join(video_root, video_id, "images/")
281 if not os.path.exists(frame_dir):
282 print("Missing frames: {}.".format(video_id))
283 continue
284 raw_frames = nncore.ls(frame_dir, ext='jpg') # all the frames
285 has_frm = nncore.pure_name(raw_frames[0]).startswith('frame_')
286 sample_indices = np.linspace(0, len(raw_frames) - 1, num=20, dtype=int) # uniformly sample 20 frames
287 assert len(sample_indices) == 20
288
289 preds = nncore.ls(f'{args.pred_path}/{video_id}/{exp_id}', ext='png', join_path=True)
290 preds.sort(key=lambda p: int(re.sub(r'^\D*', '', nncore.pure_name(p))))
291 # assert len(preds) == len(sample_indices), (f'{video_id}/{exp_id}', len(preds), len(sample_indices))
292
293 pred_0 = cv2.imread(preds[0], cv2.IMREAD_GRAYSCALE)
294 h, w = pred_0.shape
295 origin_h, origin_w = pred_0.shape
296 all_pred_masks = np.zeros((len(sample_indices), h, w), dtype=np.uint8)
297
298 for frame_idx, index in enumerate(sample_indices):
299 mask_id = "frame_" + str(index).zfill(6) + ".png" if has_frm else str(index).zfill(7) + ".png"

Callers

nothing calls this directly

Calls 4

time_str_to_secondsFunction · 0.85
db_statisticsFunction · 0.85
db_eval_iouFunction · 0.70
db_eval_boundaryFunction · 0.70

Tested by

no test coverage detected