基于文章Play and Rewind: Optimizing Binary Representations of Videos by Self-Supervised Temporal Hashing的理解以及作者提供的源码,说明一些复现过程中需要注意的问题。
原作者源码地址@github
我们的实现@gitee
An unsupervised hashing model that generates binary codes (+1,-1) for a video sequence. This is just a quick demo for running the training and test. The source code is simple and well commented. Future details about feature extraction and visualization will be added ASAP.
可以为视频序列生成二进制码(+1,-1)的无监督哈希模型。这是运行训练和测试的快速例程,源码很简单。关于特征提取、可视化的更多细节会尽快补上。
Only [Theano] (http://deeplearning.net/software/theano/) is required. In fact, some of the core layers exploit a high-level wrapper [Keras] (https://keras.io/), but the code is not dependent on Keras installation. You may need to install h5py for data loader.
仅需要Theano。事实上一些核心层使用了高级的keras封装,但是代码并不依赖Keras的安装。需要安装h5py模块用于数据加载。
run Blstm.py
conda create -n py27 python=2.7 # 创建虚拟空间名为py27
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy==1.16.2,scipy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple theano
conda install mkl-service # 可能不需要
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple h5py
训练过程直接跑就行,测试时把Blstm.py的最后一句True改为False即可。
这里参考的是无法加载downsample模型的问题
解释的话应该是theano框架更新了downsample的用法。
./data/theano_backend.py line4改成:from theano.tensor.signal.pool import pool_2d
./data/theano_backend.py line638改成:pool_out = pool.pool_2d(x, ws=pool_size, st=strides,
./data/theano_backend.py line643改成:pool_out = pool.pool_2d(x, ws=pool_size, st=strides,
这里应该是作者忘了改一下代码里的数据名。
./Blstm.py line40&42的单引号中的文件名分别改为:fcv_train_demo.h5和fcv_test_demo.h5
测试时出现的问题,因为原来的目录下没有./results文件夹,所以直接新建一个即可,另外如果依旧报错,将 'results/hidden_1.mat’改为 ‘results\hidden_1.mat’,不一定会有这个问题,有些情况下python把 / 当做转义符了。
作者把训练与测试的代码卸载一起了,因此执行训练和测试时代码需要微调,仅是一些flag的改变而已。
测试时:./Blstm.py的97行改为run_blstm(is_train=False,reload_model=True);./model.py的128行注释掉。
——————————————————分割线———————————————————————
2019年5月15日补充,源码中没有训练可视化,损失函数的值看不出来变化,加了点程序把损失函数的曲线画出来。
pip install xlwt # 安装excel写入库
import xlwt # Blstm.py和model.py的开头都加上这一句
Blstm.py中,在main之前加上几句
ex=xlwt.Workbook(encoding='utf-8')
sheet = ex.add_sheet('MySheet1')
ex.save('666.xlsx')
具体位置看下图
model.py中,train函数中的try部分,加上
sheet.write(uidx/10,1,train_loss)
具体位置看下图
这样训练完之后,就可以把我们的损失函数数据保存在666.xlsx中,可以进行后续处理了。
import xlrd
import matplotlib.pyplot as plt
wb=xlrd.open_workbook('666.xlsx') # 记得换成自己的路径
x=[]
y=[]
x1=[]
y1=[]
for s in wb.sheets():
for row in range(s.nrows):
values = []
for col in range(s.ncols):
values.append(s.cell(row,col).value)
x.append(values[0])
y.append(values[1])
'''
for i in range(1800,2001):
x1.append(x[i])
y1.append(y[i])
'''
plt.plot(x,y)
plt.title('loss function')
plt.xlabel('epoch')
plt.ylabel('loss')
plt.show()
上面的是所有数据的曲线,后面的变化几乎看不出来了,可以把18000到20000的曲线再画一下,把上面程序注释的部分展开,再把下面的plt.plot(x,y)该为plt.plot(x1,y1)即可。
18号要拿这个做课程汇报了,加油!!!