본문 바로가기

분류 전체보기

(38)
model 학습 시 loss대신 predict 결과가 나올 경우 Problem mask rcnn transfer learning중에 loss dict를 구하는 상황이었는데, model(image,target)넣어도 다음처럼 predict 결과만 숭숭 나왔다. {'boxes': tensor([[ 23.0990, 377.5876, 305.9265, 562.2125], [ 11.2159, 242.4047, 369.8665, 428.1471], [155.2247, 96.2208, 580.0000, 248.9312], [ 5.0806, 275.1395, 101.7696, 426.0195], [ 20.9149, 266.0938, 331.9341, 614.7516], [ 11.2956, 134.7541, 386.5382, 542.4605], [ 57.4241, 228.0799, ..
Dataloader dictionary에서 batch를 밖으로 빼내기 Problem 기존에 pytorch로 구현되어 있는 maskrcnn training 코드를 pytorch lightning으로 바꾸다가 발생한 문제. 모델의 loss를 계산하기위해 입력하는 데이터의 형식이 약간 다른 문제가 발생. batch가 dictionary 안에 들어가 있어서 이를 dictionary 밖으로 빼내야 한다. # 현재 상태 { 'boxes': tensor([[[ 25., 209., 343., 610.]], [[181., 138., 550., 608.]]], device='cuda:1') } # 되어야하는 상태 # batch가 dictionary 밖으로 나와야함 [ {'boxes': tensor([[ 25., 209., 343., 610.]], device='cuda:1')}, {'box..
RuntimeError: stack expects each tensor to be equal size 에러 해결 Problem mask rcnn 모델을 학습하기위해 dataset과 dataloader를 구성한 뒤 코드를 실행했을 때, 다음과같은 에러가 발생했다 RuntimeError: stack expects each tensor to be equal size, but got [3, 680, 720] at entry 0 and [3, 580, 620] at entry 4 Solution batch로 묶는 이미지의 사이즈가 달라서 묶을 수 없다고하는 뜻이라, dataloader setup의 transform에 resize를 넣어서 해결해야 한다. def get_transform(self): transform = [ transforms.Resize((580,620)), ToTensor() ] return Compose..
change edge thickness (using opencv Morphological Transformations ) Problem cv2.canny를 이용해 추출한 edge의 thickness를 올리고 싶어서 방법을 찾던중 형태학적 변환(Morphological Transformations)을 opencv에서 이미 제공을 하고 있는 것을 발견했다. thickness를 늘릴수도있고, 줄일수도있고, 잡티를 제거할수도 있는등, 다양한 방법을 제공하고 있었다. 난 그중에 thickness를 늘리는 것이 목적이었으므로 해당 함수를 적용했다. Solution plt.subplot(1,3,1) plt.imshow(edges,cmap='gray') plt.subplot(1,3,2) kernel = np.ones((3,3),np.uint8) dilation = cv2.dilate(edges,kernel,iterations = 1) p..
gray scale image to RGB image (using opencv) Problem image에서 egde를 추출할 일이 있었는데, edge는 gray scale이라 1channel만 가지고 있었다. 원본 image에 edge를 추가할 목적이라 1channel의 edge를 3channel로 맞춰주는 작업이 필요했다. Solution # original image read img = cv2.imread('/path/to/image.jpg') img.shape # (680,720,3) # Canny Edge Detection edges = cv2.Canny(image=img, threshold1=50, threshold2=200) edges.shape # (680,720) # 1channel image to 3channel image img2 = cv2.merge((edges..
AttributeError: 'YourDataModule' object has no attribute '_has_prepared_data' 해결방법 Problem LightningDataModule을 다루면서 나타난 에러인데, 처음엔 단순히 prepare_data 함수를 정의하지 않아서 발생한 문제인 줄 알았는데, 해당 함수를 정의했음에도 불구하고 다른 _has_~~~ 에러들이 발생했다. AttributeError: 'YourDataModule' object has no attribute '_has_prepared_data' Solution 해결방법은 굉장히 간단했는데, LightningDataModule의 init안에 super().__init__()를 작성하면 바로 해결이 된다. def __init__(self, root, batchsize = 16,num_workers=24): super().__init__() self.root = root s..
LightningDataModule을 for loop에서 이용하는 방법 Problem LightningDataModule을 만들어서 Trainer에 직접 넣는 것은 해봤지만, predict할 때도 이용을 해보고 싶어서 이거저거 찾던 와중에 대부분의 코드는 다음처럼 batch를 불러오는 것을 확인했다. dl = AutoEncoderDataLoader(root = data_path, batchsize=128) dl.setup() next(iter(dl)) 근데 난 for loop으로 돌리고 싶어졌다. 단순히 그 이유였다. Solution for batch in dl.train_dataloader(): #do something 간단하다.
Warning: find_unused_parameters=True 해결방법 (DDP programming) Problem DDP 코드를 만들어 학습하다가 갑자기 아래 warning이 발생했다. [W reducer.cpp:1050] Warning: find_unused_parameters=True was specified in DDP constructor, but did not find any unused parameters. This flag results in an extra traversal of the autograd graph every iteration, which can adversely affect performance. If your model indeed never has any unused parameters, consider turning this flag off. Note that thi..