Load image paths and labels from a "frame list". Each line of the frame list contains: `original_vido_id video_id frame_id path labels` Args: frame_list_file (string): path to the frame list. prefix (str): the prefix for the path. return_list (bool): if True,
(frame_list_file, prefix="", return_list=False)
| 304 | |
| 305 | |
| 306 | def load_image_lists(frame_list_file, prefix="", return_list=False): |
| 307 | """ |
| 308 | Load image paths and labels from a "frame list". |
| 309 | Each line of the frame list contains: |
| 310 | `original_vido_id video_id frame_id path labels` |
| 311 | Args: |
| 312 | frame_list_file (string): path to the frame list. |
| 313 | prefix (str): the prefix for the path. |
| 314 | return_list (bool): if True, return a list. If False, return a dict. |
| 315 | Returns: |
| 316 | image_paths (list or dict): list of list containing path to each frame. |
| 317 | If return_list is False, then return in a dict form. |
| 318 | labels (list or dict): list of list containing label of each frame. |
| 319 | If return_list is False, then return in a dict form. |
| 320 | """ |
| 321 | image_paths = defaultdict(list) |
| 322 | labels = defaultdict(list) |
| 323 | with g_pathmgr.open(frame_list_file, "r") as f: |
| 324 | assert f.readline().startswith("original_vido_id") |
| 325 | for line in f: |
| 326 | row = line.split() |
| 327 | # original_vido_id video_id frame_id path labels |
| 328 | assert len(row) == 5 |
| 329 | video_name = row[0] |
| 330 | if prefix == "": |
| 331 | path = row[3] |
| 332 | else: |
| 333 | path = os.path.join(prefix, row[3]) |
| 334 | image_paths[video_name].append(path) |
| 335 | frame_labels = row[-1].replace('"', "") |
| 336 | if frame_labels != "": |
| 337 | labels[video_name].append( |
| 338 | [int(x) for x in frame_labels.split(",")] |
| 339 | ) |
| 340 | else: |
| 341 | labels[video_name].append([]) |
| 342 | |
| 343 | if return_list: |
| 344 | keys = image_paths.keys() |
| 345 | image_paths = [image_paths[key] for key in keys] |
| 346 | labels = [labels[key] for key in keys] |
| 347 | return image_paths, labels |
| 348 | return dict(image_paths), dict(labels) |
| 349 | |
| 350 | |
| 351 | def tensor_normalize(tensor, mean, std): |