RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces)
Asked Answered
B

2

16

I am using Pytorch. I got this RuntimeError while evaluating a model. Any idea how to solve this?

Bouilli answered 22/3, 2021 at 16:50 Comment(1)
This link can be helpful github.com/cezannec/capsule_net_pytorch/issues/4Beutner
B
22

SOLUTION: Just replace the view() function with reshape() function as suggested in the error and it works.

I guess this has to do with how the tensor is stored in memory.

Bouilli answered 22/3, 2021 at 16:52 Comment(0)
H
14

SOLUTION2: change the .view(...) to .contiguous().view(...).

Actually, 'reshape()' does a similar job as contiguous() under the hood, if it needs.

Hypoderma answered 20/2, 2022 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.