반응형

pytorch 82

[PyTorch] RuntimeError("grad can be implicitly created only for scalar outputs")

UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector RuntimeError("grad can be implicitly created only for scalar outputs") 위와 같은 에러가 발생했다. loss.backward() 에서 발생했는데.. loss.shape = ([2]) 로 되어 있기 때문이다. 파이토치 DP를 쓰면서 loss가 gpu 수 만큼 반환하게 되어, vector를 출력하게 된 것이다. loss.backward()를 위해서는 loss가 scalar이어야 하낟. 따라서 loss.mean().backw..

[PyTorch] Error: one of the variables needed for gradient computation has been modified by an inplace operation

파이토치 오류 https://discuss.pytorch.org/t/one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation-torch-cuda-floattensor-3-48-3-3-is-at-version-2-expected-version-1-instead/83241 One of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [3, 48, When I was training the GAN, the first iteration worked ..

[PyTorch] Boolean value of Tensor with more than one value is ambiguous

pred와 target값을 loss function에 전달하여 loss를 계산할때 아래와 같은 오류가 발생했다. Boolean value of Tensor with more than one value is ambiguous loss 계산 코드를 잘못 짠게 원인이었다. def mse_loss(pred, target): loss = nn.MSELoss(pred, target) return loss 위 코드를 아래와 같이 수정하니 오류 해결! def mse_loss(pred, target): loss_func = nn.MSELoss() loss = loss_func(pred, target) return loss

[논문 구현] ViT(2020) PyTorch 구현 및 학습

공부 목적으로 ViT를 구현하고 학습한 내용을 공유합니다 ㅎㅎ. 작업 환경은 Google Colab에서 진행했습니다. 필요한 라이브러리를 설치 및 임포트합니다. !pip install einops import torch import torch.nn as nn import torch.nn.functional as F import matplotlib.pyplot as plt %matplotlib inline from torch import optim from torchvision import datasets import torchvision.transforms as transforms from torch.utils.data import DataLoader import os from torchvision im..

논문 구현 2021.08.04

[PyTorch] nn.Sequential 을 상속받아 Class 정의하기

안녕하세요, 이번 포스팅에서는 class를 정의하는 경우에 nn.Module이 아닌 nn.Sequential을 상속하여 사용하는 것에 대해 알아보겠습니다. nn.Module 대신에 nn.Sequential을 subclass하면 어떤 이점이 있을까요?? 바로 forward method를 작성하지 않아도 됩니다 ㅎㅎ 예시 코드를 살펴보겠습니다. # Subclassing nn.Sequential to avoid writing the forward method. class FeedFowardBlock(nn.Sequential): def __init__(self, emb_size, expansion=4, drop_p=0.): super().__init__( nn.Linear(emb_size, expansion *..

[논문 구현] MoCov2(2020) PyTorch 구현

안녕하세요, 이번 포스팅에서는 MoCov2를 Google Colab 환경에서 PyTorch로 구현해보도록 하겠습니다. 논문 리뷰와 전체 코드는 아래 주소에서 확인하실 수 있습니다. [논문 읽기] MoCov2(2020), Improved Baselines with Momentum Contrastive Learning 안녕하세요, 오늘 읽은 논문은 Improved Baselines with Mometum Contrastive Learning 입니다. 해당 논문은 MoCo v1에서 SimCLR의 두 가지 아이디어를 적용한 모델입니다. SimCLR은 contrastive learning.. deep-learning-study.tistory.com Seonghoon-Yu/MoCov2_Pytorch_tutorial..

논문 구현 2021.07.12

[논문 읽기] PyTorch 코드로 살펴보는 Transformer(2017)

안녕하세요, 오늘 읽은 논문은 transformer을 제안하는 Attention is All You Need 입니다. 논문에서는 self-attention 으로 구성된 encoder와 decoder을 사용합니다. self-attention 작동 방법이 이해가 되질 않아서 2~3일 동안 공부했네요..ㅎㅎ 저는 이해가 잘 안될때는 코드와 함께 보는 편입니다. 코드를 보면서 어떤 과정으로 데이터가 처리되는지 확인하면 이해가 더 잘되는 것 같아요. 자연어처리 모델은 익숙하지가 않아서 아래 깃허브를 참고하면서 공부했어요. 구현 코드와 논문 설명이 함께 되어 있어서, 큰 도움이 되었습니다 ㅎㅎ bentrevett/pytorch-seq2seq Tutorials on implementing a few sequence-..

논문 읽기/NLP 2021.06.28

[PyTorch] VOC Segmentation 데이터셋 사용하기

안녕하세요, 이번 포스팅에서는 PyTorch에서 제공하는 VOC Segmentation dataset을 사용해보도록 하겠습니다. 우선 transformation을 정의하기 위한 albumentations 모듈을 설치합니다. !pip install -U albumentations 필요한 라이브러리를 import 합니다. from torchvision.datasets import VOCSegmentation from torchvision.transforms.functional import to_tensor, to_pil_image from PIL import Image import torch import numpy as np from skimage.segmentation import mark_boundari..

반응형