Пример #1
0
def detect(img_path):
    #------------------preprocessing------------------------
    ori_imgs, framed_imgs, framed_metas = preprocess(
        img_path, max_size=input_size)  #input_size: 512

    x = torch.stack([torch.from_numpy(fi).cuda() for fi in framed_imgs], 0)

    x = x.to(torch.float32 if not use_float16 else torch.float16).permute(
        0, 3, 1, 2)

    with torch.no_grad():
        start = timeutil.get_epochtime_ms()
        t1 = time.time()

        features, regression, classification, anchors = model(x)

        regressBoxes = BBoxTransform()
        clipBoxes = ClipBoxes()

        out = postprocess(x, anchors, regression, classification, regressBoxes,
                          clipBoxes, threshold, iou_threshold)
    out = invert_affine(framed_metas, out)
    c1, c2 = display(out, ori_imgs, imshow=True, imwrite=False)
    t2 = time.time()
    tact_time = (t2 - t1) / 10
    print(f'{tact_time} seconds, {1 / tact_time} FPS, @batch_size 1')
    print('milisecond is ' + str(t2 - t1))
    print("Latency: %fms" % (timeutil.get_epochtime_ms() - start))

    return c1, c2
Пример #2
0
                            "color": color,
                            "pad": 0
                        },
                    )

            plt.axis("off")
            plt.gca().xaxis.set_major_locator(NullLocator())
            plt.gca().yaxis.set_major_locator(NullLocator())
            filename = path.split("/")[-1].split(".")[0]
            plt.savefig(f"output/{filename}.jpg",
                        bbox_inches="tight",
                        pad_inches=0.0)
            plt.close()

        return result_x1, result_y1, result_x2, result_y2, result_box_h


detection = top_detect(weigth_PATH='./weights/yolov3_ckpt_99.pth'
                       )  # change your image path and weight path

start = timeutil.get_epochtime_ms()
x1, y1, x2, y2, box_h = detection.detect(IMG_PATH='sample3.jpg', )  # output

# img = cv2.imread('./sample2.jpg')
# img = cv2.rectangle(img, (int(x1[0]), int(y1[0]+box_h[0])), (int(x2[0]), int(y1[0])), (0,0,255), 2)
# cv2.imshow('result', img)
# cv2.waitKey(0)

print("{} {} {} {}".format(x1[0], y1[0] + box_h[0], x2[0], y1[0]))
print("Latency: %fms" % (timeutil.get_epochtime_ms() - start))
Пример #3
0
from top_detect import top_detect

import timeutil

detection = top_detect(weigth_PATH='./weights/yolov3_ckpt_99.pth'
                       )  # change your image path and weight path

total_time = 0.0

for i in range(1000):
    start = timeutil.get_epochtime_ms()
    x1, x2, y1, y2, box_h = detection.detect(IMG_PATH='sample/resize_2.jpg',
                                             conf_thres=0.5,
                                             nms_thres=0.5)  # output
    total_time += timeutil.get_epochtime_ms() - start
    # print("Latency: %fms" % (timeutil.get_epochtime_ms() - start))

print('avg time is ' + str(total_time / 1000))