torch序列化 pickle 慢
100张图片 反序列化需要1s,300张需要3s
#coding=utf-8
import time
import numpy as np
import redis
import cv2 as cv
import pickle
import torch
pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
r = redis.StrictRedis(connection_pool=pool)
x = torch.rand(1, 3, 352, 352)
for i in range(3):
r.set(i,pickle.dumps(x))
start = time.time()
for i in range(100):
b = r.get(1)
b=pickle.loads(b)
# print(b.type)
print('time',time.time()-start)
#
# for i in range(100):
# data = np.arange(1000 * 4000, dtype='float').reshape(1000, 4000)
# t1=time.time()
# r.set(b'list'+str(i),data)
# print('存入时间',time.time()-t1)
#
# for i in range(100):
# t2=time.time()
# list2=r.get
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/85224465
- 点赞
- 收藏
- 关注作者
评论(0)