-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from ankandrew/dev-test
New models and Improved logging
- Loading branch information
Showing
10 changed files
with
242 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Config example for Latin plates from 70 countries | ||
|
||
# Max number of plate slots supported. This represents the number of model classification heads. | ||
max_plate_slots: 9 | ||
# All the possible character set for the model output. | ||
alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_' | ||
# Padding character for plates which length is smaller than MAX_PLATE_SLOTS. It should still be present in the alphabet. | ||
pad_char: '_' | ||
# Image height which is fed to the model. | ||
img_height: 70 | ||
# Image width which is fed to the model. | ||
img_width: 140 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" | ||
Utils used for the CLI scripts. | ||
""" | ||
|
||
import inspect | ||
import pathlib | ||
from collections.abc import Callable | ||
from functools import wraps | ||
from typing import Any | ||
|
||
import albumentations as A | ||
from rich import box | ||
from rich.console import Console | ||
from rich.pretty import Pretty | ||
from rich.table import Table | ||
|
||
|
||
def print_variables_as_table( | ||
c1_title: str, c2_title: str, title: str = "Variables Table", **kwargs: Any | ||
) -> None: | ||
""" | ||
Prints variables in a formatted table using the rich library. | ||
Args: | ||
c1_title (str): Title of the first column. | ||
c2_title (str): Title of the second column. | ||
title (str): Title of the table. | ||
**kwargs (Any): Variable names and values to be printed. | ||
""" | ||
console = Console() | ||
console.print("\n") | ||
table = Table(title=title, show_header=True, header_style="bold blue", box=box.ROUNDED) | ||
table.add_column(c1_title, min_width=20, justify="left", style="bold") | ||
table.add_column(c2_title, min_width=60, justify="left", style="bold") | ||
|
||
for key, value in kwargs.items(): | ||
if isinstance(value, pathlib.Path): | ||
value = str(value) # noqa: PLW2901 | ||
table.add_row(f"[bold]{key}[/bold]", Pretty(value)) | ||
|
||
console.print(table) | ||
|
||
|
||
def print_params( | ||
table_title: str = "Parameters Table", c1_title: str = "Variable", c2_title: str = "Value" | ||
) -> Callable: | ||
""" | ||
A decorator that prints the parameters of a function in a formatted table | ||
using the rich library. | ||
Args: | ||
c1_title (str, optional): Title of the first column. Defaults to "Variable". | ||
c2_title (str, optional): Title of the second column. Defaults to "Value". | ||
table_title (str, optional): Title of the table. Defaults to "Parameters Table". | ||
Returns: | ||
Callable: The wrapped function with parameter printing functionality. | ||
""" | ||
|
||
def decorator(func: Callable) -> Callable: | ||
@wraps(func) | ||
def wrapper(*args: Any, **kwargs: Any) -> Any: | ||
func_signature = inspect.signature(func) | ||
bound_arguments = func_signature.bind(*args, **kwargs) | ||
bound_arguments.apply_defaults() | ||
params = dict(bound_arguments.arguments.items()) | ||
print_variables_as_table(c1_title, c2_title, table_title, **params) | ||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return decorator | ||
|
||
|
||
def print_train_details(augmentation: A.Compose, config: dict[str, Any]) -> None: | ||
console = Console() | ||
console.print("\n") | ||
console.print("[bold blue]Augmentation Pipeline:[/bold blue]") | ||
console.print(Pretty(augmentation)) | ||
console.print("\n") | ||
console.print("[bold blue]Configuration:[/bold blue]") | ||
console.print(Pretty(config)) | ||
console.print("\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.