Repository: Project-MONAI/MONAI
File: tests/test_controlnet_maisi.py (Python)

Code before:
        (1, 8, 4, 4),
    ],
    [
        {
            "spatial_dims": 3,
            "in_channels": 1,
            "num_res_blocks": 1,
            "num_channels": (8, 8, 8),
            "attention_levels": (False, False, True),
            "num_head_channels": 8,
            "norm_num_groups": 8,
            "conditioning_embedding_in_channels": 1,
            "conditioning_embedding_num_channels": (8, 8),
            "use_checkpointing": True,
            "with_conditioning": True,
            "cross_attention_dim": 2,
        },
        6,
        (1, 8, 4, 4, 4),
    ],
]

TEST_CASES_ERROR = [
    [
        {"spatial_dims": 2, "in_channels": 1, "with_conditioning": True, "cross_attention_dim": None},
        "DiffusionModelUNet expects dimension of the cross-attention conditioning (cross_attention_dim) "
        "to be specified when with_conditioning=True.",
    ],
    [
        {"spatial_dims": 2, "in_channels": 1, "with_conditioning": False, "cross_attention_dim": 2},
        "DiffusionModelUNet expects with_conditioning=True when specifying the cross_attention_dim.",
    ],
    [
        {"spatial_dims": 2, "in_channels": 1, "num_channels": (8, 16), "norm_num_groups": 16},
        f"DiffusionModelUNet expects all channels to be a multiple of norm_num_groups, but got"
        f" channels={(8, 16)} and norm_num_groups={16}",
    ],
    [
        {
            "spatial_dims": 2,
            "in_channels": 1,
            "num_channels": (8, 16),
            "attention_levels": (True,),
            "norm_num_groups": 8,
        },
        f"DiffusionModelUNet expects channels to have the same length as attention_levels, but got "
        f"channels={(8, 16)} and attention_levels={(True,)}",
    ],
]



Review comment (bug):
Hi @guopengf, could you please help modify the error message in https://github.com/Project-MONAI/MONAI/blob/62430315cd176478d06dd197b7a6dfdd6cd90c44/monai/networks/nets/controlnet.py#L181?

Look like it's wrong and misleading.

Code after:
        (1, 8, 4, 4),
    ],
    [
        {
            "spatial_dims": 3,
            "in_channels": 1,
            "num_res_blocks": 1,
            "num_channels": (8, 8, 8),
            "attention_levels": (False, False, True),
            "num_head_channels": 8,
            "norm_num_groups": 8,
            "conditioning_embedding_in_channels": 1,
            "conditioning_embedding_num_channels": (8, 8),
            "use_checkpointing": True,
            "with_conditioning": True,
            "cross_attention_dim": 2,
        },
        6,
        (1, 8, 4, 4, 4),
    ],
]

TEST_CASES_ERROR = [
    [
        {"spatial_dims": 2, "in_channels": 1, "with_conditioning": True, "cross_attention_dim": None},
        "ControlNet expects dimension of the cross-attention conditioning (cross_attention_dim) "
        "to be specified when with_conditioning=True.",
    ],
    [
        {"spatial_dims": 2, "in_channels": 1, "with_conditioning": False, "cross_attention_dim": 2},
        "ControlNet expects with_conditioning=True when specifying the cross_attention_dim.",
    ],
    [
        {"spatial_dims": 2, "in_channels": 1, "num_channels": (8, 16), "norm_num_groups": 16},
        f"ControlNet expects all channels to be a multiple of norm_num_groups, but got"
        f" channels={(8, 16)} and norm_num_groups={16}",
    ],
    [
        {
            "spatial_dims": 2,
            "in_channels": 1,
            "num_channels": (8, 16),
            "attention_levels": (True,),
            "norm_num_groups": 8,
        },
        f"ControlNet expects channels to have the same length as attention_levels, but got "
        f"channels={(8, 16)} and attention_levels={(True,)}",
    ],
]