Thank you for your help, the sample code that you gave me do exactly what I want anyway I don’t know how implement the first piece of code.
I load my imagewith datasets.Imagefolder function, this one allow me to divide under the root path every image by class in different folder (and automatically understand that each folder is a different target) so I don’t know how can I use glob in this case.

Image folder.png1160×782 157 KB

Anyway I have implemented a lambda function in the transform function of my dataset and seems to work for binarizing.
data_transform = transforms.Compose([
        transforms.Resize((64,64)),
        transforms.Grayscale(),
        transforms.ToTensor(),
        transforms.Normalize(mean=[0.5, 0.5, 0.5],
                            std=[0.225, 0.225, 0.225]),
        lambda x: x>0,
        lambda x: x.float(),
        transforms.Normalize(mean=[0.5, 0.5, 0.5],
                            std=[0.225, 0.225, 0.225])
    ])

I still have to implement masking on input
Thank you for your help
Matteo