refactor: restructure project according to open-source code standards Reorganize code into standard directory structure (src/, configs/, scripts/, data/) Split monolithic gcn.py into modular components (config, dataset, model, train, eval) Add configuration management with YAML support and CLI argument parsing Implement reproducibility features (seed management, config/command logging) Add .gitignore to exclude outputs, weights, and data artifacts Remove data/cora.pkl from git tracking (keep only README in data/) Rewrite README.md with complete documentation per spec (env setup, data prep, training, eval, results) Add requirements.txt for dependency management Add shell scripts for training and evaluation Improve code documentation with docstrings and comments Add proper error messages for missing files/paths
refactor: restructure project according to open-source code standards
赛道一热身赛:基于图卷积网络(GCN)的 Cora 半监督节点分类
本仓库实现了一个两层 GCN 模型,在 Cora 引用网络数据集上完成半监督节点分类任务。代码基于 Jittor 与 JittorGeometric。
. ├── configs/ # 训练/评测配置文件(YAML) │ └── default.yaml ├── src/ # 核心源码(模型 / 数据 / 训练 / 评测) │ ├── config.py │ ├── dataset.py │ ├── model.py │ ├── train.py │ ├── eval.py │ └── main.py # 入口脚本 ├── scripts/ # 运行脚本 │ ├── train.sh │ └── eval.sh ├── data/ # 数据说明(原始数据文件不提交) │ └── README.md ├── outputs/ # 日志、权重、预测结果(默认 git 忽略) ├── requirements.txt ├── .gitignore └── LICENSE
安装步骤:
# 1) 安装 Jittor(参考官方文档:https://github.com/Jittor/jittor) pip install jittor # 2) 安装 JittorGeometric 及其依赖 # 详见:https://github.com/AlgRUC/JittorGeometric?tab=readme-ov-file#installation pip install jittor-geometric # 3) 安装其他 Python 依赖 pip install -r requirements.txt
数据集文件 cora.pkl(pickle 格式,约 15 MB)需要手动放入 data/ 目录:
cora.pkl
data/
data/ cora.pkl # <-- 将文件放在这里
cora.pkl 包含以下字段:
x
numpy.ndarray (2708, 1433)
y
numpy.ndarray (2708,)
-1
edge_index
numpy.ndarray (2, E)
train_mask
numpy.ndarray (2708,) bool
val_mask
test_mask
num_classes
int
num_features
数据根目录通过 --data-path 参数配置(默认 data/cora.pkl)。
--data-path
data/cora.pkl
使用默认配置直接训练:
bash scripts/train.sh
或直接用 Python 并自定义参数:
python -m src.main \ --config configs/default.yaml \ --data-path data/cora.pkl \ --hidden-dim 256 \ --dropout 0.8 \ --epochs 200 \ --lr 0.01 \ --weight-decay 5e-4 \ --seed 42
训练结束后,产物保存在 outputs/:
outputs/
best_ckpt.pkl
config.yaml
command.txt
train.log
使用训练好的 checkpoint 生成测试集预测结果:
bash scripts/eval.sh --ckpt outputs/best_ckpt.pkl
或:
python -m src.main --ckpt outputs/best_ckpt.pkl
预测结果保存为 outputs/result.json,格式为 {节点编号: 预测类别}。
outputs/result.json
{节点编号: 预测类别}
argmax(logits)
--seed
42
jt.misc.set_global_seed()
outputs/config.yaml
outputs/command.txt
outputs/train.log
configs/default.yaml
GCNConv
lr=0.01
weight_decay=5e-4
planspace.org
本项目基于 MIT License 开源。
第六届计图人工智能挑战赛热身赛赛道一代码实现
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802047560号
GCN Node Classification on Cora (Jittor)
本仓库实现了一个两层 GCN 模型,在 Cora 引用网络数据集上完成半监督节点分类任务。代码基于 Jittor 与 JittorGeometric。
目录结构
1. 环境安装
安装步骤:
2. 数据准备
数据集文件
cora.pkl(pickle 格式,约 15 MB)需要手动放入data/目录:cora.pkl包含以下字段:xnumpy.ndarray (2708, 1433)ynumpy.ndarray (2708,)-1)edge_indexnumpy.ndarray (2, E)train_masknumpy.ndarray (2708,) boolval_masknumpy.ndarray (2708,) booltest_masknumpy.ndarray (2708,) boolnum_classesintnum_featuresint数据根目录通过
--data-path参数配置(默认data/cora.pkl)。3. 训练
使用默认配置直接训练:
或直接用 Python 并自定义参数:
训练结束后,产物保存在
outputs/:best_ckpt.pkl— 最佳验证准确率对应的模型权重config.yaml— 本次运行实际使用的完整配置command.txt— 启动命令train.log— 训练日志4. 评测 / 推理
使用训练好的 checkpoint 生成测试集预测结果:
或:
预测结果保存为
outputs/result.json,格式为{节点编号: 预测类别}。5. 结果说明
argmax(logits)得到预测类别,与真实标签逐元素比较。test_mask,与比赛线上提交可能存在微小差异,原因在于随机种子、硬件精度以及数据版本。如需完全复现线上结果,请以官方提交系统的输出为准。6. 可复现性
--seed统一设置(默认42),并在代码中调用jt.misc.set_global_seed()。outputs/config.yamloutputs/command.txtoutputs/train.logconfigs/default.yaml)。7. 模型架构
GCNConv)lr=0.01,weight_decay=5e-4)8. 第三方引用与声明
planspace.org整理)License
本项目基于 MIT License 开源。