Questions tagged [einops]

12 questions
4
votes
1 answer

Dimension error by using Patch Embedding for video processing

I am working on one of the transformer models that has been proposed for video classification. My input tensor has the shape of [batch=16 ,channels=3 ,frames=16, H=224, W=224] and for applying the patch embedding on the input tensor it uses the…
dtr43
  • 135
  • 7
  • 19
3
votes
3 answers

Pytorch maxpooling over channels dimension

I was trying to build a cnn to with Pytorch, and had difficulty in maxpooling. I have taken the cs231n held by Stanford. As I recalled, maxpooling can be used as a dimensional deduction step, for example, I have this (1, 20, height, width) input ot…
Sun Chuanneng
  • 127
  • 1
  • 9
1
vote
1 answer

Reshaping a 3D array of shape (K, M, N) to 2D array of shape (n_rows * M, n_cols * N) with Numpy

I was trying to reshape a 3D array/tensor arr of shape (K, M, N) in numpy (where each (M, N) subarray could be an image for instance) to a 2D of shape (n_rows * M, n_cols * N). Obviously, I ensure K = n_rows * n_cols beforehand. I tried all the…
floflo29
  • 2,261
  • 2
  • 22
  • 45
1
vote
1 answer

Understanding fancy einsum equation

I was reading about attention and came across this equation: import einops from fancy_einsum import einsum import torch x = torch.rand((200, 10, 768)) y = torch.rand((20, 768, 64)) res = einsum("batch query_pos d_model, n_heads d_model d_head ->…
Sai Prashanth
  • 144
  • 2
  • 11
1
vote
0 answers

Simplify tensor-matrix operation with numpy.einsum or einops

I have the following inputs: T: a (H x W x C) tensor, or if needed (H x W x C x 1). M: (C x C) matrix. I need to compute a (H x W x C) tensor, in which each "slice" is the matrix product between M and the corresponding (1 x 1 x C) slice from T,…
Milo
  • 2,062
  • 16
  • 38
1
vote
1 answer

Performing simple custom operations with Einsum

I am new to Einsum and wanted a particular case - using einsum for multiplying all elements of a matrix with each other; say given a 2D matrix:- np.random.rand((16,2)) Multiplying elements across an axis obtaining (16,) and then multiplying those…
neel g
  • 1,138
  • 1
  • 11
  • 25
1
vote
1 answer

Einops rearrange function basic functionallity

I'm trying to grok the einops syntax for tensor reordering, but am somehow missing the point If I have the following matrix: mat = torch.randint(1, 10, (8,4)) I understand what the following command does: rearrange(mat, '(h n) w -> (n h) w', n =…
user680111
  • 971
  • 1
  • 9
  • 17
0
votes
1 answer

Tensorflow Tutorial Error. "Tensor is unhashable. Instead, use tensor.ref() as the key"

I was using the colab notebook in the link below and it was working fine. https://www.tensorflow.org/tutorials/video/video_classification Now I am trying to use it again and I am getting the error below when I start fitting the model. ----> 3…
Hammond
  • 11
  • 2
0
votes
2 answers

EinopsError: Error while processing rearrange-reduction pattern "(b1 b2) h w c -> (b1 h) (b2 w) c"

I'm learning the basics of einops to incorporate in my code. process = transforms.Compose([ transforms.Resize(225), transforms.ToTensor() ]) cat = Image.open('cat.jpeg').convert('RGB') cat = process(cat) rearrange(cat, '(b1 b2) h w c ->…
0
votes
0 answers

Even though I have Einops installed in the virtual environment, I was unable to import it

Basically, the title, I'm trying to import Einops after installing it through pip, but I can't. I'm using VScode and I'm inside a Jupyter notebook file. As you can see from the bottom of the picture I attached, I have einops installed. I'm in my…
franc-coding
  • 1
  • 1
  • 2
0
votes
1 answer

einops not equivalent to torch.chunk?

I'm trying to replicate the following 2 lines in einops: emb = emb[..., None, None] cond_w, cond_b = th.chunk(emb, 2, dim=1) So far, I've managed to get: emb = rearrange(emb, "b (c h w) -> b c h w", w=1, h=1) cond_w, cond_b = th.chunk(emb, 2,…
Foobar
  • 7,458
  • 16
  • 81
  • 161
0
votes
1 answer

Generating probabilites from patches of image

I am working with an image of size 512x512. The image is divided into patches using einops with patch size of 32. The number of patches overall is 256, in other words, we get a new "image" of size 256x1024. Since this image is actually a mask for a…
user574362
  • 67
  • 1
  • 7