fnet.utils package

Submodules

fnet.utils.general_utils module

fnet.utils.general_utils.add_augmentations(df: pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame[source]

Adds augmented versions of dataframe rows.

This is intended to be used on dataframes that represent datasets. Two columns will be added: flip_y, flip_x. Each dataframe row will be replicated 3 more times with flip_y, flip_x, or both columns set to 1.

Parameters

df – Dataset dataframe to be augmented.

Returns

Augmented dataset dataframe.

Return type

pd.DataFrame

fnet.utils.general_utils.add_logging_file_handler(path_save: pathlib.Path) → None[source]

Adds a file handler to fnet logger.

Parameters

path_save – Location to save logging records.

Returns

Return type

None

fnet.utils.general_utils.create_formatter()[source]

Creates a default logging Formatter.

fnet.utils.general_utils.files_from_dir(path_dir: str, extensions: Optional[Sequence[str]] = None) → List[str][source]

Returns sorted list of files in a directory with optional extension(s).

Parameters
  • path_dir – Input directory.

  • extensions – Optional file extensions.

fnet.utils.general_utils.get_args()[source]

Returns the arguments passed to the calling function.

Example:

>>> def foo(a, b, *args, **kwargs):
...     print(get_args())
...
>>> foo(1, 2, 3, 'bar', fizz='buzz')
({'b': 2, 'a': 1, 'fizz': 'buzz'}, (3, 'bar'))

References: kbyanc.blogspot.com/2007/07/python-aggregating-function-arguments.html

Returns

  • dict – Named arguments

  • list – Unnamed positional arguments

fnet.utils.general_utils.init_fnet_logging() → None[source]

Initializes logging for fnet.

Parameters

path_save – Location to save logging records.

Returns

Return type

None

fnet.utils.general_utils.retry_if_oserror(fn: Callable)[source]

Retries input function if an OSError is encountered.

fnet.utils.general_utils.str_to_class(string: str)[source]

Return class from string representation.

fnet.utils.general_utils.str_to_object(str_o: str)[source]

Get object from string.

Parameters

str_o – Fully qualified object name.

fnet.utils.general_utils.to_objects(slist)[source]

Get a list of objects from list of object __repr__s.

fnet.utils.general_utils.whats_my_name(obj: object)[source]

Returns object’s name.

fnet.utils.model_utils module

fnet.utils.model_utils.move_optim(optim: torch.optim.optimizer.Optimizer, device: torch.device)[source]

Moves optimizer parameters to specified device.

fnet.utils.split_dataset module

fnet.utils.split_dataset.int_or_float(x)[source]
fnet.utils.split_dataset.main()[source]

fnet.utils.viz_utils module

Visualization tools.

fnet.utils.viz_utils.plot_loss(paths_model: Union[List[str], str], path_save: Optional[str] = None, train: bool = True, val: bool = True, title: Optional[str] = None, ymin: Optional[float] = None, ymax: Optional[float] = None) → None[source]

Plots model loss curve(s).

Parameters
  • paths_model – List of paths to model directories specified as a list or as a string of paths separated by spaces.

  • path_save – If not None, specifies where to save figure and figure will not be displayed.

  • train – Set to plot training curve.

  • val – Set to plot validation curve.

  • title – Plot title.

  • ymin – Y-axis minimum value.

  • ymax – Y-axis maximum value.

fnet.utils.viz_utils.plot_metric(path_csv: str, metric: str, path_save: Optional[str] = None, title: Optional[str] = None, ymin: Optional[float] = None, ymax: Optional[float] = None) → None[source]

Plots box-plot of model performance according to some metric.

Parameters
  • path_csv – Path to csv where each row is a dataset item.

  • metric – Name of metric. Should be within one or more CSV column names.

  • path_save – If not None, specifies where to save figure and figure will not be displayed.

  • title – Plot title.

  • ymin – Y-axis minimum value.

  • ymax – Y-axis maximum value.

Module contents