본문 바로가기

반응형

분류 전체보기

(290)
rdkit 설치하기 rdkit 공식 문서를 보면 pip 도 안되고 conda로 해라고 한다. 그런데 conda로도 안돼서 여러 삽질을 거치다 다음과 같은 해결법을 알게됐다. !pip install python-rdkit 위 명령어면 한 방에 해결된다. # General Imports import os import pandas as pd import numpy as np pd.options.display.max_columns=300 import warnings warnings.filterwarnings("ignore") from rdkit import Chem from rdkit.Chem import Draw, Descriptors from rdkit import DataStructs from rdkit.Chem import..
[pytorch] Expected cuda got cpu, 혹은 타입 에러 발생시 내가 주로 사용하는 함수는 torch.FloatTensor() torch.LongTensor() 인데 이게 안 먹는 경우가 있다. 그럴 경우 .float() .long() 으로 하면 된다.
[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..
[python] matplotlib을 이용해 png를 svg로 바꾸기, png to svg, png2svg, svg2png, svg to png 애초에 저장할 때 array를 svg로 저장하면 된다. x = plt.imread('../handwritting_fonts/0.png')[..., 0] image_format = 'svg' x.shape plt.imsave('0.svg', x, format='svg', cmap='gray') svg2png로 검증하기. from svglib.svglib import svg2rlg from reportlab.graphics import renderPM drawing = svg2rlg("0.svg") renderPM.drawToFile(drawing, "my.png", fmt="PNG")
[논문 읽기] ConvLSTM 이해하기 시계열에 좋은 LSTM! 이미지에 좋은 Conv! 이 둘을 짬뽕시킨 Convolutional LSTM을 알아보자. LSTM에 대한 사전지식이 필요하다. https://limitsinx.tistory.com/62 [코드로 이해하는 딥러닝 2-11] - RNN(Recurrent Neural Network)/LSTM(Long-Short-Term-Memory) [코드로 이해하는 딥러닝 0] - 글연재에 앞서 https://limitsinx.tistory.com/27 [코드로 이해하는 딥러닝 1] - Tensorflow 시작 https://limitsinx.tistory.com/28 [코드로 이해하는 딥러닝 2] - Tensorflow 변.. limitsinx.tistory.com $i_t$는 입력 게이트, $f..
[pytorch error] GAN학습시 에러, RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation 에러 발생시 대처법 This happens because the opt_D.step() modifies the parameters of your discriminator inplace. But these parameters are required to compute the gradient for the generator. Hence the error. We fixed the inplace detection for the optimizers in 1.5, this is why it works in 1.4. You should re-organize your code to only do the steps() after all the gradients have been computed or make sure you don't mo..

728x90
반응형