查看DVC/DCVC的ME网络 (都是用的SpyNet网络)
找到DVC里面的flow文件,分析一下里面的函数的作用

所以怎么实现呢
将estmv保存为.flo的光流文件


在我的文件夹
from torchvision import transforms
import matplotlib.pyplot as plt
def writeFlow(self,filename, uv, v=None):#注意输入格式应当是array/(h,w,c)
TAG_CHAR = np.array([202021.25], np.float32)
nBands = 2
if v is None:
assert (uv.ndim == 3)
assert (uv.shape[2] == 2)
u = uv[:, :, 0]
v = uv[:, :, 1]
else:
u = uv
assert (u.shape == v.shape)
height, width = u.shape
f = open(filename, 'wb')
# write the header
f.write(TAG_CHAR)
np.array(width).astype(np.int32).tofile(f)
np.array(height).astype(np.int32).tofile(f)
# arrange into matrix form
tmp = np.zeros((height, width * nBands))
tmp[:, np.arange(width) * 2] = u
tmp[:, np.arange(width) * 2 + 1] = v
tmp.astype(np.float32).tofile(f)
f.close()
def imShow(self , input,i):
tensor = transforms.ToPILImage()(input)
tensor.save(("./src/flow_from_DVC/img{}.png".format(i)))
(69条消息) 光流.flo文件处理_光流文件存储形式_nulixuexidexiaojie的博客-优快云博客
读取.flo光流文件,并可视化出来(代码在本地的PyCharm中;有两版:一个来自DVC/一个来自网上)
错误总结
首先是要注意保存时,flow的输入格式,要【去梯度/,cpu()/换成numpy格式】,并且应当是(h,w,c)的格式,所以需要自己换一下轴的顺序
一开始,输出的光流图很不好,原因:用了没有训练好的网络
结论发现:和官方给的flow的图不同,我们的训练和测试集有背景的偏移