RuntimeError: view size is not compatible with input tensor's size and stride ~

2023. 1. 30. 22:45·Error Note
728x90
반응형
반응형

- 전체 에러 문구

RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.

​

expand(), view(), transpose() 등의 함수를 이용해 텐서의 모양을 바꿀 때 새로운 텐서를 생성하는 것이 아니라, 저장된 메모리의 주소는 그대로 둔체 텐서의 모양만 바꾸게 됩니다. 이런 경우 메모리 주소가 연속적이지 않게 변하게되므로 발생하는 에러입니다.

​

​

- 해결 방법

연속적이지 않은 메모리 주소를 연속적이게 만들어주면 됩니다.

1) contiguous() 사용하기

x.contiguous().view([-1])

 

2) reshape() 사용하기

x.reshape([-1])

메모리 주소의 연속성인 contiguous()에 대한 자세한 설명은 이곳을 참고해주세요!

 

728x90
반응형
저작자표시 (새창열림)

'Error Note' 카테고리의 다른 글

[Pytorch] Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!  (0) 2023.03.01
[Bug]Invalid SOS parameters for sequential JPEG  (0) 2023.02.05
RuntimeError: grad can be implicitly created only for scalar outputs  (0) 2023.01.30
RuntimeError: result type Float can't be cast to the desired output type Long  (0) 2023.01.30
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor,,,  (0) 2023.01.30
'Error Note' 카테고리의 다른 글
  • [Pytorch] Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
  • [Bug]Invalid SOS parameters for sequential JPEG
  • RuntimeError: grad can be implicitly created only for scalar outputs
  • RuntimeError: result type Float can't be cast to the desired output type Long
ga.0_0.ga
ga.0_0.ga
    반응형
    250x250
  • ga.0_0.ga
    ##뚝딱뚝딱 딥러닝##
    ga.0_0.ga
  • 전체
    오늘
    어제
    • 분류 전체보기 (181)
      • Paper Review (51)
        • Video Scene Graph Generation (6)
        • Image Scene Graph Generation (18)
        • Graph Model (5)
        • Key Information Extraction (4)
        • Fake Detection (2)
        • Text to Image (1)
        • Diffusion Personalization (4)
        • etc (11)
      • AI Research (49)
        • Deep Learning (30)
        • Artificial Intelligence (15)
        • Data Analysis (4)
      • Pytorch (10)
      • ONNX (5)
      • OpenCV (2)
      • Error Note (34)
      • Linux (2)
      • Docker (3)
      • Etc (7)
      • My Study (16)
        • Algorithm (10)
        • Project (4)
        • Interview (2)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    활성화 함수
    차원의 저주
    알고리즘
    나이브 베이즈 분류
    linear regression
    그래프신경망
    pandas
    Logistic regression
    Activation Function
    tensorflow
    RuntimeError
    torch.nn
    정규화
    GCN
    dataloader
    오차 역전파
    fine tuning
    dataset
    permute
    ONNX
    contiguous
    forch.nn.functional
    TypeError
    Inductive bias
    3dinput
    pytorch
    transformer
    i3d
    HRNet
    JNI
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
ga.0_0.ga
RuntimeError: view size is not compatible with input tensor's size and stride ~
상단으로

티스토리툴바