sav_evaluator.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright (c) Meta Platforms, Inc. and affiliates.
  2. # All rights reserved.
  3. # This source code is licensed under the license found in the
  4. # LICENSE file in the sav_dataset directory of this source tree.
  5. # adapted from https://github.com/hkchengrex/vos-benchmark
  6. # and https://github.com/davisvideochallenge/davis2017-evaluation
  7. # with their licenses found in the LICENSE_VOS_BENCHMARK and LICENSE_DAVIS files
  8. # in the sav_dataset directory.
  9. from argparse import ArgumentParser
  10. from utils.sav_benchmark import benchmark
  11. """
  12. The structure of the {GT_ROOT} can be either of the follow two structures.
  13. {GT_ROOT} and {PRED_ROOT} should be of the same format
  14. 1. SA-V val/test structure
  15. {GT_ROOT} # gt root folder
  16. ├── {video_id}
  17. │ ├── 000 # all masks associated with obj 000
  18. │ │ ├── {frame_id}.png # mask for object 000 in {frame_id} (binary mask)
  19. │ │ └── ...
  20. │ ├── 001 # all masks associated with obj 001
  21. │ ├── 002 # all masks associated with obj 002
  22. │ └── ...
  23. ├── {video_id}
  24. ├── {video_id}
  25. └── ...
  26. 2. Similar to DAVIS structure:
  27. {GT_ROOT} # gt root folder
  28. ├── {video_id}
  29. │ ├── {frame_id}.png # annotation in {frame_id} (may contain multiple objects)
  30. │ └── ...
  31. ├── {video_id}
  32. ├── {video_id}
  33. └── ...
  34. """
  35. parser = ArgumentParser()
  36. parser.add_argument(
  37. "--gt_root",
  38. required=True,
  39. help="Path to the GT folder. For SA-V, it's sav_val/Annotations_6fps or sav_test/Annotations_6fps",
  40. )
  41. parser.add_argument(
  42. "--pred_root",
  43. required=True,
  44. help="Path to a folder containing folders of masks to be evaluated, with exactly the same structure as gt_root",
  45. )
  46. parser.add_argument(
  47. "-n", "--num_processes", default=16, type=int, help="Number of concurrent processes"
  48. )
  49. parser.add_argument(
  50. "-s",
  51. "--strict",
  52. help="Make sure every video in the gt_root folder has a corresponding video in the prediction",
  53. action="store_true",
  54. )
  55. parser.add_argument(
  56. "-q",
  57. "--quiet",
  58. help="Quietly run evaluation without printing the information out",
  59. action="store_true",
  60. )
  61. # https://github.com/davisvideochallenge/davis2017-evaluation/blob/d34fdef71ce3cb24c1a167d860b707e575b3034c/davis2017/evaluation.py#L85
  62. parser.add_argument(
  63. "--do_not_skip_first_and_last_frame",
  64. help="In SA-V val and test, we skip the first and the last annotated frames in evaluation. "
  65. "Set this to true for evaluation on settings that doen't skip first and last frames",
  66. action="store_true",
  67. )
  68. if __name__ == "__main__":
  69. args = parser.parse_args()
  70. benchmark(
  71. [args.gt_root],
  72. [args.pred_root],
  73. args.strict,
  74. args.num_processes,
  75. verbose=not args.quiet,
  76. skip_first_and_last=not args.do_not_skip_first_and_last_frame,
  77. )