본문 바로가기

AI/PyTorch

[PyTorch] torch.tensor.float(), torch.mean()

torch.float()

 

_, argmax = torch.max(outputs, 1)
accuracy = (labels == argmax).float().mean()

 

torch.tensor.float()는 인자값을 넣지 않고 실행시킨다.

TORCH.TENSOR.FLOAT

Tensor.float(memory_format=torch.preserve_format) → Tensor

self.float() is equivalent to self.to(torch.float32). See to().

Parameters

memory_format (torch.memory_format, optional) – the desired memory format of returned Tensor. Default: torch.preserve_format.

 


torch.mean()

 

 

torch.Tensor.mean — PyTorch 1.9.0 documentation

Shortcuts

pytorch.org

 

 

 

 

tensor를 float()로 만든다.

  • torch.mean(input)
  • input.mean()

두 가지 방법이 있다.

 

 

  • torch.tensor는 객체 자체를 계산시키는 방법이다.
  • torch.mean은 함수로 인자값을 넣어 계산한다.

 

https://frieden1946.tistory.com/556?category=952749 에서 나온 차이점과 동일하다고 할 수 있다.