ci: Add swanlab initialization and training logging
Browse files- Added requirements.txt file to list project dependencies
- Added train.py file to implement basic training logging functionality
- requirements.txt +3 -0
- train.py +29 -0
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# onnx==1.17.0
|
| 2 |
+
torch==2.7.0
|
| 3 |
+
swanlab==0.5.7
|
train.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import swanlab
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
# 初始化一个新的swanlab run类来跟踪这个脚本
|
| 5 |
+
swanlab.init(
|
| 6 |
+
# 设置将记录此次运行的项目信息
|
| 7 |
+
project="MODNet",
|
| 8 |
+
workspace="wudi",
|
| 9 |
+
# 跟踪超参数和运行元数据
|
| 10 |
+
config={
|
| 11 |
+
"learning_rate": 0.02,
|
| 12 |
+
"architecture": "CNN",
|
| 13 |
+
"dataset": "CIFAR-100",
|
| 14 |
+
"epochs": 10
|
| 15 |
+
}
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
# 模拟训练
|
| 19 |
+
epochs = 10
|
| 20 |
+
offset = random.random() / 5
|
| 21 |
+
for epoch in range(2, epochs):
|
| 22 |
+
acc = 1 - 2 ** -epoch - random.random() / epoch - offset
|
| 23 |
+
loss = 2 ** -epoch + random.random() / epoch + offset
|
| 24 |
+
|
| 25 |
+
# 向swanlab上传训练指标
|
| 26 |
+
swanlab.log({"acc": acc, "loss": loss})
|
| 27 |
+
|
| 28 |
+
# [可选] 完成训练,这在notebook环境中是必要的
|
| 29 |
+
swanlab.finish()
|