最近在研究Transformer在医疗图像分割的应用,
解决 TransUNet 和 Swim Unet 源码的坑
KeyError: 'Transformer/encoderblock_0/MultiHeadDotProductAttention_1/query\\kernel is not a file in the archive'
这是os.path.join 合并路径的时候出现的问题
解决方案:
1.在vit_seg_modeling.py 文件里面
下面这些路径后面加上'/':
ATTENTION_Q = "MultiHeadDotProductAttention_1/query/"
ATTENTION_K = "MultiHeadDotProductAttention_1/key/"
ATTENTION_V = "MultiHeadDotProductAttention_1/value/"
ATTENTION_OUT = "MultiHeadDotProductAttention_1/out/"
FC_0 = "MlpBlock_3/Dense_0/"
FC_1 = "MlpBlock_3/Dense_1/"
ATTENTION_NORM = "LayerNorm_0/"
MLP_NORM = "LayerNorm_2/"
2.在vit_seg_modeling_resnet_skip.py 文件里面
ResNetV2类 里面 每个'block'和'unit'后面加'/'
self.body = nn.Sequential(OrderedDict([
('block1/', nn.Sequential(OrderedDict(
[('unit1/', PreActBottleneck(cin=width, cout=width*4, cmid=width))] +
[(f'unit{i:d}/', PreActBottleneck(cin=width*4, cout=width*4, cmid=width)) for i in range(2, block_units[0] + 1)],
))),
('block2/', nn.Sequential(OrderedDict(
[('unit1/', PreActBottleneck(cin=width*4, cout=width*8, cmid=width*2, stride=2))] +
[(f'unit{i:d}/', PreActBottleneck(cin=width*8, cout=width*8, cmid=width*2)) for i in range(2, block_units[1] + 1)],
))),
('block3/', nn.Sequential(OrderedDict(
[('unit1/', PreActBottleneck(cin=width*8, cout=width*16, cmid=width*4, stride=2))] +
[(f'unit{i:d}/', PreActBottleneck(cin=width*16, cout=width*16, cmid=width*4)) for i in range(2, block_units[2] + 1)],
))),
]))
KeyError: ‘Transformer/...query\\kernel is not a file in the archive‘(已解决)
最新推荐文章于 2024-07-12 17:38:57 发布