close

[solved] TypeError: __array__() takes 1 positional argument but 2 were given

Hello Guys, How are you all? Hope You all Are Fine. I am Using pytorchand I am facing following error in my stack track TypeError: array() takes 1 positional argument but 2 were given in Python. So Here I am Explain to you all the possible solutions here.

Without Wasting your time, Lets start This Article to Solve This Error.

How TypeError: array() takes 1 positional argument but 2 were given Error Occurs ?

I am Using pytorchand I am facing following error in my stack track.

  File "/transforms.py", line 26, in __call__
    image, target = t(image, target)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/transforms.py", line 50, in forward
    image = F.to_tensor(image)
  File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/functional.py", line 129, in to_tensor
    np.array(pic, mode_to_nptype.get(pic.mode, np.uint8), copy=True)
TypeError: __array__() takes 1 positional argument but 2 were given

How To Solve TypeError: array() takes 1 positional argument but 2 were given Error ?

  1. How To Solve TypeError: array() takes 1 positional argument but 2 were given Error ?

    To Solve TypeError: array() takes 1 positional argument but 2 were given Error you have to downgrade torch library. In requirements.txt if you downgrad the torch library then you must have to downgrade torchvision. Below verion of torch and torchvision is working fine without any error.

Solution 1:  downgrading pillow version

Just downgrading pillow version will resolve this error just downgrad pillow to 8.2.0

pip install pillow==8.2.0

Solution 2: downgrad the torch library

To solve this error you have to downgrade torch library. In requirements.txt if you downgrad the torch library then you must have to downgrade torchvision. Below verion of torch and torchvision is working fine without any error.

torch==1.9.0
torchvision==0.10.0

Downgrade above two version to below version.

torch==1.8.1
torchvision==0.9.1

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also Read

Please Rate Our Solution to Motivate Us For Give Our Best

Leave a Comment