Reference#

flyswot.cli#

flyswot command line

flyswot.cli.main()#

flyswot command line application

Return type:

None

flyswot.models#

Model Commands.

class flyswot.models.LocalModel(hf_cache)#

A local model container

Parameters:

hf_cache (Path) –

flyswot.models.create_markdown_model_card(model_id)#

Creates rich Markdown wrapper for hub readme

Parameters:

model_id (str) –

flyswot.models.create_metrics_tables(model_info)#

Creates a list of rich tables for metrics contained in model_info

Parameters:

model_info (ModelInfo) –

Return type:

List[Table]

flyswot.models.ensure_model(model_dir)#

Checks for a local model and if not found downloads the latest available remote model

Parameters:

model_dir (Path) –

Return type:

LocalModel

flyswot.models.ensure_model_dir(model_dir_path=None)#

Checks for a local model dir and creates one if not found

Parameters:

model_dir_path (Path | None) –

Return type:

Path

flyswot.models.get_model(revision=<typer.models.ArgumentInfo object>, model_dir=<typer.models.ArgumentInfo object>, local_only=False)#

Downloads models, defaults to the latest available model

Parameters:
  • revision (str | None) –

  • model_dir (Path) –

Return type:

Path

Creates rich link for model card

Parameters:

model_id (str) –

Return type:

str

flyswot.models.is_pipe(c)#

Checks if | in c

Parameters:

c (Tuple) –

Return type:

bool

flyswot.models.load_vocab(vocab)#

loads vocab from vocab and returns as list contaning lists of vocab

Parameters:

vocab (Path) –

Return type:

List[List[str]]

flyswot.models.show_model_card(localmodel)#

Shows model card for model

Parameters:

localmodel (LocalModel) –

flyswot.models.show_model_dir()#

Print out the directory where models are stored

Return type:

None

flyswot.models.vocab(model=<typer.models.ArgumentInfo object>, show=<typer.models.OptionInfo object>)#

Prints out vocab for latest model

Parameters:
  • model (str) –

  • show (bool) –

flyswot.inference#

Core inference functionality.

class flyswot.inference.ImagePredictionArgmaxItem(path, predicted_label, confidence)#

Most confident predicted label for an item.

Parameters:
  • path (Path) –

  • predicted_label (str) –

  • confidence (float) –

path#

The Path to the image

Type:

pathlib.Path

predicted_label#

The predicted label i.e. the argmax value for the prediction tensor

Type:

str

confidence#

The confidence for predicted_label i.e. the max value for prediction tensor

Type:

float

class flyswot.inference.InferenceSession(model)#

Abstract class for inference sessions

Parameters:

model (str | Path) –

abstract predict_batch(model, batch, bs)#

Predict a batch

Parameters:
  • model (Path) –

  • batch (Iterable[Path]) –

  • bs (int) –

abstract predict_image(image)#

Predict a single image

Parameters:

image (Path) –

class flyswot.inference.MultiLabelImagePredictionItem(path, predictions)#

Multiple predictions for a single image

Parameters:
  • path (Path) –

  • predictions (List[Dict[float, str]]) –

class flyswot.inference.MultiPredictionBatch(batch)#

Container for MultiLabelImagePredictionItems

Parameters:

batch (List[MultiLabelImagePredictionItem]) –

class flyswot.inference.PredictionBatch(batch)#

Container for ImagePredictionItems

Parameters:

batch (List[ImagePredictionArgmaxItem]) –

flyswot.core#

Core functionality.

flyswot.core.count_files_with_ext(directory, ext)#

Counts files matching extension in directory

Parameters:
  • directory (Path) –

  • ext (str) –

Return type:

int

flyswot.core.create_file_search_message(directory, pattern, ext)#

Creates a message to show pattern and ext used for search

Parameters:
  • directory (Path) –

  • pattern (str | None) –

  • ext (str | None) –

Return type:

str

flyswot.core.file_can_be_read(path)#

Checks if a file can be opened.

Return type:

bool

flyswot.core.filter_readable_files(files)#

Yields all readable files from files.

Parameters:

files (Iterator[Path]) –

Return type:

Iterator[Path]

flyswot.core.filter_to_preferred_ext(files, exts)#

Filter files to preferred extension.

Parameters:
  • files (Iterable[Path]) –

  • exts (List[str]) –

Return type:

Iterable[Path]

flyswot.core.get_image_files_from_pattern(directory, filename_pattern=None, image_formats=None, check_opens=True)#

yield image files from directory matching pattern with ext

Parameters:
  • directory (Path) –

  • filename_pattern (str | None) –

  • image_formats (str | Set[str]) –

  • check_opens (bool) –

Return type:

Iterator[Path]

flyswot.core.signal_last(it)#

returns original iterator and iterator yield false until last item in iterator

Parameters:

it (Iterable[Any]) –

Return type:

Iterable[Tuple[bool, Any]]

flyswot.core.yield_all_files(directory)#

Yield all files recursively from directory.

Parameters:

directory (Path) –

Return type:

Iterator[Path]

flyswot.config#

configuration file

flyswot.console#

Console