Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions tests/ngc_mmar_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
# limitations under the License.

import os
import sys
import unittest

import torch
from parameterized import parameterized

from monai.apps.mmars import MODEL_DESC, load_from_mmar
from monai.config import print_debug_info
from monai.networks.utils import copy_model_state


class TestAllDownloadingMMAR(unittest.TestCase):
Expand All @@ -26,10 +28,33 @@ def setUp(self):

@parameterized.expand((item,) for item in MODEL_DESC)
def test_loading_mmar(self, item):
if item["name"] == "clara_pt_self_supervised_learning_segmentation": # test the byow model
default_model_file = os.path.join("ssl_models_2gpu", "best_metric_model.pt")
pretrained_weights = load_from_mmar(
item=item["name"],
mmar_dir="./",
map_location="cpu",
api=True,
model_file=default_model_file,
weights_only=True,
)
pretrained_weights = {k.split(".", 1)[1]: v for k, v in pretrained_weights["state_dict"].items()}
sys.path.append(os.path.join(f"{item['name']}", "custom")) # custom model folder
from vit_network import ViTAutoEnc # pylint: disable=E0401

model = ViTAutoEnc(
in_channels=1,
img_size=(96, 96, 96),
patch_size=(16, 16, 16),
pos_embed="conv",
hidden_size=768,
mlp_dim=3072,
)
_, loaded, not_loaded = copy_model_state(model, pretrained_weights)
self.assertTrue(len(loaded) > 0 and len(not_loaded) == 0)
return
if item["name"] == "clara_pt_fed_learning_brain_tumor_mri_segmentation":
default_model_file = os.path.join("models", "server", "best_FL_global_model.pt")
elif item["name"] == "clara_pt_self_supervised_learning_segmentation":
default_model_file = os.path.join("models_2gpu", "best_metric_model.pt")
else:
default_model_file = None
pretrained_model = load_from_mmar(
Expand Down