question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EinopsError raised

See original GitHub issue

After uploading a picture, this error is raised:

File "C:\Users\zhang\anaconda3\lib\site-packages\einops\einops.py", line 418, in reduce
    raise EinopsError(message + '\n {}'.format(e))
einops.EinopsError:  Error while processing rearrange-reduction pattern "b n (h d) -> b h n d".
 Input tensor shape: torch.Size([1, 512]). Additional info: {'h': 8}.
 Expected 3 dimensions, got 2

This error also appears on google colab:

Saving Screenshot 2022-07-12 113227.png to Screenshot 2022-07-12 113227.png
---------------------------------------------------------------------------
EinopsError                               Traceback (most recent call last)
[/usr/local/lib/python3.7/dist-packages/einops/einops.py](https://localhost:8080/#) in reduce(tensor, pattern, reduction, **axes_lengths)
    409         recipe = _prepare_transformation_recipe(pattern, reduction, axes_lengths=hashable_axes_lengths)
--> 410         return _apply_recipe(recipe, tensor, reduction_type=reduction)
    411     except EinopsError as e:

17 frames
EinopsError: Expected 3 dimensions, got 2

During handling of the above exception, another exception occurred:

EinopsError                               Traceback (most recent call last)
[/usr/local/lib/python3.7/dist-packages/einops/einops.py](https://localhost:8080/#) in reduce(tensor, pattern, reduction, **axes_lengths)
    416             message += '\n Input is list. '
    417         message += 'Additional info: {}.'.format(axes_lengths)
--> 418         raise EinopsError(message + '\n {}'.format(e))
    419 
    420 

EinopsError:  Error while processing rearrange-reduction pattern "b n (h d) -> b h n d".
 Input tensor shape: torch.Size([1, 512]). Additional info: {'h': 8}.
 Expected 3 dimensions, got 2

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
pkjq11commented, Jul 13, 2022

In https://github.com/rwightman/pytorch-image-models/blob/master/timm/models/vision_transformer.py The default value of parameter global_pool of VisionTransformer is “token”

def forward_head(self, x, pre_logits: bool = False):
        if self.global_pool:
            x = x[:, self.num_prefix_tokens:].mean(dim=1) if self.global_pool == 'avg' else x[:, 0]
        x = self.fc_norm(x)
        return x if pre_logits else self.head(x)

So we can add an argument (global_pool=“”) to construct CustomVisionTransformer in “hybrid.py”, like this image

0reactions
lukas-blechercommented, Jul 13, 2022

Will push the update to pypi when I get home. Until then you can call

pip install -U git+https://github.com/lukas-blecher/LaTeX-OCR.git

Edit: Done

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the einops.einops.EinopsError function in einops
3: raise EinopsError('Expression may contain dots only inside ellipsis (...); only one ellipsis for tensor ') expression = expression.replace('.
Read more >
EinopsError: Error while processing rearrange-reduction ...
Raises the error: EinopsError: Error while processing rearrange-reduction pattern "(b1 b2) h w c -> (b1 h) (b2 w) c".
Read more >
einops.reduce
einops.reduce provides combination of reordering and reduction using reader-friendly notation. Examples for reduce operation: >>> x = ...
Read more >
einops.EinopsError Example - Program Talk
def _report_axes(axes: set, report_message: str): if len(axes) > 0: raise EinopsError(report_message.format(axes)) class WeightedEinsumMixin:.
Read more >
einops - Rust - Docs.rs
Almost all the operations specified in its tutorial should be available, if you find any inconsistencies please raise a github issue.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found