Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yaoyuping
nnDetection
Commits
938687e7
Unverified
Commit
938687e7
authored
May 31, 2022
by
Michael Baumgartner
Committed by
GitHub
May 31, 2022
Browse files
Merge pull request #84 from kapsner/minor_enhancements
Check if instance class is defined in metadata
parents
9aaa3f43
faf22873
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
2 deletions
+7
-2
nndet/utils/check.py
nndet/utils/check.py
+7
-2
No files found.
nndet/utils/check.py
View file @
938687e7
...
@@ -174,7 +174,7 @@ def check_data_and_label_splitted(
...
@@ -174,7 +174,7 @@ def check_data_and_label_splitted(
"mask info path but it does not exist."
)
"mask info path but it does not exist."
)
mask_info
=
load_json
(
mask_info_path
)
mask_info
=
load_json
(
mask_info_path
)
_type_check_instances_json
(
mask_info
,
mask_info_path
)
_type_check_instances_json
(
mask_info
,
mask_info_path
,
expected_labels
=
cfg
[
"labels"
]
)
# check presence / absence of instances in json and mask
# check presence / absence of instances in json and mask
if
mask_info
[
"instances"
]:
if
mask_info
[
"instances"
]:
...
@@ -195,7 +195,7 @@ def check_data_and_label_splitted(
...
@@ -195,7 +195,7 @@ def check_data_and_label_splitted(
print
(
"Data and label check complete."
)
print
(
"Data and label check complete."
)
def
_type_check_instances_json
(
mask_info
:
Dict
,
mask_info_path
:
Union
[
str
,
Path
]):
def
_type_check_instances_json
(
mask_info
:
Dict
,
mask_info_path
:
Union
[
str
,
Path
]
,
expected_labels
:
list
):
"""
"""
Check types of json files
Check types of json files
...
@@ -203,11 +203,14 @@ def _type_check_instances_json(mask_info: Dict, mask_info_path: Union[str, Path]
...
@@ -203,11 +203,14 @@ def _type_check_instances_json(mask_info: Dict, mask_info_path: Union[str, Path]
mask_info: contains information loaded from the label json file.
mask_info: contains information loaded from the label json file.
Specifically the `instances` key is checked for a "str":"int" type
Specifically the `instances` key is checked for a "str":"int" type
mask_info_path: path to json file where information was loaded from
mask_info_path: path to json file where information was loaded from
expected_labels: list with the expected labels
Raises:
Raises:
ValueError: raised if instance ids are not typed as str
ValueError: raised if instance ids are not typed as str
ValueError: raised if instance classes are not typed as int
ValueError: raised if instance classes are not typed as int
"""
"""
# transform expected labels to integer
exp_labs
=
[
int
(
lab
)
for
lab
in
expected_labels
]
# type check instances key
# type check instances key
for
key_instance_id
,
item_instance_cls
in
mask_info
[
"instances"
].
items
():
for
key_instance_id
,
item_instance_cls
in
mask_info
[
"instances"
].
items
():
if
not
isinstance
(
key_instance_id
,
str
):
if
not
isinstance
(
key_instance_id
,
str
):
...
@@ -216,6 +219,8 @@ def _type_check_instances_json(mask_info: Dict, mask_info_path: Union[str, Path]
...
@@ -216,6 +219,8 @@ def _type_check_instances_json(mask_info: Dict, mask_info_path: Union[str, Path]
if
not
isinstance
(
item_instance_cls
,
int
):
if
not
isinstance
(
item_instance_cls
,
int
):
raise
ValueError
(
f
"Instance classes needs to be an int, found
{
type
(
item_instance_cls
)
}
"
raise
ValueError
(
f
"Instance classes needs to be an int, found
{
type
(
item_instance_cls
)
}
"
f
"of instance
{
key_instance_id
}
in
{
mask_info_path
}
"
)
f
"of instance
{
key_instance_id
}
in
{
mask_info_path
}
"
)
if
not
item_instance_cls
in
exp_labs
:
raise
ValueError
(
f
"Instance class
{
item_instance_cls
}
not defined in dataset.yml"
)
def
_full_check
(
def
_full_check
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment