일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Pull Request
- vscode
- WSSS
- 백신후원
- HookNet
- 사회조사분석사2급
- ssh
- aiffel exploration
- docker exec
- docker attach
- airflow
- AIFFEL
- 프로그래머스
- 코크리
- Decision Boundary
- CellPin
- numpy
- 히비스서커스
- 티스토리챌린지
- IVI
- 기초확률론
- Multi-Resolution Networks for Semantic Segmentation in Whole Slide Images
- cs231n
- GIT
- cocre
- logistic regression
- 도커
- docker
- 오블완
- Jupyter notebook
Archives
- Today
- Total
히비스서커스의 블로그
[Pytorch] AttributeError: 'DataParallel' object has no attribute 'predict' 본문
Programming/Python
[Pytorch] AttributeError: 'DataParallel' object has no attribute 'predict'
HibisCircus 2021. 10. 8. 10:55728x90

파이썬에서 딥러닝 프레임워크를 pytorch로 쓰다가 GPU 병렬처리를 위해서 DataParallel 처리를 해주었다.
import torch
# model 생성부분 생략
model = torch.nn.DataParallel(model, device_ids=[0,1,2,3]) # GPU 0,1,2,3 총 4개 사용
model.cuda()
모델을 학습까지 완료시킨 후 다음과 같이 model.predict()을 하니 아래와 같은 에러 메세지가 나왔다.
코드
# x_tensor 생성부분 생략
pr_mask = model.predict(x_tensor)
에러 메시지
AttributeError: 'DataParallel' object has no attribute 'predict'
해결 방안은 다음과 같이 model과 predict 사이에 .module을 추가하여 코드를 수정하면 된다.
pr_mask = model.module.predict(x_tensor)
이상없이 잘 돌아간다!
참고한 github issue
https://github.com/jytime/Mask_RCNN_Pytorch/issues/2
AttributeError: 'DataParallel' object has no attribute 'train_model' · Issue #2 · jytime/Mask_RCNN_Pytorch
Thank for your implementation, but I got an error when using 4 GPUs to train this model # model = torch.nn.DataParallel(model, device_ids=[0,1,2,3]) Traceback (most recent call last): File "bd...
github.com
-히비스서커스-
728x90