Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mednet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
medai
software
mednet
Commits
fcf9a7d7
Commit
fcf9a7d7
authored
9 months ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
[libs.common.scripts.utils] Define a better type for JSON-able content
parent
6355dc02
No related branches found
No related tags found
1 merge request
!46
Create common library
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mednet/libs/common/scripts/utils.py
+13
-1
13 additions, 1 deletion
src/mednet/libs/common/scripts/utils.py
with
13 additions
and
1 deletion
src/mednet/libs/common/scripts/utils.py
+
13
−
1
View file @
fcf9a7d7
...
@@ -8,6 +8,7 @@ import logging
...
@@ -8,6 +8,7 @@ import logging
import
pathlib
import
pathlib
import
re
import
re
import
shutil
import
shutil
import
typing
import
lightning.pytorch
import
lightning.pytorch
import
lightning.pytorch.callbacks
import
lightning.pytorch.callbacks
...
@@ -16,6 +17,17 @@ from mednet.libs.common.engine.device import SupportedPytorchDevice
...
@@ -16,6 +17,17 @@ from mednet.libs.common.engine.device import SupportedPytorchDevice
logger
=
logging
.
getLogger
(
"
mednet
"
)
logger
=
logging
.
getLogger
(
"
mednet
"
)
JSONable
:
typing
.
TypeAlias
=
(
typing
.
Mapping
[
str
,
"
JSONable
"
]
|
typing
.
Sequence
[
"
JSONable
"
]
|
str
|
int
|
float
|
bool
|
None
)
"""
Defines types that can be encoded in a JSON string.
"""
def
model_summary
(
def
model_summary
(
model
:
torch
.
nn
.
Module
,
model
:
torch
.
nn
.
Module
,
...
@@ -198,7 +210,7 @@ def execution_metadata() -> dict[str, int | float | str | dict[str, str] | list[
...
@@ -198,7 +210,7 @@ def execution_metadata() -> dict[str, int | float | str | dict[str, str] | list[
}
}
def
save_json_with_backup
(
path
:
pathlib
.
Path
,
data
:
dict
|
list
)
->
None
:
def
save_json_with_backup
(
path
:
pathlib
.
Path
,
data
:
JSONable
)
->
None
:
"""
Save a dictionary into a JSON file with path checking and backup.
"""
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
This function will save a dictionary into a JSON file. It will check to
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment