camfi.cli module¶
Defines command-line interface to Camfi.
- class camfi.cli.Commander(config_path: Optional[pathlib.Path], input_file: Optional[pathlib.Path] = None, root: Optional[pathlib.Path] = None, output: Optional[pathlib.Path] = None, disable_progress_bar: Optional[bool] = None, vprint: Callable = <function _vprint>, vvprint: Callable = <function _qprint>)¶
Bases:
objectDefines commands for camfi cli. Any command defined on this class can be called by providing them as command-line arguments to
camfi.- __call__(command: str) None¶
Calls method of self corresponding to command.
- Parameters
command (str) – Name of command to call. These are the same as the methods defined on this class. Any “-” characters are converted to “_” charaters.
- __init__(config_path: Optional[pathlib.Path], input_file: Optional[pathlib.Path] = None, root: Optional[pathlib.Path] = None, output: Optional[pathlib.Path] = None, disable_progress_bar: Optional[bool] = None, vprint: Callable = <function _vprint>, vvprint: Callable = <function _qprint>)¶
Parses config_path file into self.config : camfi.projectconfig.CamfiConfig.
- Parameters
config_path (Optional[Path]) – Path to configuration file. Can be JSON (.json) or StrictYAML (.yaml|.yml).
input_file (Optional[Path]) – Path to VIA project file. If set,
self.config.via_project_filewill be overwritten with this value.root (Optional[Path]) – Path to root directory containing all images. If set,
self.config.rootwill be overwritten with this value.output (Optional[Path]) – If set,
self.config.default_outputwill be overwritten with this value.disable_progress_bar (Optional[bool]) – Option to force progress bars to be hidden or shown. If set,
self.config.disable_project_barwill be overwritten with this value.vprint (Callable) – Called for verbose printing.
vvprint (Callable) – Called for very verbose printing.
- __weakref__¶
list of weak references to the object (if defined)
- annotate() None¶
Performs automatic annotation on all the images in via_project, outputting the resulting annotated VIA project file to the configured
output_pathspecified underannotator.inferencein the configuration file. Requiresannotator.inferenceto be configured. While not strictly required,annotator.inference.output_pathshould be configured, otherwise the result of annotation will not be saved before the program terminates (and this is probably not what you want). Alternatively, you can configuredefault_outputeither in the configuration file or by using the-o/--outputflag.
- classmethod cmds() dict¶
Returns the commands defined by this class.
- Returns
commands – Dictionary with command names mapped to command docstrings.
- Return type
dict[str, str]
- do_nothing() None¶
Does nothing, except parse options and configuration. This can be useful if all you want to do is validate and/or convert the configuration file. This is the default command which is run when
camfiis called.
- extract_wingbeats() None¶
Runs the Camfi algorithm to extract wingbeat data from all images in the VIA project, inserting that data into the project in-place. Requires
cameraandwingbeat_extractionto be configured.
- filelist() None¶
Lists the images in the VIA project to stdout or file (set using
default_outputconfiguration parameter or-o/--output).
- filter_images() None¶
Applies filters to exclude images from VIA project. Operates in-place on the VIA project. Does nothing if
filters.image_filtersisn’t configured.
- filter_regions() None¶
Applies filters to exclude regions (annotations) from VIA project. Operates in-place on the VIA project. Does nothing if
filters.region_filtersisn’t configured.
- image_table() None¶
Produces a table with one row per image, with various image metadata columns, including n_annotations (the number of annotations in the image). Table is written to stout or file (set using
default_outputconfiguration parameter or-o/--output).
- load_exif() None¶
Loads EXIF metadata into VIA project in-place after reading it from file. If
time(and optionallycamera) are configured, then this will also insert location and corrected timestamp metadata.
- region_table() None¶
Produces a table with one row per region (annotation). Table is written to stout or file (set using
default_outputconfiguration parameter or-o/--output).
- table() None¶
Similar to
image-table, but includes weather and sun time columns. Produces a table with one row per image, with various image metadata columns, including n_annotations (the number of annotations in the image). Table is written to stout or file (set usingdefault_outputconfiguration parameter or-o/--output).
- train() None¶
Trains a camfi instance segmentation annotation model on manually annotated dataset, saving to trained model to the
outdirconfigured underannotator.training. Requiresannotator.trainingto be configured. Ifannotator.inferenceis configured, but under itmodelhas not been explicitely set, then after the model is trainedmodelofannotator.inferencewill be set to the newly trained model. This means that with proper configuration,trainandannotatecan be strung together in one command (i.e.camfi train annotate).
- validate() None¶
Validates automatically aquired annotations against ground-truth annotations, saving the results to the
output_dirconfigured underannotator.validation. Requiresannotator.validationto be configured. While not strictly required,annotator.validation.output_dirshould be configured, otherwise the result of validation will not be saved before the program terminates (and this is probably not what you want). Ifimage_setunderannotator.validationcontains “train” or “test”, thentest_set(ortest_set_file) underannotator.trainingshould also be configured. Ifannotator.trainingis not set, then the “train”image_setwill be equivalent to “all”, and “test” will be an empty set of images. It is also possible to leaveautoannotated_via_project_fileunderannotator.validationunconfigured. In this case, theoutput_pathfromannotation.inferencewill be validated (so at least one of these must be configured). Alternatively, you can configuredefault_outputeither in the configuration file or by using the-o/--outputflag.
- write() None¶
Writes VIA project to stdout or file (set using
default_outputconfiguration parameter or-o/--output). Can be used after other commands which act in-place on the VIA project (e.g.load-exif,extract-wingbeatsandapply-filters). Prints to stdout if no output is given.
- zip_images() None¶
Makes a zip archive of all the images in the VIA project file (
default_outputconfiguration parameter or-o/--outputmust be set).
- exception camfi.cli.ConfigParseError¶
Bases:
ExceptionRaised if config parsing fails.
- __weakref__¶
list of weak references to the object (if defined)
- camfi.cli.get_argument_parser(show_rst: bool = True) argparse.ArgumentParser¶
Defines arguments to the
camficommand.- Parameters
show_rst (bool) – If False, reStructuredText will be ommitted from description and epilog.
- Returns
parser – Command-line argument parser for
camfi.- Return type
ArgumentParser