当前位置: 代码迷 >> 综合 >> 已解决:KeyError: ‘Transformer/encoderblock_0/MultiHeadDotProductAttention_1/query\\kernel is
  详细解决方案

已解决:KeyError: ‘Transformer/encoderblock_0/MultiHeadDotProductAttention_1/query\\kernel is

热度:40   发布时间:2023-11-03 03:27:41.0
最近在研究Transformer在细粒度图像的应用,
解决 vit 源码的坑KeyError: 'Transformer/encoderblock_0/MultiHeadDotProductAttention_1/query\\kernel is not a file in the archive'这是os.path.join 合并路径的时候出现的问题解决方案:1.在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_modeling_resnet.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)],))),
]))
  相关解决方案