Boundary Sensitive Network (BSN) 源码运行
BSN论文:https://arxiv.org/abs/1806.02964
BSN源码:https://github.com/wzmsltw/BSN-boundary-sensitive-network.pytorch
步骤:
(参考自 BSN 项目内 README.md
)
1. 下载源码
$ git clone https://github.com/wzmsltw/BSN-boundary-sensitive-network.pytorch.git
2. 下载Dataset
在复现时,直接应用了作者使用TSN提取后的视频特征,特征文件可以从作者提供的百度云链接下载。然后将特征文件放在 ./data/activitynet_feature_cuhk/
目录下。
如果使用百度云下载,按照作者提供的方法 cat zip_csv_mean_100.z* > csv_mean_100.zip
在Ubuntu系统下解压 csv_mean_100.zip
只能得到 3992 条数据。如果下载好全部的 6 个分卷压缩文件后,在Windows系统下直接解压 zip_csv_mean_100.zip
文件可以得到完整的 19228 条数据。
3. 配置环境
作者源码的运行环境为: Python 2
PyTorch 0.4.1
tensorboardX
配置环境的教程可以参考:
也可以在现有的 Python 3
PyTorch 1.x
环境中运行 ,需要对代码做一些修改。
- 遍历字典 keys() 前先转为list
TypeError: ‘dict_keys’ object does not support indexing
self.video_list = list(self.video_dict.keys())
lr_scheduler.step()
在optimizer.step()
之后使用
UserWarning: Detected call of
lr_scheduler.step()
beforeoptimizer.step()
. In PyTorch 1.1.0 and later, you should call them in the opposite order:optimizer.step()
beforelr_scheduler.step()
. Failure to do this will result in PyTorch skipping the first value of the learning rate schedule. See more details at https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate
for epoch in range(opt["tem_epoch"]):
train_TEM(train_loader, model, optimizer, epoch, writer, opt)
test_TEM(test_loader, model, epoch, writer, opt)
scheduler.step()
- index 转为整数
TypeError: slice indices must be integers or None or have an index method
num_videos_per_thread = num_videos // opt["pgm_thread"]
video_extend = video_scale // 4 + 10
4. 训练
$ sh bsn.sh # 开始训练
# bsn.sh内容:
python main.py --module TEM --mode train
python main.py --module TEM --mode inference
python main.py --module PGM
python main.py --module PEM --mode train
python main.py --module PEM --mode inference --pem_batch_size 1
python main.py --module Post_processing
python main.py --module Evaluation
$ tensorboard --dir=./runs # 查看训练过程
在执行训练脚本时出现 ImportError
:
ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.22’ not found
解决方法可以参考 https://blog.csdn.net/jsk_learner/article/details/102468919