You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'VisionTransformer' object has no attribute 'dist_token' #1
When I fully follow the README file, when I run the py file, I report the following error“'VisionTransformer' object has no attribute 'dist_token' ”, how can I solve this.as follows:
Traceback (most recent call last):
File "main.py", line 102, in
main()
File "main.py", line 42, in main
model = CountingAnything(CFG)
File "/home/hao/桌面/LearningToCountAnything/models/CountingAnything.py", line 47, in init
self.backbone = ViTExtractor(vit_config)
File "/home/hao/桌面/LearningToCountAnything/models/backbone_vit.py", line 29, in init
self.create_from_base_model(
File "/home/hao/桌面/LearningToCountAnything/models/backbone_vit.py", line 47, in create_from_base_model
self.dist_token = base_model.dist_token
File "/root/anaconda3/envs/LearningToCountAnything/lib/python3.8/site-packages/torch/nn/modules/module.py", line 947, in getattr
raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'VisionTransformer' object has no attribute 'dist_token'
I was not able to replicate this error.
We believe this may occur if using an incorrect version of timm, and that it can be fixed by removing the dist_token from the timm method as it is no longer needed.
Found the exact same problem. Maybe it would be interesting to update the environment.yml so it includes the correct version of timm, and also other libraries needed for the execution that are not initially installed such as opencv, scipy and sklearn.
Also, could not get over of this problem so as for today I still cannot run the --config example_training step
My apologies that you haven't been able to run it today, I have just updated the backbone_vit.py to remove the dist_token.
It should work now (and works on my clean env from the yml), let me know if you have any more problems.
another problem that appears when trying to run it is "no module named torch._six". I was able to overcome it by modifying the async_dataloader.py of pytorch lighning bolts so it doesnt use it. Updating plbolts might also solve that problem. I dont know why it happens to me though, if you tested it with clean yml
Edit: I updated the backbone_vit.py with your changes and it appears now that it works fine, although I get constantly in screen this warning:
"UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
img = torch.ByteTensor(torch.ByteStorage.from_buffer(pic.tobytes()))"
Activity
mahobley commentedon Dec 16, 2022
I was not able to replicate this error.
We believe this may occur if using an incorrect version of timm, and that it can be fixed by removing the dist_token from the timm method as it is no longer needed.
JavierUrenaPhDProjects commentedon Apr 4, 2023
Found the exact same problem. Maybe it would be interesting to update the environment.yml so it includes the correct version of timm, and also other libraries needed for the execution that are not initially installed such as opencv, scipy and sklearn.
Also, could not get over of this problem so as for today I still cannot run the --config example_training step
mahobley commentedon Apr 4, 2023
My apologies that you haven't been able to run it today, I have just updated the backbone_vit.py to remove the dist_token.
It should work now (and works on my clean env from the yml), let me know if you have any more problems.
JavierUrenaPhDProjects commentedon Apr 4, 2023
another problem that appears when trying to run it is "no module named torch._six". I was able to overcome it by modifying the async_dataloader.py of pytorch lighning bolts so it doesnt use it. Updating plbolts might also solve that problem. I dont know why it happens to me though, if you tested it with clean yml
Edit: I updated the backbone_vit.py with your changes and it appears now that it works fine, although I get constantly in screen this warning:
"UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
img = torch.ByteTensor(torch.ByteStorage.from_buffer(pic.tobytes()))"