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

Create Anomalib CLI #378

Merged
merged 58 commits into from
Jun 24, 2022
Merged

Create Anomalib CLI #378

merged 58 commits into from
Jun 24, 2022

Conversation

samet-akcay
Copy link
Contributor

@samet-akcay samet-akcay commented Jun 16, 2022

Description

  • This is to add new anomalib cli that is based on pytorch lightning cli. With this design it'll be possible to tweak the parameters from both config files and cli simultaneously.

  • Fixes Refactor Anomalib CLI #21

Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the pre-commit style and check guidelines of this project.
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes

…notoolkit/anomalib into nb/sa/add-dataset-module-notebook
@samet-akcay samet-akcay requested review from ashwinvaidya17 and djdameln and removed request for ashwinvaidya17 June 20, 2022 13:39
@samet-akcay samet-akcay marked this pull request as ready for review June 20, 2022 13:39
@ashwinvaidya17
Copy link
Collaborator

Can you add commands to run the models to the README?

config/model/cflow.yaml Outdated Show resolved Hide resolved
anomalib/utils/cli/cli.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@ashwinvaidya17 ashwinvaidya17 left a comment

Choose a reason for hiding this comment

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

Thanks for the efforts. From the little exploration I've done, this is a cleaner approach.

anomalib/utils/cli/cli.py Show resolved Hide resolved
@samet-akcay
Copy link
Contributor Author

Can you add commands to run the models to the README?
@ashwinvaidya17, I only added the command for the training. I think the documentation needs a bit of more work. Need to double check the inference as well. I'll create a follow-up PR for this

Copy link
Collaborator

@ashwinvaidya17 ashwinvaidya17 left a comment

Choose a reason for hiding this comment

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

Thanks!

model_name = config.model.class_path.split(".")[-1].lower()
data_name = config.data.class_path.split(".")[-1].lower()
category = config.data.init_args.category if config.data.init_args.keys() else ""
time_stamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think about this time_stamp here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see an issue with it.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
anomalib/utils/cli/cli.py Outdated Show resolved Hide resolved
requirements/base.txt Show resolved Hide resolved
Comment on lines +99 to +108
parser.set_defaults(
{
"metrics.adaptive_threshold": True,
"metrics.default_image_threshold": None,
"metrics.default_pixel_threshold": None,
"metrics.image_metric_names": ["F1Score", "AUROC"],
"metrics.pixel_metric_names": ["F1Score", "AUROC"],
"metrics.normalization_method": "min_max",
}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm probably misunderstanding something, but why do we need to set the defaults? Aren't those parsed from the config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If they are provided in the config, yes, they are parsed from the config file. However, if the user does not provide those parameters from the config file, then this part sets these by default. With this approach it becomes also possible to configure these from the CLI as well.

}
)

def before_instantiate_classes(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is quite long and therefore a bit hard to navigate. Do you think you could split it between several smaller methods?

# TODO: This is a workaround. normalization-method is actually not used in metrics.
# It's only accessed from `before_instantiate` method in `AnomalibCLI` to configure
# its callback.
self.normalization_method = normalization_method
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand this. Maybe we could discuss it in the daily

@samet-akcay samet-akcay merged commit ef62199 into development Jun 24, 2022
@samet-akcay samet-akcay deleted the samet-akcay/issue21 branch June 24, 2022 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Anomalib CLI
3 participants