Skip to content

Commit

Permalink
Add undefined label prompt check (#693)
Browse files Browse the repository at this point in the history
Fixes # .

### Description
A few sentences describing the changes proposed in this pull request.

### Status
**Ready/Work in progress/Hold**

### Please ensure all the checkboxes:
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Codeformat tests passed locally by running `./runtests.sh
--codeformat`.
- [ ] In-line docstrings updated.
- [ ] Update `version` and `changelog` in `metadata.json` if changing an
existing bundle.
- [ ] Please ensure the naming rules in config files meet our
requirements (please refer to: `CONTRIBUTING.md`).
- [ ] Ensure versions of packages such as `monai`, `pytorch` and `numpy`
are correct in `metadata.json`.
- [ ] Descriptions should be consistent with the content, such as
`eval_metrics` of the provided weights and TorchScript modules.
- [ ] Files larger than 25MB are excluded and replaced by providing
download links in `large_file.yml`.
- [ ] Avoid using path that contains personal information within config
files (such as use `/home/your_name/` for `"bundle_root"`).

---------

Signed-off-by: heyufan1995 <heyufan1995@gmail.com>
Signed-off-by: Yiheng Wang <vennw@nvidia.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Yiheng Wang <68361391+yiheng-wang-nv@users.noreply.github.com>
Co-authored-by: Dr. Bruce Hashemian <3968947+drbeh@users.noreply.github.com>
Co-authored-by: Yiheng Wang <vennw@nvidia.com>
  • Loading branch information
5 people authored Oct 11, 2024
1 parent c094cda commit 9d35f9a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
22 changes: 21 additions & 1 deletion ci/unit_tests/test_vista3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
TEST_CASE_INFER_MULTI_NEW_STR_PROMPT = [
{
"bundle_root": "models/vista3d",
"input_dict": {"label_prompt": ["new class 1", "new class 2", "new class 3"]},
"input_dict": {"label_prompt": ["new class 1"], "points": [[123, 212, 151]], "point_labels": [1]},
"patch_size": [32, 32, 32],
"checkpointloader#_disabled_": True, # do not load weights"
"initialize": ["$monai.utils.set_determinism(seed=123)"],
Expand Down Expand Up @@ -223,6 +223,26 @@
"error": "Label prompt can only be a single object if provided with point prompts.",
}
],
[
{
"bundle_root": "models/vista3d",
"input_dict": {"label_prompt": [16, 25, 26]},
"patch_size": [32, 32, 32],
"checkpointloader#_disabled_": True, # do not load weights"
"initialize": ["$monai.utils.set_determinism(seed=123)"],
"error": "Undefined label prompt detected. Provide point prompts for zero-shot.",
}
],
[
{
"bundle_root": "models/vista3d",
"input_dict": {"label_prompt": [136]},
"patch_size": [32, 32, 32],
"checkpointloader#_disabled_": True, # do not load weights"
"initialize": ["$monai.utils.set_determinism(seed=123)"],
"error": "Undefined label prompt detected. Provide point prompts for zero-shot.",
}
],
]


Expand Down
3 changes: 2 additions & 1 deletion models/vista3d/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20240725.json",
"version": "0.5.3",
"version": "0.5.4",
"changelog": {
"0.5.4": "add undefined label prompt check",
"0.5.3": "update readme",
"0.5.2": "fix eval issue",
"0.5.1": "add description for zero-shot and upate eval",
Expand Down
4 changes: 4 additions & 0 deletions models/vista3d/scripts/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ def check_prompts_format(self, label_prompt, points, point_labels):
raise ValueError("Label prompt must be a list of single scalar, [1,2,3,4,...,].")
if not np.all([(x < 255).item() for x in label_prompt]):
raise ValueError("Current bundle only supports label prompt smaller than 255.")
if points is None:
supported_list = list({i + 1 for i in range(132)} - {16, 18, 129, 130, 131})
if not np.all([x in supported_list for x in label_prompt]):
raise ValueError("Undefined label prompt detected. Provide point prompts for zero-shot.")
else:
raise ValueError("Label prompt must be a list, [1,2,3,4,...,].")
# check points
Expand Down

0 comments on commit 9d35f9a

Please sign in to comment.