.npz 存储
注意,outpath 是一个文件的路径。
imsize,keypoints 等是上文已经生成的变量。
用 np.savez 函数将这些变量一起存储在 outpath 文件里。
np.savez(open(outpath,'wb'),
imsize = (W,H),
keypoints = xys[idxs],
descriptors = desc[idxs],
scores = scores[idxs])
.npz 读取
注意,filepath 对应的 file 不一定要是以 .npz 为后缀的
npzfile = np.load(open(filepath,'rb'))
npzfile.files # 相当于获取 keys
npzfile[key1] # 相当于 dict 访问 key 对应的 value
npzfile [key2]
也可以这样使用 open
with open(filepath, 'rb') as f:
data = np.load(f)
print(data.files)
.npy 读取
运行
data = np.load('r2d2_WAF_N16.scale-0.3-1.npy')
报错
ValueError: Object arrays cannot be loaded when allow_pickle=False
解决方法, 加上 allow_pickle=True
data = np.load('r2d2_WAF_N16.scale-0.3-1.npy', allow_pickle=True)
.npz 与 .npy 的比较
torch load cuda mapping
ptPath = Path("./r2d2_WAF_N16.pt")
pt = torch.load(ptPath,map_location='cuda:0')