mednet.scripts.utils¶
Utilities for command-line scripts.
Module Attributes
Defines types that can be encoded in a JSON string. |
Functions
|
Generate information concerning hardware properties. |
Produce metadata concerning the running script, in the form of a dictionary. |
|
|
Save a little summary of the model in a txt file. |
|
Save prediction hyperparameters into a .json file. |
|
Save a dictionary into a JSON file with path checking and backup. |
Classes
|
Extends the standard JSON encoder to support Numpy arrays. |
- mednet.scripts.utils.JSONable¶
Defines types that can be encoded in a JSON string.
alias of
Mapping
[str
,JSONable
] |Sequence
[JSONable
] |str
|int
|float
|bool
|None
- mednet.scripts.utils.model_summary(model)[source]¶
Save a little summary of the model in a txt file.
- Parameters:
model (
Module
) – Instance of the model for which to save the summary.- Returns:
A tuple with the model summary in a text format and number of parameters of the model.
- Return type:
- mednet.scripts.utils.device_properties(device_type)[source]¶
Generate information concerning hardware properties.
- mednet.scripts.utils.execution_metadata()[source]¶
Produce metadata concerning the running script, in the form of a dictionary.
This function returns potentially useful metadata concerning program execution. It contains a certain number of preset variables.
- Return type:
- Returns:
A dictionary that contains the following fields:
package-name
: current package name (e.g.mednet
)package-version
: current package version (e.g.1.0.0b0
)datetime
: date and time in ISO8601 format (e.g.2024-02-23T18:38:09+01:00
)user
: username (e.g.johndoe
)conda-env
: if set, the name of the current conda environmentpath
: current path when executing the commandcommand-line
: the command-line that is being runhostname
: machine hostname (e.g.localhost
)platform
: machine platform (e.g.darwin
)accelerator
: acceleration devices available (e.g.cuda
)
- class mednet.scripts.utils.NumpyJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶
Bases:
JSONEncoder
Extends the standard JSON encoder to support Numpy arrays.
- mednet.scripts.utils.save_json_with_backup(path, data)[source]¶
Save a dictionary into a JSON file with path checking and backup.
This function will save a dictionary into a JSON file. It will check to the existence of the directory leading to the file and create it if necessary. If the file already exists on the destination folder, it is backed-up before a new file is created with the new contents.
- Parameters:
path (
Path
) – The full path where to save the JSON data.data (
Union
[Mapping
[str
,Union
[Mapping
[str
, JSONable],Sequence
[JSONable],str
,int
,float
,bool
,None
]],Sequence
[Union
[Mapping
[str
, JSONable],Sequence
[JSONable],str
,int
,float
,bool
,None
]],str
,int
,float
,bool
,None
]) – The data to save on the JSON file.
- Return type: