[Solved] KeyError: ‘Transformer/encoderblock_0/MultiHeadDotProductAttention_1/query\\kernel is

Recently, I've been working on the application of Transformer to fine-grained images.
Solving the problem with the vit source code
 
KeyError: 'Transformer/encoderblock_0/MultiHeadDotProductAttention_1/query\kernel is not a file in the archive'
 
This is a problem when merging paths with os.path.join
 
Solution.
 
1. In the modeling.py file
 
Add '/' to the following paths:
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. In the vit_modeling_resnet.py file
 
ResNetV2 class Add '/' after each 'block' and '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)],
        ))),
]))

Read More: