biubug6 / Pytorch_Retinaface

Retinaface get 80.99% in widerface hard val using mobilenet0.25.
MIT License
2.63k stars 774 forks source link

您好,请问我在运行detect.py时设置不同尺度输入进行测试,为什么net forword time没有变化 #23

Closed yjhuasheng closed 4 years ago

yjhuasheng commented 5 years ago

for i in range(100): image_path = "./curve/3.jpg" img_raw = cv2.imread(image_path, cv2.IMREAD_COLOR) img = np.float32(img_raw) count=0

    # img=cv2.resize(img,(1280,1920))
    target_size = 1080
    max_size = 1920
    im_shape=img.shape
    im_size_min=np.min(im_shape[0:2])
    im_size_max=np.max(im_shape[0:2])
    resize = float(target_size) / float(im_size_min)
    if np.round(resize * im_size_max) > max_size:
        resize = float(max_size)/float(im_size_max)
    if args.origin_size:
        resize = 1

    if resize!=1:
        img=cv2.resize(img, None, None, fx=resize, fy=resize, interpolation=cv2.INTER_LINEAR)

    im_height, im_width, _ = img.shape
    scale = torch.Tensor([img.shape[1], img.shape[0], img.shape[1], img.shape[0]])
    img -= (104, 117, 123)
    img = img.transpose(2, 0, 1)
    img = torch.from_numpy(img).unsqueeze(0)
    img = img.to(device)
    scale = scale.to(device)

    tic = time.time()
    loc, conf, landms = net(img)  # forward pass
    toc=time.time()
    print('net forward time: {:.4f}'.format(toc - tic))
biubug6 commented 5 years ago

一般是由于网络比较小, 一定尺度范围内的图像,一次前向过程中,GPU的核心计算单元并没有被用完导致时间消耗没有增加

yjhuasheng commented 5 years ago

我分别测的320x240,480x640,720x1280,1280x1920尺度的前向过程的时间,我是直接resiez的,可是时间还是很相近都是8ms,这是什么原因呢?

biubug6 commented 5 years ago

建议你打印出送入网络之前的shape, 我在GTX1070上测试, 时间与送入网络的尺度成正相关.

yjhuasheng commented 5 years ago

好的,我打印看看

yjhuasheng commented 5 years ago

我打印出来了,还是这样的结果,测试的时候是单张图像循环测试100次,然后计算平均的前向时间,不同尺度的平均时间还是很相近, torch.Size([1, 3, 1280, 720]) net forward time: 0.0141 torch.Size([1, 3, 1280, 720]) net forward time: 0.0149 ave_time: 0.02009380340576172

torch.Size([1, 3, 640, 480]) net forward time: 0.0130 torch.Size([1, 3, 640, 480]) net forward time: 0.0125 ave_time: 0.019301908016204836

torch.Size([1, 3, 1920, 1080]) net forward time: 0.0140 torch.Size([1, 3, 1920, 1080]) net forward time: 0.0132 ave_time: 0.02022948145866394

Govan111 commented 4 years ago

请问找到原因了吗?为什么不同尺度的平均时间还是很相近,我用256*256尺寸的图片也需要14ms