openvinotoolkit / anomalib

An anomaly detection library comprising state-of-the-art algorithms and features such as experiment management, hyper-parameter optimization, and edge inference.
https://anomalib.readthedocs.io/en/latest/
Apache License 2.0
3.4k stars 614 forks source link

[Task]: Missing modules may fail silently #2154

Open djdameln opened 1 week ago

djdameln commented 1 week ago

What is the motivation for this task?

Missing modules may go unnoticed due to the exception handling at the top of cli.py here.

When one of the imports in lines 28 to 35 fails due to a missing module, anomalib gives the following output, hiding the issue from the user:

anomalib train --model Padim --data MVTec
To use other subcommand using `anomalib install`
Usage: anomalib [-h] [-c CONFIG] [--print_config [=flags]] {install} ...
error: argument subcommand: invalid choice: 'train' (choose from 'install')

I guess this is intended to check if anomalib install has previously been called. But the above behaviour may also occur when anomalib install has been called, but a required package is missing in the environment. In this case it would be better to let the user know which package is missing.


To reproduce, add an import to one of the submodules of anomalib, e.g. add import missing_package to this file, and then try to call the training entrypoint of the CLI.

Describe the solution you'd like

The user should be notified about the missing module.

Additional context

No response