Tutorial-Book icon indicating copy to clipboard operation
Tutorial-Book copied to clipboard

Tutorial-Book/chapters/object-detection/Ch5-Faster-R-CNN

Open utterances-bot opened this issue 4 years ago • 12 comments

5. Faster R-CNN — PseudoLab Tutorial Book

https://pseudo-lab.github.io/Tutorial-Book/chapters/object-detection/Ch5-Faster-R-CNN.html

utterances-bot avatar Oct 28 '21 21:10 utterances-bot

안녕하세요 좋은 글 감사드립니다.

다름이 아니라 혹시 이 모델을 활용해서 새로운 데이터(이미지)의 mask detection을 하려면 혹시 어떤 방식으로 진행하면 될까요?

chush25 avatar Oct 28 '21 21:10 chush25

안녕하세요 @chush25 님. 5.6절에 나와 있는 test_data_loader에 예측하시고자 하는 새로운 이미지를 data_loader 객체로 저장해두신 후 5.6절에 있는 for 반복문을 그대로 활용하여 순차적으로 예측을 수행해주시면 됩니다.

SDSTony avatar Nov 01 '21 10:11 SDSTony

답변 감사드립니다! 추가적으로 질문을 드리고 싶은데, 앞에 데이터 전처리 과정에서 data augmentation을 수행하였지만, RetinaNet과 Faster R-CNN같은 경우 data augmentation 작업을 진행하지 않은 것으로 보이는데 혹시 이유가 있을까요??

chush25 avatar Nov 04 '21 17:11 chush25

별다른 이유는 없습니다! 필요에 따라 augmentation 과정을 추가하여 모델 성능이 올라가는지 비교해보셔도 좋을 것 같습니다!

SDSTony avatar Nov 07 '21 11:11 SDSTony

안녕하세요. 좋은 글 잘 봤습니다. 혹시 예측된 이미지를 위의 예시처럼 1장이 아닌, 순차적으로 모두 plot하려면 어떠한 방법을 사용하면 될까요?

HeejaeLeeCAU avatar Dec 22 '21 08:12 HeejaeLeeCAU

안녕하세요 글 너무 잘봤습니다. 다른건 다 잘되는데 plot_image_from_output(imgs[_idx], pred[_idx]) 부분에서 계속
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first. 오류가 납니다. 어떻게 하면 해결 할 수 있을까요?..ㅠ

jinbilly avatar Jun 13 '22 12:06 jinbilly

@jinbilly 5.3 데이터셋 클래스 정의 부분의 plot_image_from_output() 함수를 아래와 같이 수정하면 됩니다.

# 코드 생략
for idx in range(len(annotation["boxes"])):
    xmin, ymin, xmax, ymax = annotation["boxes"][idx].cpu()

gpu에 할당된 텐서를 cpu로 바꾸지 않아 발생하는 에러라고 합니다. [ref]

처음에는 prediction을 출력할때만 에러가 나는게 이상했지만, ground truth를 plot할 때와 달리 prediction값은 gpu연산을 거치기 때문에 에러가 발생하는 것 같습니다.

HanNayeoniee avatar Sep 13 '22 06:09 HanNayeoniee

@jinbilly

Added codes to solve plotting error #105

이미 다른 분이 올린 이슈가 있네요!

HanNayeoniee avatar Sep 13 '22 07:09 HanNayeoniee

안녕하세요 혹시 test set에 대하여 model의 accuracy를 계산하려면 어떻게 코드를 구현할 수 있는지 조언해주실 수 있는 분 계신다면 조언 부탁드립니다.

HelloSarahWorld avatar Apr 01 '23 13:04 HelloSarahWorld

↑ 제 경우에는 다음과 같이 구현했는데 혹시 잘못된 부분이 있는지 알고 싶습니다! 늘 좋은글 감사합니다!

with torch.no_grad(): len_ = 0 same = 0 for imgs, annotations in tqdm(test_data_loader):

    imgs = list(img.to(device) for img in imgs)
    preds = make_prediction(model, imgs, 0.5)
    
    annot_label = [annot['labels'] for annot in annotations]
    preds_label = [pred['labels'] for pred in preds]

    len_ += len(annot_label)

    for i, j in zip(annot_label, preds_label):
        if len(i) == len(j):
            if i == j.cpu():
                same += 1

print('accuracy: '+str(same/len_))

HelloSarahWorld avatar Apr 01 '23 14:04 HelloSarahWorld

↑ 앗, AP 이해했습니다. 위에 댓글들 삭제하셔도 괜찮습니다!

HelloSarahWorld avatar Apr 05 '23 12:04 HelloSarahWorld

혹시 loss값만 추출하셨는데 정확도는 어떻게 산출하나요? 또한validation을 했을 때 가장 높은 정확도를 save하는 방법은 무엇인가요?

yubbel avatar Jul 03 '23 04:07 yubbel