@NielsRogge,
Hi Niels, the issue I am facing when running layoutlmv3 model on FunsdDataset
return forward_call(*args, **kwargs)
File "/Users/im/Documents/projects_dl/ocr_layoutlm/myenv1/lib/python3.9/site-packages/transformers-4.32.0.dev0-py3.9.egg/transformers/models/layoutlmv3/modeling_layoutlmv3.py", line 345, in forward
embeddings = embeddings + spatial_position_embeddings
RuntimeError: The size of tensor a (512) must match the size of tensor b (4) at non-singleton dimension 2
I have created custom dataset for funds annotations and images as below
===
Upon training the Layoutlmv3Tokenforclassification model , runtime error of size mismatch is throwing when creating spatial position embedding.
File "/Users/im/Documents/projects_dl/ocr_layoutlm/myenv1/lib/python3.9/site-packages/transformers-4.32.0.dev0-py3.9.egg/transformers/models/layoutlmv3/modeling_layoutlmv3.py", line 345, in forward
embeddings = embeddings + spatial_position_embeddings
RuntimeError: The size of tensor a (512) must match the size of tensor b (4) at non-singleton dimension 2
I am not getting how to resolve this issue. Looking out for your help
Thanks,
@NielsRogge, Hi Niels, the issue I am facing when running layoutlmv3 model on FunsdDataset return forward_call(*args, **kwargs) File "/Users/im/Documents/projects_dl/ocr_layoutlm/myenv1/lib/python3.9/site-packages/transformers-4.32.0.dev0-py3.9.egg/transformers/models/layoutlmv3/modeling_layoutlmv3.py", line 345, in forward embeddings = embeddings + spatial_position_embeddings RuntimeError: The size of tensor a (512) must match the size of tensor b (4) at non-singleton dimension 2
I have created custom dataset for funds annotations and images as below
class CustomFunsdDataSet(Dataset): def init(self, filepath, processor): self.words = [] self.bboxes = [] self.images = [] self.word_labels = []
train_dataset = CustomFunsdDataSet(os.path.join(path, train), processor) train_sampler = RandomSampler(train_dataset) train_dataloader = DataLoader(train_dataset, sampler=train_sampler, batch_size=2)
Processor defined as:
feature_extractor = LayoutLMv3FeatureExtractor(apply_ocr=False) tokenizer = LayoutLMv3TokenizerFast.from_pretrained( "/Users/madhavim/Documents/projects_dl/ocr_layoutlm/src_layoutlmv3/model_layoutlmv3", ignore_mismatched_sizes=True)
processor = LayoutLMv3Processor(tokenizer=tokenizer, feature_extractor=feature_extractor)
=== Upon training the Layoutlmv3Tokenforclassification model , runtime error of size mismatch is throwing when creating spatial position embedding.
File "/Users/im/Documents/projects_dl/ocr_layoutlm/myenv1/lib/python3.9/site-packages/transformers-4.32.0.dev0-py3.9.egg/transformers/models/layoutlmv3/modeling_layoutlmv3.py", line 345, in forward embeddings = embeddings + spatial_position_embeddings RuntimeError: The size of tensor a (512) must match the size of tensor b (4) at non-singleton dimension 2
I am not getting how to resolve this issue. Looking out for your help Thanks,