목록인공지능 코드 (6)
Bamboo is coming
https://medium.com/@wfeng6/difference-between-cd-and-cd-in-google-colab-52f241da67f8 Difference between %cd and !cd in Google Colab In this article, you will hopefully understand the basic difference between !cd and %cd, and will be able to use colab better. medium.com !는 다시 원상복구 %는 현상유지
In PyTorch, both .cuda() and .to(device) are used to move tensors or models to the GPU, but there are some differences in their functionality: .cuda(): This method is specific to moving a tensor or model to the GPU (CUDA device). You can optionally specify a GPU device index (e.g., .cuda(0) to move to the first GPU). If you call .cuda() on a tensor or model that's already on the GPU, it will cre..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/qadM4/btsqYRWZmFi/G1EhrIp8svSFKyrPktw8T1/img.png)
colab에 옮겨적었는데 지우기 아까워서 킵함. 내용이 잘 돌아가는지 여부는 확인 안됨 Guided backpropagation은 기존 backpropagation-ReLu의 입력값이 음수면 0으로 초기화되는 동작에 가중치 역시 음수면 0으로 초기화되는 동작을 추가했다. **결국, Guided backpropagation은 입력값, 가중치값이 음수면 0으로 초기화시켜 출력에 긍정적인 영향을 끼치는 입력 이미지에 초점을 맞춰 중요한 기능을 시각적으로 식별할 수 있다.** Forward pass에서는, input image에서 양수인 부분들은 그대로 출력하고, 음수인 부분은 0으로 처리합니다.ReLU와 동일하다고 할 수 있죠. Backward pass에서, 우리가 살펴볼 내용은 가장 아래쪽에 있는 Guide..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/TZbmc/btsqYFh2Pos/MtD5IKazmKyne95mUp2gYK/img.png)
# 정상 코드 import torch import torch.nn as nn import torch.nn.functional as F from google.colab.patches import cv2_imshow class GradCam(nn.Module): def __init__(self, model, module, layer): super().__init__() self.model = model self.module = module self.layer = layer self.register_hooks() def register_hooks(self): for modue_name, module in self.model._modules.items(): if modue_name == self.module: ..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/RXwXH/btsqLlSYNdr/5dJc1tg2nIOTsOTQlBuJP0/img.png)
for name, child in model.named_children(): for param in child.parameters(): print(name, param) layer1의 weight, bias를 tensor 형식으로 출력
ImageFolder 이 방법을 사용하게 되면 분류에 사용 되는 라벨이 서브폴더의 이름으로 매겨지기 때문에 원하는 만큼 폴더를 만들어 놓은 뒤, 그 안에 나만의 이미지를 넣어두기만 하면 된다. 실제로 train_imgs.classes 와 train_imgs.class_to_idx 를 출력 해 보면 다음 처럼 클래스명과 클래스의 인덱스까지도 반환해 주는 것을 확인할 수 있다. ImageFolder return (path, class) def make_dataset( # ImageFolder 만들고 나서 호출할 수 있는 메소드 directory: str, class_to_idx: Dict[str, int], extensions: Optional[Tuple[str, ...]] = None, is_valid_f..