TorchStudio / torchstudio

IDE for PyTorch and its ecosystem
https://torchstudio.ai
MIT License
378 stars 27 forks source link

NameError: name 'Any' is not defined #55

Closed tvanachteren closed 6 months ago

tvanachteren commented 1 year ago

image

On Windows, when trying to build the mobilenet_v2 model with weights 'IMAGENET1K_V2' following the tutorial on "Transfer Learning", I get the error: NameError: name 'Any' is not defined. The MobileNetV2 without pretrained weights worked fine.

Armin234 commented 11 months ago

I have the same problem, any solution ?

philippejuhel commented 8 months ago

Hi,

Same for me. TorchStudio version is : 0.9.16 on Ubuntu 22.04. I try with other pretrained networks and got the same error. I try with versions 0.9.15 and 0.9.14 and got the same error.

I try to install TorchStudio 0.9.16 on another computer

Ready (Linux-6.2.0-39-generic-x86_64-with-glibc2.35, Python 3.11.5, PyTorch 2.1.0, Devices: cpu "CPU" (FP32), cuda:0 "NVIDIA GeForce RTX 2080 Ti" (FP32/FP16))

After clicking on the 'Build' button, the following lines are added on the log file :

10:52:56.902 INFO  build: "Model 1" "Loading PyTorch...\n\n" ""
10:52:56.989 INFO  metricsplot: "/home/phil/TorchStudio/torchstudio/metricsplot.py:133: MatplotlibDeprecationWarning: The tostring_rgb function was deprecated in Matplotlib 3.8 and will be removed two minor releases later. Use buffer_rgba instead.\n  img = PIL.Image.frombytes('RGB',canvas.get_width_height(),canvas.tostring_rgb())\n"
10:52:58.143 INFO  build: "Model 1" "Build script connected\n\n" ""
10:52:58.511 INFO  build: "Model 1" "model definition, line 9, in <module>\n\nNameError: name 'Any' is not defined\n" ""
10:52:58.873 INFO  build end: "Model 1" "" ""

Philippe

philippejuhel commented 8 months ago

After hours of debugging, I manage to correct this problem. (let me know if the explanation is OK)

When you select a pretrained model, it uses a description from torchvision website (for example : mobilenet_v2) In this declaration, it's written : **kwargs: Any (the famous not defined 'Any') So, before clicking on the Build button, check the Code checkbox to access the def mobilenet_v2 code and replace **kwargs: Any by **kwargs: None

and now, the model is built.

Philippe

divideconcept commented 6 months ago

This should now be fixed with TorchStudio 0.9.17: https://github.com/TorchStudio/torchstudio/releases/tag/0.9.17