본문 바로가기

인공지능/Python

(22)
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..
Data Parallel(DP), Distributed Data Parallel(DDP)의 차이 목차 Keywords Data Parallel(DP), Distributed Data Parallel (DDP), Multi-GPU training, All reduce Data Parallel(DP), Distributed Data Parallel(DDP)의 차이 Compared to DataParallel, DistributedDataParallel requires one more step to set up, i.e., calling init_process_group. DDP uses multi-process parallelism, and hence there is no GIL contention across model replicas. Moreover, the model is broadcast at..
Tensorflow/Keras Out of memory 해결 Out of memory out of memory(이후 OOM)는 여러가지 경우에 발생할 수 있다. 하지만 본문에서 다뤄볼 경우는 하나의 서버 (multi-gpu 환경 포함)에서 여러 keras process를 실행할 때 발생하는 OOM에 대해 말한다. 우선 같은 서버 내에 keras model을 사용하는 process를 실행한 뒤 keras model을 사용하는 process를 하나 더 실행하게 되면 나중에 실행한 process는 높은 확률로 OOM에러를 뿜고 사망할 것이다. Why? 사용자의 잘못이 아닌 tensorflow의 정책 때문이다. 이에 대한 이유로 다음과 같이 설명하고 있다: By default, TensorFlow maps nearly all of the GPU memory of all ..
python mask to polygon, reducing points in polygon Introduction 2021 인공지능 온라인 경진대회의 hair segmentation 부분에 참여를 했고, 그 과정에서 가장 많이 고생했으면서 새롭게 알았던 부분에 대해 공유를 하고자 이 글을 작성한다. 우리 팀에서 사용한 모델은 torchvision의 mask R-CNN로 mask를 결과물로 줬고, 대회 submission form은 polygon이었다. 여기서 mask는 binary로 제공되지 않고, 각 픽셀 별 확률로 나타나 있기 때문에, 어느정도까지를 mask로 봐야할지 정하는 threshold 또한 최적화를 진행했다. 출력으로 얻는 mask 이미지를 polygon으로 바꿔야했고, submission json 파일크기에 제한이 있어 polygon의 갯수를 줄여야(최적화) 했다. mask를 p..