-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
在使用 test.py 对模型进行测试时,当输入图像尺寸不能被 patch_size(默认 64)整除时,会出现维度不匹配的错误。具体错误信息如下:
plaintext
RuntimeError: shape '[1, 48, 64, 64]' is invalid for input of size 123456
复现步骤
使用尺寸为 256×256 的图像进行测试(可正常运行)
使用尺寸为 200×200 的图像进行测试(出现错误)
配置参数使用默认值:patch_size=64
可能原因分析
在 test.py 的图像分割部分:
python
运行
batch_x = torch.cat(torch.split(batch_x, split_size_or_sections=config.para.patch_size, dim=3), dim=0)
batch_x = torch.cat(torch.split(batch_x, split_size_or_sections=config.para.patch_size, dim=2), dim=0)
当图像尺寸不能被 patch_size 整除时,torch.split 会产生尺寸不一致的补丁,导致后续拼接和重塑操作失败。
建议解决方案
在图像预处理阶段增加自动填充逻辑,确保图像尺寸为 patch_size 的整数倍
或修改分割逻辑,对最后一个不完整的补丁进行单独处理
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels