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('list'+str(i))
# list(list2.decode())
# print('取出時間',time.time()-t2,len(list2))
# img=cv.imread('ren.png')
# t1=time.time()
# r.hset('img',img)
# print('存入時間',time.time()-t1)
# t1=time.time()
# data = np.arange(1000 * 4000, dtype='float').reshape(1000, 4000)
# t1=time.time()
# data=pickle.dumps(data)
# r.set('list',data)
# print('存入時間',time.time()-t1)
#
# t2=time.time()
# list2=r.get('list')
# print(pickle.loads(list2))
# print('取出時間',time.time()-t2)