nvjpeg-python icon indicating copy to clipboard operation
nvjpeg-python copied to clipboard

为什么测试解码提升很小?而且与官方demo 使用的api不一样

Open hacktmz opened this issue 3 years ago • 2 comments

环境 20核cpu cuda 10.2 T4 单卡

def get_image(image_url): if not image_url: return None try: image_url = parse.unquote(image_url) response = requests.get(image_url) if response.status_code != 200: print("get image filed!!!!!!") return " " return response.content except Exception as e: print(e) raise

def test_load_img(image, count): start = cv2.getTickCount() for num in range(0, count): np_image = np.frombuffer(bytearray(image), np.uint8) cv_image = cv2.imdecode(np_image, cv2.IMREAD_COLOR) end1 = cv2.getTickCount() print("load img1 base line = %s" % ((end1 - start) / cv2.getTickFrequency())) return cv_image

def test_load_img_nvjpeg(image, count): from nvjpeg import NvJpeg nj = NvJpeg() start = cv2.getTickCount() for num in range(0, count): np_image = np.asarray(bytearray(image), dtype="uint8") # cv_image = cv2.imdecode(np_image, cv2.IMREAD_COLOR) cv_image = nj.decode(np_image) end1 = cv2.getTickCount() print("load img nvjpeg base line = %s" % ((end1 - start) / cv2.getTickFrequency())) return cv_image

if name == "main": image = get_image("http://cdn.weipaitang.com/img/20200313rli2rh7p-jdgj-7vyi-91qd-584099256046-W3024H4032") if image != "": count = 100 test_load_img_nvjpeg(image, count) cv_image = test_load_img(image, count)

结果为: opencv 14秒 pynvjpeg 12.6秒 (确定观察到GPU的使用率,没有任何报错)

hacktmz avatar Jun 08 '21 06:06 hacktmz