Skip to content

Commit

Permalink
Add flag to omit timestamp in output directory (#253)
Browse files Browse the repository at this point in the history
* Add flag to omit timestamp in output directory

* Redefine constructor test using pytest monkeypatching rather than unittest's mock (for consistency with the rest)

* Simplify test for tracking constructor

* Reduce number of fixtures in test_tracking_constructor using factories

* Add test_prep_outputs using mock_mkdir

* Parametrize test_prep_outputs

* Adapt constructor tests to new fixtures

* Update README

* Small fixes to docs

* Small changes to docstrings and comments
  • Loading branch information
sfmig authored Nov 20, 2024
1 parent c3e653d commit 1cdb184
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 66 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ To track crabs in a new video, using a trained detector and a tracker, run the f
detect-and-track-video --trained_model_path <path-to-ckpt-file> --video_path <path-to-input-video>
```

This will produce a `tracking_output_<timestamp>` directory with the output from tracking under the current working directory.
This will produce a `tracking_output_<timestamp>` directory with the output from tracking under the current working directory. To avoid adding the `<timestamp>` suffix to the directory name, run the command with the `--output_dir_no_timestamp` flag. To see the full list of possible arguments to the `detect-and-track-video` command, run it with the `--help` flag.

The tracking output consists of:
- a .csv file named `<video-name>_tracks.csv`, with the tracked bounding boxes data;
Expand All @@ -153,8 +153,6 @@ If a file with ground-truth annotations is passed to the command (with the `--an

<!-- When used in combination with the `--save_video` flag, the tracked video will contain predicted bounding boxes in red, and ground-truth bounding boxes in green. -- PR 216-->

To see the full list of possible arguments to the `evaluate-detector` command, run it with the `--help` flag.

## Task-specific guides
For further information on specific tasks, such as launching a training job or evaluating a set of models in the HPC cluster, please see [our guides](guides).

Expand Down
28 changes: 21 additions & 7 deletions crabs/tracker/track_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, args: argparse.Namespace) -> None:

# input video data
self.input_video_path = args.video_path
self.input_video_file_root = f"{Path(self.input_video_path).stem}"
self.input_video_file_root = Path(self.input_video_path).stem

# tracking output directory root name
self.tracking_output_dir_root = args.output_dir
Expand All @@ -92,15 +92,19 @@ def prep_outputs(self):
This method:
- creates a timestamped directory to store the tracking output.
Optionally the timestamp can be omitted.
- sets the name of the output csv file for the tracked bounding boxes.
- sets up the output video path if required.
- sets up the frames subdirectory path if required.
"""
# Create output directory
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
self.tracking_output_dir = Path(
self.tracking_output_dir_root + f"_{timestamp}"
)
if self.args.output_dir_no_timestamp:
self.tracking_output_dir = Path(self.tracking_output_dir_root)
else:
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
self.tracking_output_dir = Path(
self.tracking_output_dir_root + f"_{timestamp}"
)
self.tracking_output_dir.mkdir(parents=True, exist_ok=True)

# Set name of output csv file
Expand Down Expand Up @@ -366,13 +370,23 @@ def tracking_parse_args(args):
default="tracking_output",
help=(
"Root name of the directory to save the tracking output. "
"The name of the output directory is appended with a timestamp. "
"By default, the name of the output directory is appended with "
"a timestamp. The timestamp can be omitted with the "
"--output_dir_no_timestamp flag. "
"The tracking output consist of a .csv. file named "
"<video-name>_tracks.csv with the tracked bounding boxes. "
"Optionally, it can include a video file named "
"<video-name>_tracks.mp4, and all frames from the video "
"under a <video-name>_frames subdirectory. "
"Default: ./tracking_output_<timestamp>. "
"Default: tracking_output_<timestamp>. "
),
)
parser.add_argument(
"--output_dir_no_timestamp",
action="store_true",
help=(
"Flag to disable appending a timestamp to the output "
"directory name. "
),
)
parser.add_argument(
Expand Down
Loading

0 comments on commit 1cdb184

Please sign in to comment.