Skip to content

Commit

Permalink
Reverted �iew_ back to save_ and changed new training checkbox to Kee…
Browse files Browse the repository at this point in the history
…p visualization images after training.
  • Loading branch information
hajin-park committed Jul 1, 2024
1 parent ad06cf5 commit c75a0ef
Show file tree
Hide file tree
Showing 29 changed files with 91 additions and 91 deletions.
10 changes: 5 additions & 5 deletions docs/guides/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ optional arguments:

```none
usage: sleap-train [-h] [--video-paths VIDEO_PATHS] [--val_labels VAL_LABELS]
[--test_labels TEST_LABELS] [--tensorboard] [--view_viz]
[--delete_viz] [--zmq] [--run_name RUN_NAME] [--prefix PREFIX]
[--test_labels TEST_LABELS] [--tensorboard] [--save_viz]
[--keep_viz] [--zmq] [--run_name RUN_NAME] [--prefix PREFIX]
[--suffix SUFFIX]
training_job_path [labels_path]
Expand Down Expand Up @@ -65,11 +65,11 @@ optional arguments:
to resume training from.
--tensorboard Enable TensorBoard logging to the run path if not
already specified in the training job config.
--view_viz Enable saving of prediction visualizations to the run
--save_viz Enable saving of prediction visualizations to the run
folder if not already specified in the training job
config.
--delete_viz Delete prediction visualizations in the run
folder after training if view_viz is enabled.
--keep_viz Keep prediction visualization images in the run
folder after training when save_viz is enabled.
--zmq Enable ZMQ logging (for GUI) if not already specified
in the training job config.
--run_name RUN_NAME Run name to use when saving file, overrides other run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
" \"test_labels\": null,\n",
" \"base_checkpoint\": null,\n",
" \"tensorboard\": false,\n",
" \"view_viz\": false,\n",
" \"save_viz\": false,\n",
" \"zmq\": false,\n",
" \"run_name\": \"courtship.centroid\",\n",
" \"prefix\": \"\",\n",
Expand Down Expand Up @@ -335,7 +335,7 @@
" \"runs_folder\": \"models\",\n",
" \"tags\": [],\n",
" \"save_visualizations\": true,\n",
" \"delete_viz_images\": true,\n",
" \"keep_viz_images\": true,\n",
" \"zip_outputs\": false,\n",
" \"log_to_csv\": true,\n",
" \"checkpointing\": {\n",
Expand Down Expand Up @@ -581,7 +581,7 @@
" \"test_labels\": null,\n",
" \"base_checkpoint\": null,\n",
" \"tensorboard\": false,\n",
" \"view_viz\": false,\n",
" \"save_viz\": false,\n",
" \"zmq\": false,\n",
" \"run_name\": \"courtship.topdown_confmaps\",\n",
" \"prefix\": \"\",\n",
Expand Down Expand Up @@ -727,7 +727,7 @@
" \"runs_folder\": \"models\",\n",
" \"tags\": [],\n",
" \"save_visualizations\": true,\n",
" \"delete_viz_images\": true,\n",
" \"keep_viz_images\": true,\n",
" \"zip_outputs\": false,\n",
" \"log_to_csv\": true,\n",
" \"checkpointing\": {\n",
Expand Down
8 changes: 4 additions & 4 deletions sleap/config/pipeline_form.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ training:
name: outputs.tensorboard.write_logs
type: bool

- name: _view_viz
- name: _save_viz
label: Visualize Predictions During Training
type: bool
default: true

- name: _delete_viz
label: Delete Prediction Visualizations After Training
- name: _keep_viz
label: Keep Prediction Visualization Images After Training
type: bool
default: true
default: false

- name: _predict_frames
label: Predict On
Expand Down
34 changes: 17 additions & 17 deletions sleap/gui/learning/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ def run_learning_pipeline(
"""

view_viz = inference_params.get("_view_viz", False)
delete_viz = inference_params.get("_delete_viz", False)
save_viz = inference_params.get("_save_viz", False)
keep_viz = inference_params.get("_keep_viz", False)

if "movenet" in inference_params["_pipeline"]:
trained_job_paths = [inference_params["_pipeline"]]
Expand All @@ -560,8 +560,8 @@ def run_learning_pipeline(
config_info_list=config_info_list,
inference_params=inference_params,
gui=True,
view_viz=view_viz,
delete_viz=delete_viz,
save_viz=save_viz,
keep_viz=keep_viz,
)

# Check that all the models were trained
Expand Down Expand Up @@ -589,8 +589,8 @@ def run_gui_training(
config_info_list: List[ConfigFileInfo],
inference_params: Dict[str, Any],
gui: bool = True,
view_viz: bool = False,
delete_viz: bool = True,
save_viz: bool = False,
keep_viz: bool = False,
) -> Dict[Text, Text]:
"""
Runs training for each training job.
Expand All @@ -599,8 +599,8 @@ def run_gui_training(
labels: Labels object from which we'll get training data.
config_info_list: List of ConfigFileInfo with configs for training.
gui: Whether to show gui windows and process gui events.
view_viz: Whether to save visualizations from training.
delete_viz: Whether to delete prediction visualizations after training.
save_viz: Whether to save visualizations from training.
keep_viz: Whether to keep prediction visualization images after training.
Returns:
Dictionary, keys are head name, values are path to trained config.
Expand Down Expand Up @@ -667,7 +667,7 @@ def run_gui_training(
win.reset(what=str(model_type), config=job)
win.setWindowTitle(f"Training Model - {str(model_type)}")
win.set_message(f"Preparing to run training...")
if view_viz:
if save_viz:
viz_window = QtImageDirectoryWidget.make_training_vizualizer(
job.outputs.run_path
)
Expand All @@ -689,8 +689,8 @@ def waiting():
labels_filename=labels_filename,
video_paths=video_path_list,
waiting_callback=waiting,
view_viz=view_viz,
delete_viz=delete_viz,
save_viz=save_viz,
keep_viz=keep_viz,
)

if ret == "success":
Expand Down Expand Up @@ -832,8 +832,8 @@ def train_subprocess(
inference_params: Dict[str, Any],
video_paths: Optional[List[Text]] = None,
waiting_callback: Optional[Callable] = None,
view_viz: bool = False,
delete_viz: bool = True,
save_viz: bool = False,
keep_viz: bool = False,
):
"""Runs training inside subprocess."""
run_path = job_config.outputs.run_path
Expand All @@ -860,10 +860,10 @@ def train_subprocess(
str(inference_params["publish_port"]),
]

if view_viz:
cli_args.append("--view_viz")
if delete_viz:
cli_args.append("--delete_viz")
if save_viz:
cli_args.append("--save_viz")
if keep_viz:
cli_args.append("--keep_viz")

# Use cli arg since cli ignores setting in config
if job_config.outputs.tensorboard.write_logs:
Expand Down
10 changes: 5 additions & 5 deletions sleap/nn/config/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ class OutputsConfig:
tags: A list of strings to use as "tags" that can be used to organize multiple
runs. These are not used for anything during training or inference, so they
can be used to store arbitrary user-specified metadata.
view_visualizations: If True, will render and save visualizations of the model
save_visualizations: If True, will render and save visualizations of the model
predictions as PNGs to "{run_folder}/viz/{split}.{epoch:04d}.png", where the
split is one of "train", "validation", "test".
delete_viz_images: If True, delete the saved visualizations after training
completes. This is useful to reduce the model folder size if you do not need
keep_viz_images: If True, keep the saved visualization images after training
completes. This is useful unchecked to reduce the model folder size if you do not need
to keep the visualization images.
zip_outputs: If True, compress the run folder to a zip file. This will be named
"{run_folder}.zip".
Expand All @@ -169,8 +169,8 @@ class OutputsConfig:
run_name_suffix: Optional[Text] = None
runs_folder: Text = "models"
tags: List[Text] = attr.ib(factory=list)
view_visualizations: bool = True
delete_viz_images: bool = True
save_visualizations: bool = True
keep_viz_images: bool = False
zip_outputs: bool = False
log_to_csv: bool = True
checkpointing: CheckpointingConfig = attr.ib(factory=CheckpointingConfig)
Expand Down
20 changes: 10 additions & 10 deletions sleap/nn/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def setup_visualization(
"This probably means Qt is running headless."
)

if config.view_visualizations and config.save_outputs:
if config.save_visualizations and config.save_outputs:
callbacks.append(
MatplotlibSaver(
save_folder=os.path.join(run_path, "viz"), plot_fn=viz_fn, prefix=name
Expand Down Expand Up @@ -945,8 +945,8 @@ def train(self):
# Run post-training actions.
if self.config.outputs.save_outputs:
if (
self.config.outputs.view_visualizations
and self.config.outputs.delete_viz_images
self.config.outputs.save_visualizations
and not self.config.outputs.keep_viz_images
):
self.cleanup()

Expand Down Expand Up @@ -997,7 +997,7 @@ def cleanup(self):

def package(self):
"""Package model folder into a zip file for portability."""
if self.config.outputs.delete_viz_images:
if not self.config.outputs.keep_viz_images:
self.cleanup()
logger.info(f"Packaging results to: {self.run_path}.zip")
shutil.make_archive(
Expand Down Expand Up @@ -1857,19 +1857,19 @@ def create_trainer_using_cli(args: Optional[List] = None):
),
)
parser.add_argument(
"--view_viz",
"--save_viz",
action="store_true",
help=(
"Enable saving of prediction visualizations to the run folder if not "
"already specified in the training job config."
),
)
parser.add_argument(
"--delete_viz",
"--keep_viz",
action="store_true",
help=(
"Delete prediction visualizations in the run folder after training if "
"view_viz is enabled."
"Keep prediction visualization images in the run folder after training when "
"save_viz is enabled."
),
)
parser.add_argument(
Expand Down Expand Up @@ -1956,8 +1956,8 @@ def create_trainer_using_cli(args: Optional[List] = None):
job_config.outputs.run_name_prefix = args.prefix
if args.suffix != "":
job_config.outputs.run_name_suffix = args.suffix
job_config.outputs.view_visualizations |= args.view_viz
job_config.outputs.delete_viz_images |= args.delete_viz
job_config.outputs.save_visualizations |= args.save_viz
job_config.outputs.keep_viz_images |= args.keep_viz
if args.labels_path == "":
args.labels_path = None
args.video_paths = args.video_paths.split(",")
Expand Down
4 changes: 2 additions & 2 deletions sleap/training_profiles/baseline.centroid.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
"run_name_suffix": null,
"runs_folder": "models",
"tags": [],
"view_visualizations": true,
"delete_viz_images": true,
"save_visualizations": true,
"keep_viz_images": false,
"log_to_csv": true,
"checkpointing": {
"initial_model": false,
Expand Down
4 changes: 2 additions & 2 deletions sleap/training_profiles/baseline_large_rf.bottomup.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@
"run_name_suffix": null,
"runs_folder": "models",
"tags": [],
"view_visualizations": true,
"delete_viz_images": true,
"save_visualizations": true,
"keep_viz_images": false,
"log_to_csv": true,
"checkpointing": {
"initial_model": false,
Expand Down
4 changes: 2 additions & 2 deletions sleap/training_profiles/baseline_large_rf.single.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
"run_name_suffix": null,
"runs_folder": "models",
"tags": [],
"view_visualizations": true,
"delete_viz_images": true,
"save_visualizations": true,
"keep_viz_images": false,
"log_to_csv": true,
"checkpointing": {
"initial_model": false,
Expand Down
4 changes: 2 additions & 2 deletions sleap/training_profiles/baseline_large_rf.topdown.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
"run_name_suffix": null,
"runs_folder": "models",
"tags": [],
"view_visualizations": true,
"delete_viz_images": true,
"save_visualizations": true,
"keep_viz_images": false,
"log_to_csv": true,
"checkpointing": {
"initial_model": false,
Expand Down
4 changes: 2 additions & 2 deletions sleap/training_profiles/baseline_medium_rf.bottomup.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@
"run_name_suffix": null,
"runs_folder": "models",
"tags": [],
"view_visualizations": true,
"delete_viz_images": true,
"save_visualizations": true,
"keep_viz_images": false,
"log_to_csv": true,
"checkpointing": {
"initial_model": false,
Expand Down
4 changes: 2 additions & 2 deletions sleap/training_profiles/baseline_medium_rf.single.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
"run_name_suffix": null,
"runs_folder": "models",
"tags": [],
"view_visualizations": true,
"delete_viz_images": true,
"save_visualizations": true,
"keep_viz_images": false,
"log_to_csv": true,
"checkpointing": {
"initial_model": false,
Expand Down
4 changes: 2 additions & 2 deletions sleap/training_profiles/baseline_medium_rf.topdown.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
"run_name_suffix": null,
"runs_folder": "models",
"tags": [],
"view_visualizations": true,
"delete_viz_images": true,
"save_visualizations": true,
"keep_viz_images": false,
"log_to_csv": true,
"checkpointing": {
"initial_model": false,
Expand Down
4 changes: 2 additions & 2 deletions sleap/training_profiles/pretrained.bottomup.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
"run_name_suffix": null,
"runs_folder": "models",
"tags": [],
"view_visualizations": true,
"delete_viz_images": true,
"save_visualizations": true,
"keep_viz_images": false,
"log_to_csv": true,
"checkpointing": {
"initial_model": false,
Expand Down
4 changes: 2 additions & 2 deletions sleap/training_profiles/pretrained.centroid.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
"run_name_suffix": null,
"runs_folder": "models",
"tags": [],
"view_visualizations": true,
"delete_viz_images": true,
"save_visualizations": true,
"keep_viz_images": false,
"log_to_csv": true,
"checkpointing": {
"initial_model": false,
Expand Down
4 changes: 2 additions & 2 deletions sleap/training_profiles/pretrained.single.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
"run_name_suffix": null,
"runs_folder": "models",
"tags": [],
"view_visualizations": true,
"delete_viz_images": true,
"save_visualizations": true,
"keep_viz_images": false,
"log_to_csv": true,
"checkpointing": {
"initial_model": false,
Expand Down
4 changes: 2 additions & 2 deletions sleap/training_profiles/pretrained.topdown.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
"run_name_suffix": null,
"runs_folder": "models",
"tags": [],
"view_visualizations": true,
"delete_viz_images": true,
"save_visualizations": true,
"keep_viz_images": false,
"log_to_csv": true,
"checkpointing": {
"initial_model": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@
"run_name_suffix": null,
"runs_folder": "models",
"tags": [],
"view_visualizations": false,
"delete_viz_images": false,
"save_visualizations": false,
"keep_viz_images": true,
"log_to_csv": true,
"checkpointing": {
"initial_model": false,
Expand Down
Loading

0 comments on commit c75a0ef

Please sign in to comment.