项目场景:
用tensoboard 在jupyter notebook 中可视化train/loss
问题描述
如果跑过一次示例, 再跑第二次tensorboard就会坚持端口“6006”被使用了, 但是其实并没有, 就算杀死了已经在进行的process,还是会报这个错, 以及展示白板。
Reusing TensorBoard on port 6006 (pid 15092), started 0:14:16 ago. (Use '!kill 15092' to kill it.)
!!!but no process is using port “6006”
原因分析:
tensorboard 的官方团队回应说这是一个bug,因为tensorboard 没有动态清除.tensorboard-info
的习惯(缓存), 所以除非认为手动清除.tensorboard- info
, tensorboard 会一直以为你在使用那个之前使用的端口。
解决方案:
- crude solution:
change the port that tensorboard is bind to every time after you run. - the hard way:
find the darn tensorbard-info file and remove it
从官方文档中可以看见, .tensorboard-info
存在python 指定的放temp file 的地方
我们将用python 递归删除.tensorboard-info
找到.tensorboard-info
的path
tb_info_dir = os.path.join(tempfile.gettempdir(), '.tensorboard-info')
递归删除.tensorbard-info
import shutil
tb_info_dir = os.path.join(tempfile.gettempdir(), '.tensorboard-info')
shutil.rmtree(tb_info_dir)
已经验证可以实现tensorboard临时文件删除,解决反复执行端口占用的问题