训练日志
在训练过程中,需要实时监控模型训练效果,可以使用Tensorboard实时监控训练效果;如果使用ssh连接服务进行模型训练时,训练时间过长,可以设置在后台训练模型,这样退出终端也能继续训练
一、使用Tensorboard实时监控训练情况
1. 启动Tensorboard
# 注:results是存放训练文件的目标文件夹
tensorboard --logdir=./results
2.打开终端中的6006端口的地址

二、后台训练
有时候使用服务器时训练模型依旧消耗很多时间,并且终端随时有关闭的风险,我们可以设法让脚本在后台运行,即使退出终端也不影响任务继续
训练模型
# 模型训练
python main.py --mode train --data_dir data/processed_data/CollegeMsg_snapshots_lables --batch_size 4 --temporal_window 4
使用训练好的模型进行实验
1. 终端中测试
# 正常终端中的实验指令
python main.py --mode influence_max --k 5 --data_dir data/processed_data/CollegeMsg_snapshots_lables --model_path results/data=CollegeMsg_snapshots_lables_tw=4_bs=4_gh=64_gl=2_lh=128_ll=2_ep=300_20250812_145339/best_model.pth --temporal_window 4
2. 后台测试(!!!!)
既然是一次性在后台运行,最简单可靠的方法是用 nohup + &(配合 -u 关闭 Python 缓冲),并把输出重定向到日志文件。
# 下面是后台测试指令
nohup python -u main.py --mode influence_max --k 5 --data_dir /root/data1/MyProject/DynamicGraphInfluenceMaximization-AAAI2025-main/data/processed_data/CollegeMsg_snapshots_lables --model_path /root/data1/MyProject/DynamicGraphInfluenceMaximization-AAAI2025-main/results/data=CollegeMsg_snapshots_lables_tw=4_bs=4_gh=64_gl=2_lh=128_ll=2_ep=300_20250812_145339/best_model.pth --temporal_window 4 > run.log 2>&1 & echo $!
2.1 查看进程的运行情况
ps aux | grep main.py

2.2 查看日志
tail -f run.log


2.3 停止进程
#(用 echo $! 得到的 PID 或从 ps 找到的 PID)
kill PID
2.4 若不退出再强制
kill -9 PID
2.5 查看cpu运行情况
top

2512

被折叠的 条评论
为什么被折叠?



