• 카테고리

    질문 & 답변
  • 세부 분야

    컴퓨터 비전

  • 해결 여부

    미해결

<mmdetection 관련>

22.01.11 15:50 작성 조회수 214

0

안녕하세요 선생님 

강의 잘 듣고 대학원 연구생활에 있어서 많이 도움받고있습니다.

 

다름이 아니라 수업을 듣던 중 다음과 같은 질문사항이 생겨 질문드립니다.

1. 제가 하려고 하는것은 mmdetection - maskrcnn inference code를 이용하여 inference를 진행한 뒤 

추론 결과를 디렉토리에 저장하려고 합니다.  아래 코드와 같이 원본이미지에 추론결과를 덧씌운 결과는 저장에 성공했지만 

from mmdet.apis import init_detector, inference_detector, show_result_pyplot
import mmcv
import torch
import cv2
import matplotlib.pyplot as plt

#버전 및 gpu 작동확인
print(f"Setup complete. Using torch {torch.__version__} ({torch.cuda.get_device_properties(0).name if torch.cuda.is_available() else 'CPU'})")


# config 파일을 설정하고, 미리 학습한 maskrcnn 모델을 checkpoint로 설정.
config_file = 'custom_config.py'
checkpoint_file = '/Scratch/home/dohyeon/mmdetection/tutorial_exps/epoch_12.pth'

# config 파일과 pretrained 모델을 기반으로 Detector 모델을 생성.
model = init_detector(config_file, checkpoint_file, device='cuda:0')


#디렉토리 내 모든 파일 segmentation 실행 및 저장  
path_dir = '/Scratch/home/dohyeon/mmdetection/input/pre-processing/save_point2'
file_list = os.listdir(path_dir)

for i in range(6):
    img_name = path_dir + '/' + file_list[i]
    img_arr= cv2.imread(img_name, cv2.IMREAD_COLOR)
    img_arr_rgb = cv2.cvtColor(img_arr, cv2.COLOR_BGR2RGB)
    # cv2.imshow('img',img)
    fig= plt.figure(figsize=(12, 12))
    plt.imshow(img_arr_rgb)

    # inference_detector의 인자로 string(file경로), ndarray가 단일 또는 list형태로 입력 될 수 있음.
    results = inference_detector(model, img_arr)

    # inference 된 결과를 원본 이미지에 적용하여 새로운 image로 생성(bbox 처리된 image)
    # Default로 score threshold가 0.3 이상인 Object들만 시각화 적용. show_result_pyplot은 model.show_result()를 호출.
    show_result_pyplot(model, img_arr, results)

    #추론결과 디렉토리에 저장
    model.show_result(img_arr, results, out_file= f'input/pre-processing/save_point3/{file_list[i]}')

제가 원하는 방법은 원본이미지에 추론결과를 덧씌운 show_result_pyplot 과 같은 이미지가 아니라 

원본에 덧씌우지 않은 추론결과만을 저장하고 싶습니다. 

혹시 좋은 방법이 있을까요?

 

2. 추론 결과가 mask 형태의 이미지처럼 나오나요? 

아니면 배열과 같이 나오나요?

 

3. 만약 추론결과가 mask형태의 이미지처럼 나온다면 

위 그림과 같이 배경 픽셀은 0이고 사람의 픽셀만 0~255 사이의 값으로 나오나요? 

 

이상입니다

 

감사합니다  

답변 1

답변을 작성해보세요.

0

안녕하십니까, 

질문하신 내용은 Mask RCNN - 실습 01 섹션에서

MMDetection을 이용한 Mask RCNN Inference 실습 - Masking inference 반환 결과 분석 영상을 참조하시면 될 것 같습니다. 

추론 결과 반환은 Masking 형태로 반환하며 이미지 pixel별로 True/False 값으로 되어 있습니다. 여기에 이미지색상을 입히시는 것 역시 실습 코드로 있으니까 참조하시면 될 것 같습니다. 

감사합니다.