lukemelas / PyTorch-Pretrained-ViT

Vision Transformer (ViT) in PyTorch
770 stars 124 forks source link

TypeError with ProgressMeter class #31

Closed AvisP closed 1 year ago

AvisP commented 1 year ago

While running the script main.py in \examples\imagenet\ I am getting the following error

Exception has occurred: TypeError       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
unsupported format string passed to Tensor.__format__
  File "/home/.........../.local/lib/python3.9/site-packages/torch/_tensor.py", line 660, in __format__
    return object.__format__(self, format_spec)
  File "/home/.........../VisionTransformer/main.py", line 380, in __str__
    return fmtstr.format(**self.__dict__)
  File "/home/.........../VisionTransformer/main.py", line 391, in <listcomp>
    entries += [str(meter) for meter in self.meters]
  File "/home/.........../VisionTransformer/main.py", line 391, in print
    entries += [str(meter) for meter in self.meters]
  File "/home/.........../VisionTransformer/main.py", line 344, in validate
    progress.print(i)
  File "/home/.........../VisionTransformer/main.py", line 236, in main_worker
    res = validate(val_loader, model, criterion, args)
  File "/home/.........../VisionTransformer/main.py", line 111, in main
    main_worker(args.gpu, ngpus_per_node, args)
  File "/home/.........../VisionTransformer/main.py", line 425, in <module>
    main()
  File "/tools/conda/anaconda3/envs/torch_new/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tools/conda/anaconda3/envs/torch_new/lib/python3.9/runpy.py", line 197, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
TypeError: unsupported format string passed to Tensor.__format__

I googled a bit and it looks like the issue is happening because it is getting a format it was not expecting. I am not proficient in python to resolve this. Kindly suggest some fix, thanks!

AvisP commented 1 year ago

Issue resolved after using the fix on issue #26