728x90 Deep Learning (AI)20 [Pytorch] L1-loss, L2-loss, KLD-loss 역전파 L1 loss 역전파 및 언제 사용, 기대효과 L2 loss 역전파 및 언제 사용, 기대효과 + L1-loss의 미분값이 어떻게 업데이트 되는가? 딥러닝에서 학습되는 가중치 Weight는 다음과 같이 업데이트 됩니다. W = W - learning_rate * gradient_of_loss_with_respect_to_W 그렇기 떄문에, L1-loss로 인한 미분값 1 or -1의 값은 weight의 학습 뱡향을 바꾸게 됩니다. 예를 들어, 예측값 = 0.5, 정답값 = 0.7일 경우에 L1-loss의 gradient는 0.5-0.7 < 0 이므로, -1의 값이 됩니다. 이를, 가중치 업데이트에 반영하면, W = W + learning_rate * gradient_others (#others는 다른 lo.. 2023. 7. 20. [Pytorch] Softmax with CrossEntropyLoss 역전파 Softmax & Sigmoid with CrossEntropyLoss (CE Loss) forward and backward (calculate gradient). 아래 사진에 자세한 풀이과정을 적어놓음. softmax-with-CELoss의 입력(x)에 대한 역전파(미분값)는 softmax(x) - target(label). feaures of taget=1 and taget=0에 대해서는 부호를 반대로 역전파하여 모델이 cateogry classification ability를 학습한다. target이 one-hot label (single classification)이라는 전제하에, Softmax를 Sigmoid로 대체해도 미분값이 같기 때문에 동일한 결과를 얻을 수 있다. multi-class .. 2023. 7. 20. [에러해결] apex was installed without --cuda_ext. Fused syncbn kernels will be unavailable. Python fallbacks will be used instead. pip uninstall apex cd apex rm -rf build (if it exists) python setup.py install --cuda_ext --cpp_ext run again, clear! https://github.com/NVIDIA/apex/issues/86 Warning: apex was installed without --cuda_ext. · Issue #86 · NVIDIA/apex I install apex according this sentence: python setup.py install --cuda_ext --cpp_ext 2.After that, using import apex to test, but it report warning as following: War.. 2023. 7. 16. [에러해결] Argument save_interval is deprecated and should be None. This argument will be removed in 0.5.0.Please, use events filtering instead, e.g. Events.ITERATION_STARTED(every=1000) 해결 if u install ignite then uninstall ignite next, pip insatll pytorch-ignite==0.1.2 clear! 2023. 7. 16. [에러해결] no module named 'torchvision.models.utils 해결 from torchvision.models.utils import load_state_dict_from_url 예전 버전이므로 아래와 같이 바꾼다 from torch.utils.model_zoo import load_url as load_state_dict_from_url 2023. 7. 16. torch model parameter(params) 개수 구하기 from torchvision import models def get_n_params(model): pp = 0 for p in list(model.parameters()): nn = 1 for s in list(p.size()): nn = nn * s pp += nn return pp resnet50_pretrained = models.resnet50(pretrained=True) parms_num = get_n_params(resnet50_pretrained) # 25557032 = 25.55M 2023. 7. 16. torch seed 고정 코드 딥러닝 학습의 일관성을 위해서 아래와 같이 seed를 고정해주고, 제안된 방법들을 적용해야 효과를 정확히 측정할 수 있습니다. def set_seed_sejun(seed, cuda=True): np.random.seed(seed) torch.manual_seed(seed) random.seed(seed) if cuda: torch.cuda.manual_seed(seed) torch.cuda.manual_seed_all(seed) torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False 2023. 7. 15. [Pytorch] torch kld-loss (KD-loss) 코드 일반적인 힌튼 KD loss 코드 import torch.nn as nn import torch.nn.functional as F KL_loss = nn.KLDivLoss(reduction='batchmean')(F.log_softmax(outputs/T, dim=1), F.softmax(targets/T, dim=1))*(alpha*T*T) outputs student model output (feature -> classifer 결과) shape : (batch size, class num) targets teacher model outputs (feature -> classifier 결과) shape : (batch size, class num) T (Temperature) 얼마나 지식을 부드럽게 .. 2023. 7. 14. 이전 1 2 다음 728x90