ToTensor()(image) arguments


I am trying to iterate over pictures from folder, using PIL.Image to open and resize them, and then torchvision.transforms.ToTensor() to save them as tensors.

On the ToTensor() command I get this error:
TypeError: array() takes 1 positional argument but 2 were given

# read from given dir, resize to imageSizeXimageSize
def readImages(dir, imageSize): 
    # process one given raw image
    def processImg(rawImg):
        image =
        image.thumbnail((imageSize, imageSize), Image.ANTIALIAS)
        image = image.resize((imageSize, imageSize), Image.ANTIALIAS)
        image = torchvision.transforms.ToTensor()(image)
        return image

    images = []
    for rawImg in (Path(dir).glob('*.png')):
    return images

someone help?

This looks like an issue that has recently surfaced; you might want to see if downgrading to PIL 8.2 works.
transform toTensor fails with PIL image · Issue #4146 · pytorch/vision (
Pillow 8.3 and NumPy · Issue #5571 · python-pillow/Pillow (


It works thanks very much!