microsoft / unilm

Large-scale Self-supervised Pre-training Across Tasks, Languages, and Modalities
https://aka.ms/GeneralAI
MIT License
19.6k stars 2.5k forks source link

Issue in the backbone of LayoutLMv2 : /modeling_layoutlmv2.py", line 607, in forward images_input = (images.tensor - self.pixel_mean) / self.pixel_std AttributeError: 'Tensor' object has no attribute 'tensor' #472

Open MuhammadBilal121 opened 2 years ago

MuhammadBilal121 commented 2 years ago

I am trying to run the layout-xlm with customized dataset and facing this issue

Issue in the backbone of LayoutLMv2. I tried following but didnt worked out .

1)I tried to resolve issue by making changes in data_collactor batch['image'] = ImageList.from_tensors([feature['image'] for feature in features], 32

2)in modelling_layoutlmv2: def forward(self, images): images_input = ( (images if torch.is_tensor(images) else images.tensor) - self.pixel_mean ) / self.pixel_std

ranpox commented 2 years ago

Could you share a code snippet to reproduce this error? Thanks.

sherlocked27 commented 2 years ago

Removing .tensor should work as the images is already a tensor and explicitly converting it to tensor again raises error.

 images_input = (
            (images if torch.is_tensor(images) else images.tensor) - self.pixel_mean
        ) 

Can you share what error you are getting after this change.

mariem-m11 commented 3 months ago

I am having the same issue, did anyone know what's the solution?