데브코스 자율주행 최종 프로젝트 - 17주차 수요일 TIL

YUNJI·2024년 2월 7일
0

오늘 한 일

  • CenterPoint 3D cuboid 2D projection 알고리즘 수정

    : 2D projection된 좌표 값의 평균을 이용해 박스를 그렸더니 박스가 객체에 핏하게 생성되지만, 종종 객체보다 작게 그려지는 경우 발생

    : 구해진 좌표 값의 최대, 최소 값을 이용해 박스를 그렸다.

  • CenterPoint 3D cuboid heading 표시하기

    : CenterPoint를 통해 구해진 3D cuboid의 heading을 2D projection 결과에 나타내었다.

  • fusion 결과 기준 잡기
    : 관련 논문 서치

새롭게 알게 된 점

parser.add_argument의 action

: parser.add_argument를 통해 인자를 정의할 때, action을 지정할 수 있다.
: 지정할 수 있는 action은 다음과 같다.

  • store : action을 지정하지 않으면 기본 값으로 들어가며, 인자 이름에 따라오는 값을 저장한다.
  • store_const : 이 액션을 적어주면 주어진 const 값을 저장하며, 인자를 적지 않으면 None 값이 저장된다.
    parser.add_argument('--ex', action = 'store_const', const = '1')
    
    # 액션을 적지 않은 경우, default로 None이 주어지고, default가 지정된 경우 해당 값이 주어진다.
    > python test.py
    args.ex: None
    
    # 액션을 적어주면 지정된 const 값이 주어진다.
    > python test.py --ex
    args.ex: 1
  • store_true (store_false) : 이 액션을 적어주면 true(false)가 반환되며, 적어주지 않는 경우 false(true)가 반환된다.
    parser.add_argument('--ex', action = 'store_true')
    
    # 액션을 적지 않은 경우 false를 반환
    > python test.py
    args.ex: false
    
    # 액션을 적어주면 true를 반환
    > python test.py --ex
    args.ex: true

차원 재배치

  • reshape( ) 함수
    : reshape 함수는 가능하면 input 그대로의 view를 반환하고, 형태상 불연속적인 경우 contiguous한 텐서로 복사한 뒤 view를 반환한다.

  • view( ) 함수
    : view 함수는 contiguous한(연속적인) 텐서에 대해서만 작동한다. view 함수는 기존 input과 메모리 공간은 공유하는 게 특징이라, view 함수로 반환된 텐서가 변경되면 기존 input도 바뀌고, 불연속적인 텐서를 처리할 수 없다.
    : 불연속적인 텐서의 차원을 재배치하려면 contiguous 함수를 통해 연속적인 형태로 바꾸거나 reshape 함수를 사용해야 한다.

>>> import numpy as np
>>> import torch

>>> t = np.zeros((5,2,4))
>>> t_tensor = torch.FloatTensor(t)
>>> print(t_tensor.shape)
torch.Size([5, 2, 4])
>>> print(t_tensor.view([-1, 4]).shape)
torch.Size([10, 4])
>>> print(t_tensor.reshape([-1, 4]).shape)
torch.Size([10, 4])

# 0과 1 차원을 바꿔 t_tensor를 불연속적이게 만들었다.
>>> t_tensor = t_tensor.transpose(0, 1)
>>> t_tensor.is_contiguous()
False

# 연속적이지 않은 텐서에 대해 view를 사용하면 다음과 같은 에러가 발생한다.
>>> print(t_tensor.view([-1, 4]).shape)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
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.

# contiguous 함수를 사용해 연속적인 텐서로 바꿔준 뒤 view를 적용하면 에러가 발생하지 않는다.
>>> t_tensor = t_tensor.contiguous()
>>> print(t_tensor.view([-1, 4]).shape)
torch.Size([10, 4])

[action 참고 사이트] https://greeksharifa.github.io/references/2019/02/12/argparse-usage/

[차원 재배치 참고 사이트]
https://anweh.tistory.com/12
https://titania7777.tistory.com/3

0개의 댓글

관련 채용 정보