Open kaimonhtun opened 3 years ago
Could you provide more information?
If you mean testing with no metric evaluation, you can just test on every single frame like in https://github.com/duanzhiihao/RAPiD/blob/e56ac87b0422d98f2942dbfbc64b745a3a3149ae/api.py#L51
If you mean testing with metric evaluation, I guess you need to write your own script to do this.
For example,
from api import Detector
import numpy as np
import cv2
from PIL import Image
def cv2pil(imgCV):
imgCV_RGB = cv2.cvtColor(imgCV, cv2.COLOR_BGR2RGB)
imgPIL = Image.fromarray(imgCV_RGB)
return imgPIL
detector = Detector(model_name='rapid',
weights_path='./weights/pL1_MWHB1024_Mar11_4000.ckpt')
cap = cv2.VideoCapture('videos/test.mp4')
while(cap.isOpened()):
# フレームを取得
ret, frame = cap.read()
if ret == False:
break
np_img = detector.detect_one(pil_img=cv2pil(frame),
input_size=1024, conf_thres=0.3,
return_img=True)
new_image = np.array(np_img, dtype=np.uint8)
np_img = cv2.cvtColor(new_image, cv2.COLOR_RGB2BGR)
# フレームを表示
cv2.imshow("Frame", np_img)
# qキーが押されたら途中終了
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
However, this code has duplicate value error in "pil_img" on api.py. So you can modify the code below,
api.py #L73 https://github.com/duanzhiihao/RAPiD/blob/fcb764a308e7e7c8ad7aceeb5de58364a691d9cd/api.py#L72
to
detections = self._predict_pil(**kwargs)
and L116 https://github.com/duanzhiihao/RAPiD/blob/fcb764a308e7e7c8ad7aceeb5de58364a691d9cd/api.py#L116-L130
to
def _predict_pil(self, **kwargs):
'''
Args:
pil_img: PIL.Image.Image
input_size: int, input resolution
conf_thres: float, confidence threshold
'''
input_size = kwargs.get('input_size', self.input_size)
conf_thres = kwargs.get('conf_thres', self.conf_thres)
assert isinstance(kwargs.get('pil_img', None), Image.Image), 'input must be a PIL.Image'
assert input_size is not None, 'Please specify the input resolution'
assert conf_thres is not None, 'Please specify the confidence threshold'
# pad to square
input_img, _, pad_info = utils.rect_to_square(kwargs.get('pil_img', None), None, input_size, 0)
It works for me.
How to test detection for video file?