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

Problem Description: BTS code today, all kinds of errors. The amazing thing is that everyone has no problem, only I encounter all kinds of wonderful problems, which are too difficult.

Type error: can’t convert CUDA: 0 device type tensor to numpy. Use tensor. CPU () to copy the tensor to host memory first

The solution to this problem is to copy the GPU data to the CPU first, and then save it. But it doesn’t look like that to me. Some people encountered it before because the torch version was wrong, so I reloaded all kinds of versions and combinations, which were unsuccessful.

Only part of the code will be commented out first, and then take a closer look.

Question 2: typeerror:__ array__() takes 1 positional argument but 2 were given

This problem is even more exotic, the image reading error. It is roughly the following situation:

np.array(img) # OK
np.array(img, dtype=np.float64) # Error

After searching for a long time, I finally found that a big guy proposed that it was a PIL bug, and the version was lowered from 8.3 to 8.2 to solve it

Read More: