Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- __init__
- python
- rnn
- pytorch
- ViT
- LSTM
- __call__
- pychram
- 파이썬문법
- objectdetection
- segmentation
- 딥러닝
- CNN
- tensorflow
- 가상환경
- 가상환경구축
- torch
- torch.nn
- Anaconda
- AI
- 컴퓨터비전
- Deep learning
- DeepLearning
- 파이썬
- vsC
- torch.nn.Module
- vision transformer
- NumPy
- Torchvision
- 머신러닝
Archives
- Today
- Total
인공지능을 좋아하는 곧미남
opencv에는 무조건 np array type을 input data로 넣자! 본문
아래 코드에서 cv2.imwrite()에 image data로 input을 넣었는데, 이때 위에서 torch.tensor type으로 선언되어 있습니다.
이때, numpy array로 변환하지 않으면 아래와 같은 TypeError가 발생합니다.
TypeError: Expected Ptr for argument '%s'
with torch.no_grad():
for idx, (input, target) in enumerate(zip(input_test, target_test)):
input, target = input.float().to(device), target.to(device)
output = endtoendmodel(input)
# Decoder
_, prediction = torch.max(output.data, 1)
for i in range(len(target)):
log = [(input.shape[0] * idx) + i, prediction[i], target[i]]
with open(os.path.join(log_dir, 'test_log.csv'), 'a') as f:
log_1 = list(map(str, log))
f.write(','.join(log_1) + '\n')
if not os.path.exists('./test_result_image'):
os.makedirs('./test_result_image')
cv2.imwrite('./test_result_image/'+'%4d'%(input.shape[0] * idx+i)+'.png' , np.array(input[i].permute(1, 2, 0).cpu(), dtype=np.float32))
그래서 아래와 같이 np array로 변환한 뒤 입력 변수에 넣어줍니다.
np.array(input[i].permute(1, 2, 0).cpu(), dtype=np.float32)
'code_study > opencv' 카테고리의 다른 글
Image Gradient (0) | 2022.04.12 |
---|---|
카메라 센서에 관한 고찰 (0) | 2022.03.07 |
Simultaneously Multi Camera Capture using Multi Thread (5) | 2022.02.09 |
Opencv 패키지를 이용한 Image Sequence를 Video로 변환! (0) | 2022.01.12 |
Comments