Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ”¨ Allow string types in CLI enums #1640

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ init_args:
train_batch_size: 32
eval_batch_size: 32
num_workers: 8
task: CLASSIFICATION
task: classification
transform_config_train: null
transform_config_eval: null
test_split_mode: FROM_DIR
test_split_mode: from_dir
test_split_ratio: 0.2
val_split_mode: SAME_AS_TEST
val_split_mode: same_as_test
val_split_ratio: 0.5
seed: null
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ init_args:
normalization: imagenet
val_split_mode: NONE
test_split_mode: NONE
task: CLASSIFICATION
task: classification
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ init_args:
normal_dir: "good"
normalization: imagenet
test_split_mode: SYNTHETIC
task: CLASSIFICATION
task: classification
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ init_args:
train_batch_size: 32
eval_batch_size: 32
num_workers: 8
task: SEGMENTATION
task: segmentation
transform_config_train: null
transform_config_eval: null
test_split_mode: SYNTHETIC
test_split_ratio: 0.2
val_split_mode: SAME_AS_TEST
val_split_mode: same_as_test
val_split_ratio: 0.5
seed: null
4 changes: 2 additions & 2 deletions src/anomalib/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ def add_arguments_to_parser(self, parser: LightningArgumentParser) -> None:
parser.add_function_arguments(get_normalization_callback, "normalization")
# visualization takes task from the project
parser.add_function_arguments(get_visualization_callbacks, "visualization", skip={"task"})
parser.add_argument("--task", type=TaskType, default=TaskType.SEGMENTATION)
parser.add_argument("--task", type=TaskType | str, default=TaskType.SEGMENTATION)
parser.add_argument("--metrics.image", type=list[str] | str | None, default=["F1Score", "AUROC"])
parser.add_argument("--metrics.pixel", type=list[str] | str | None, default=None, required=False)
parser.add_argument("--metrics.threshold", type=BaseThreshold, default="F1AdaptiveThreshold")
parser.add_argument("--metrics.threshold", type=BaseThreshold | str, default="F1AdaptiveThreshold")
parser.add_argument("--logging.log_graph", type=bool, help="Log the model to the logger", default=False)
if hasattr(parser, "subcommand") and parser.subcommand != "predict": # Predict also accepts str and Path inputs
parser.link_arguments("data.init_args.image_size", "model.init_args.input_size")
Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __init__(
| ListConfig
| list[dict[str, str | float]]
| str = "F1AdaptiveThreshold",
task: TaskType = TaskType.SEGMENTATION,
task: TaskType | str = TaskType.SEGMENTATION,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering if we should call this task_type instead of task, as task could also refer to an entity that actually performs some learning or inference related behaviour (as we see in some other libraries). task_type is less ambiguous.

image_metrics: str | list[str] | None = None,
pixel_metrics: str | list[str] | None = None,
visualization: DictConfig | dict[str, Any] | Namespace | None = None,
Expand All @@ -139,7 +139,7 @@ def __init__(
self._cache = _TrainerArgumentsCache(callbacks=[*callbacks], **kwargs)
self.normalization = normalization
self.threshold = threshold
self.task = task
self.task = TaskType(task)
self.image_metric_names = image_metrics
self.pixel_metric_names = pixel_metrics
self.visualization = visualization
Expand Down
2 changes: 1 addition & 1 deletion src/configs/data/avenue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ init_args:
gt_dir: ./datasets/avenue/masks
clip_length_in_frames: 1
frames_between_clips: 1
target_frame: LAST
target_frame: last
image_size: [256, 256]
center_crop: null
normalization: imagenet
Expand Down
4 changes: 2 additions & 2 deletions src/configs/data/btech.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ init_args:
num_workers: 8
transform_config_train: null
transform_config_eval: null
test_split_mode: FROM_DIR
test_split_mode: from_dir
test_split_ratio: 0.2
val_split_mode: SAME_AS_TEST
val_split_mode: same_as_test
val_split_ratio: 0.5
seed: null
6 changes: 3 additions & 3 deletions src/configs/data/folder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ init_args:
train_batch_size: 32
eval_batch_size: 32
num_workers: 8
task: SEGMENTATION
task: segmentation
transform_config_train: null
transform_config_eval: null
test_split_mode: FROM_DIR
test_split_mode: from_dir
test_split_ratio: 0.2
val_split_mode: SAME_AS_TEST
val_split_mode: same_as_test
val_split_ratio: 0.5
seed: null
4 changes: 2 additions & 2 deletions src/configs/data/kolektor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ init_args:
num_workers: 8
transform_config_train: null
transform_config_eval: null
test_split_mode: FROM_DIR
test_split_mode: from_dir
test_split_ratio: 0.2
val_split_mode: SAME_AS_TEST
val_split_mode: same_as_test
val_split_ratio: 0.5
seed: null
6 changes: 3 additions & 3 deletions src/configs/data/mvtec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ init_args:
train_batch_size: 32
eval_batch_size: 32
num_workers: 8
task: SEGMENTATION
task: segmentation
transform_config_train: null
transform_config_eval: null
test_split_mode: FROM_DIR
test_split_mode: from_dir
test_split_ratio: 0.2
val_split_mode: SAME_AS_TEST
val_split_mode: same_as_test
val_split_ratio: 0.5
seed: null
4 changes: 2 additions & 2 deletions src/configs/data/mvtec_3d.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ init_args:
num_workers: 8
transform_config_train: null
transform_config_eval: null
test_split_mode: FROM_DIR
test_split_mode: from_dir
test_split_ratio: 0.2
val_split_mode: SAME_AS_TEST
val_split_mode: same_as_test
val_split_ratio: 0.5
seed: null
2 changes: 1 addition & 1 deletion src/configs/data/shanghaitec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ init_args:
scene: 1
clip_length_in_frames: 1
frames_between_clips: 1
target_frame: LAST
target_frame: last
image_size: [256, 256]
center_crop: null
normalization: imagenet
Expand Down
2 changes: 1 addition & 1 deletion src/configs/data/ucsd_ped.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ init_args:
category: "UCSDped2"
clip_length_in_frames: 2
frames_between_clips: 10
target_frame: LAST
target_frame: last
image_size: [256, 256]
center_crop: null
normalization: imagenet
Expand Down
4 changes: 2 additions & 2 deletions src/configs/data/visa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ init_args:
num_workers: 8
transform_config_train: null
transform_config_eval: null
test_split_mode: FROM_DIR
test_split_mode: from_dir
test_split_ratio: 0.2
val_split_mode: SAME_AS_TEST
val_split_mode: same_as_test
val_split_ratio: 0.5
seed: null
2 changes: 1 addition & 1 deletion src/configs/model/ai_vad.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ model:
n_neighbors_pose: 1
n_neighbors_deep: 1

task: DETECTION
task: detection
2 changes: 1 addition & 1 deletion src/configs/model/dfkde.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ model:
feature_scaling_method: SCALE
max_training_points: 40000

task: CLASSIFICATION
task: classification
2 changes: 1 addition & 1 deletion src/configs/model/ganomaly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ model:
beta1: 0.5
beta2: 0.999

task: CLASSIFICATION
task: classification

trainer:
max_epochs: 100
Expand Down
2 changes: 1 addition & 1 deletion src/configs/model/rkde.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ model:
feature_scaling_method: SCALE
max_training_points: 40000

task: DETECTION
task: detection
Loading