pytorch (20) 썸네일형 리스트형 [pytorch] AttributeError: module 'distutils' has no attribute 'version' 에러 해결 문제점 해결 pip install setuptools==59.5.0 https://github.com/pytorch/pytorch/issues/69894 [pytorch] one-hot encoding이 반드시 필요할까? 그렇지 않다. F.cross_entropy 에선 one-hot 인코딩을 하지 않아도 cross entropy loss를 잘 계산해준다. 예를 들어 카테고리가 3개라고 하면 pred 값은 (B, 3) 형태일 것이다. B는 배치 사이즈 이때 target의 형태는 [B] 이면 된다. 각 Batch 마다 하나의 값을 int 값으로 갖고 있으면 된단 말이다. pytorch 에선 .long()으로 케스팅해주면된다. [B, 3]처럼 one-hot encoding 해줄 필요 없음. Is One-Hot Encoding required for using PyTorch's Cross Entropy Loss Function? Is One-Hot Encoding required for using PyTorch's Cross E.. [pytorch] pytorch cross entropy 사용시 주의할 점, tf sparse categorical cross entropy in pytorch? softmax가 이미 F.cross_entropy에 포함되어 있다. 따로 레이어에 추가히지 말자. LSTM 구현 예제 1. return_sequences가 없을 때 hidden_dim = 75 #150 class SimpleLSTM(LightningModule): def __init__(self, input_features, output_features, batch_first, num_classes): super(SimpleLSTM, self).__init__() self.lstm = nn.LSTM(input_size=input_features, hidden_size=output_features, batch_first=batch_first) self.linear = nn.Linear(output_feat.. [pytorch] RuntimeError: 0D or 1D target tensor expected, multi-target not supported 에러 nn.CrossEntropyLoss() 혹은 F.cross_entropy 를 사용했을 때 나타나는 에러일 것이다. nn.CrossEntropyLoss()(pred, target) 이렇게 계산이 되는데 가령 pred의 shape의 [ B, C]라면 C는 클래스 갯수 B는 배치 사이즈 target의 shape은 [B] 가 되어야 하는데 [B, 1]이렇게 돼서 문제가 발생하는 거다. 그래서 문제를 해결하려면 target의 shape를 축소해주자. nn.CrossEntropyLoss()(pred, target.squeeze(dim=-1)) https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html CrossEntropyLoss — PyTor.. [torch] RuntimeError("{} is a zip archive 에러 해결 방법 에러 RuntimeError("{} is a zip archive (did you mean to use torch.jit.load()?)".format(f.name)) when loading model weights 문제 원인 : 학습은 torch 1.6 이상으로 하고 인퍼런스는 torch 1.6 버전 이하로 할 경우 위와 같은 에러가 발생한다. 해결 방법 : 학습시 모델을 저장할 때 다음과 같은 옵션을 추가하여 저장해준다. torch.save(model.state_dict(), path, _use_new_zipfile_serialization=False) [pytorch] torch.utils.data.DataLoader 이용시 파일 경로 출력 배경 efficientNet을 이용한 간단한 분류기 만들기 github.com/narumiruna/efficientnet-pytorch narumiruna/efficientnet-pytorch A PyTorch implementation of "EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks". - narumiruna/efficientnet-pytorch github.com shutil 을 이용해서 파일을 분류하고 분류 결과대로 저장하고 싶었다. 그래서 파일명이 필요했다. 과정 from torchvision.datasets import ImageFolder 보통 Image data의 경우 ImageFolder를 쓴다. fr.. [pytorch] type casting 하기, 타입 변환하기 가끔 가다가 RuntimeError: expected scalar type Float but found Double 이런 에러가 발생한다. 그럴경우... a 라는 텐서가 있으면 아래와 같이 케스팅해주면 된다. type도 변환된 자기 자신을 리턴한다. a = a.type(torch.FloatTensor).to(device) [논문 읽기] SeFa - Closed-Form Factorization of Latent Semantics in GANs 핵심 코드 분석 transformation matrix A에 대해 조사해야한다. 왜냐면 An의 최댓값을 이미지 Edit을 최대화 시킬 수 있기 때문이다. 그래서 A^TA의 고유벡터와 고유값을 찾는다. gan_type = parse_gan_type(net.decoder) layers, boundaries, values = factorize_weight(net.decoder, args.layer_idx) generator의 weight와 layer 인덱스를 인자로 받고, 그 결과로 layers, boundarys, values를 내 뱉는다. 문맥상 layers는 이미지 Edit에 관여된 layer들을 의미하고, boundarys가 고유 벡터, values가 고유값을 의미하는 듯하다. 위 값들은 실제 코드에 어떻게 쓰일까? .. 이전 1 2 3 다음