utils
aws
¶
download_s3(bucket_name, object_name, output_path)
¶
Download a file from an S3 bucket and save it to the local file system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket_name |
str
|
The name of the S3 bucket. |
required |
object_name |
str
|
The key or path of the object to be downloaded from the bucket. |
required |
output_path |
str
|
The local file path to save the downloaded object. |
required |
Source code in aimet_ml/utils/aws.py
7 8 9 10 11 12 13 14 15 16 17 |
|
upload_dir_s3(bucket_name, bucket_dir_path, src_dir_path)
¶
Upload a local directory to an S3 bucket, preserving the directory structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket_name |
str
|
The name of the S3 bucket. |
required |
bucket_dir_path |
str
|
The path within the bucket where the local directory will be uploaded. |
required |
src_dir_path |
str
|
The local directory path to be uploaded. |
required |
Source code in aimet_ml/utils/aws.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
upload_files_s3(bucket_name, bucket_dir_path, src_file_paths)
¶
Upload multiple local files to an S3 bucket.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket_name |
str
|
The name of the S3 bucket. |
required |
bucket_dir_path |
str
|
The path within the bucket where the files will be uploaded. |
required |
src_file_paths |
list
|
A list of local file paths to be uploaded to the bucket. |
required |
Source code in aimet_ml/utils/aws.py
20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
git
¶
get_commit_id(short=True)
¶
Get the Git commit ID of the current repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
short |
bool
|
Whether to get a short or full Git commit ID. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The Git commit ID as a string. |
Source code in aimet_ml/utils/git.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
hamd_7
¶
score_to_severity(score)
¶
Convert a score to a severity category.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
score |
int
|
The input score. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The corresponding severity category ("normal", "mild", "moderate", or "severe"). |
Source code in aimet_ml/utils/hamd_7.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
io_utils
¶
read_json(file_path)
¶
Read and parse a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The path to the JSON file to be read. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the parsed JSON data. |
Source code in aimet_ml/utils/io_utils.py
8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
read_pickle(file_path)
¶
Read and unpickle a binary pickle file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The path to the pickle file to be read. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
The unpickled object. |
Source code in aimet_ml/utils/io_utils.py
23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
read_yaml(file_path)
¶
Read and parse a YAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The path to the YAML file to be read. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the parsed YAML data. |
Source code in aimet_ml/utils/io_utils.py
38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
write_json(file_path, data, indent=None)
¶
Write data to a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The path to the JSON file to be written. |
required |
data |
dict
|
The data to be written to the JSON file. |
required |
indent |
int
|
The number of spaces to use for indentation. |
None
|
Source code in aimet_ml/utils/io_utils.py
53 54 55 56 57 58 59 60 61 62 63 |
|
write_pickle(file_path, data)
¶
Write data to a binary pickle file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The path to the pickle file to be written. |
required |
data |
The data to be pickled and written to the file. |
required |
Source code in aimet_ml/utils/io_utils.py
66 67 68 69 70 71 72 73 74 75 |
|
write_yaml(file_path, data, default_flow_style=False)
¶
Write data to a YAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The path to the YAML file to be written. |
required |
data |
dict
|
The data to be written to the YAML file. |
required |
default_flow_style |
bool
|
Whether to use the default flow style for YAML. |
False
|
Source code in aimet_ml/utils/io_utils.py
78 79 80 81 82 83 84 85 86 87 88 |
|
plots
¶
add_bar_label(bar_chart, with_percent=False, percent_digits=2)
¶
Add labels to a bar chart with optional percentage values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bar_chart |
Axes
|
The bar chart object. |
required |
with_percent |
bool
|
Whether to include percentage values. Defaults to False. |
False
|
percent_digits |
int
|
Number of decimal digits for percentage values. Defaults to 2. |
2
|
Source code in aimet_ml/utils/plots.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
plt2arr(fig, draw=True)
¶
Convert a Matplotlib figure to a NumPy array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig |
Figure
|
The Matplotlib figure to be converted. |
required |
draw |
bool
|
Whether to draw the figure. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The converted figure as a NumPy array. |
Source code in aimet_ml/utils/plots.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
set_font(font_path)
¶
Set the font for Matplotlib using the provided font file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
font_path |
str
|
Path to the font file. |
required |
Source code in aimet_ml/utils/plots.py
47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
set_thai_font()
¶
Set the Thai font for Matplotlib using a predefined font path.
Source code in aimet_ml/utils/plots.py
62 63 64 65 |
|
wandb_utils
¶
list_artifact_names(api, artifact_type, with_versions=True, with_aliases=True, per_page=100)
¶
List available artifact names for a specific artifact type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api |
Api
|
The WandB API client. |
required |
artifact_type |
str
|
The type of artifact for which names are listed. |
required |
with_versions |
bool
|
Include version suffixes. Defaults to True. |
True
|
with_aliases |
bool
|
Include artifact aliases. Defaults to True. |
True
|
per_page |
int
|
Number of items to retrieve per page. Defaults to 100. |
100
|
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
A sorted list of available artifact names with optional suffixes (versions or aliases). |
Source code in aimet_ml/utils/wandb_utils.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
load_artifact(api, artifact_type, artifact_name, artifact_alias, per_page=100)
¶
Load a WandB artifact by name and alias.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api |
Api
|
The WandB API client. |
required |
artifact_type |
str
|
The type of artifact to load. |
required |
artifact_name |
str
|
The base name of the artifact. |
required |
artifact_alias |
str
|
The alias of the artifact. |
required |
per_page |
int
|
Number of items to retrieve per page. Defaults to 100. |
100
|
Returns:
Type | Description |
---|---|
Union[Artifact, None]
|
wandb.Artifact: The loaded WandB artifact or None if it doesn't exist. |
Source code in aimet_ml/utils/wandb_utils.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
table_to_dataframe(table)
¶
Convert a WandB table to a Pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table |
Table
|
The WandB table to be converted. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A Pandas DataFrame containing the data from the WandB table. |
Source code in aimet_ml/utils/wandb_utils.py
8 9 10 11 12 13 14 15 16 17 18 |
|