项目首页Project home
为新物体训练Train new objects
本页目录On this page

为每个物体训练 HccePose(BF)

本页使用公开上游源码中的准备、训练或评测脚本。请先按安装说明获取该版本,并在上游源码根目录执行本页命令;当前项目中的 examples/inference/ 用于应用推理。

HccePose(BF) 为每个物体单独训练一套权重。s4_p2_train_bf_pbr.py 可以依次训练多个物体,每个物体的训练可以使用一张或多张 GPU。

配置训练脚本

先准备物体模型与元数据、PBR 场景和正背面坐标标签。打开训练脚本,在 __main__ 中将 dataset_path 换成自己的数据集路径,并设置物体 ID 范围。

参数 示例设置 用途
start_obj_id、end_obj_id 1、5 依次训练物体 1 至 5。只训练一个物体时,两者填同一 ID。
total_iteration 50001 每个物体的训练迭代设置。
batch_size、lr 24、0.0002 每张 GPU 的批量大小及学习率。
efficientnet_key None 训练脚本的骨干网络设置。

DDP 训练处理的样本总数按下式计算:

TEXT
total samples = total iteration × batch size × GPU number

单卡调试或多卡训练

默认 ide_debug=True,适合在一张 GPU 上运行或调试:

TEXT
nohup python -u s4_p2_train_bf_pbr.py > log4.file 2>&1 &

多卡训练时,将 ide_debug 设为 False,并根据实际 GPU 数量设置 --nproc_per_node。下面的命令使用六张卡。在独立终端会话中启动,有助于避免暂停 IDE 导致各进程的通信中断。

TEXT
screen -S train_ddp
nohup python -u -m torch.distributed.launch --nproc_per_node 6 s4_p2_train_bf_pbr.py > log4.file 2>&1 &

检查权重和训练进度

权重按物体 ID 保存在数据集的 HccePose/ 目录下。以 demo-tex-objs 为例:

TEXT
demo-tex-objs
|--- HccePose
    |--- obj_01
    ...
    |--- obj_10
|--- models
|--- train_pbr
|--- train_pbr_xyz_GT_back
|--- train_pbr_xyz_GT_front

训练过程中的 test() 从同一个 train_pbr 划分中抽取 1% 的样本,可以用来观察训练进度。要报告基准成绩,请在对应的测试集上进行 BOP 评测。

Train HccePose(BF) for each object

This page uses preparation, training or evaluation scripts from the public upstream source. Obtain that revision as described in Installation, and run these commands from its root. The current project’s examples/inference/ provides application inference.

HccePose(BF) learns a separate set of weights for each object. The script s4_p2_train_bf_pbr.py trains objects in sequence and can use one or more GPUs for each object.

Configure the training script

Prepare the meshes and metadata, PBR scenes and front and back coordinate labels. Open the training script and edit the variables in __main__. Replace the placeholder dataset_path and set the object ID range.

Parameter Example setting Purpose
start_obj_id, end_obj_id 1, 5 Train objects 1 through 5 in sequence. Set both to the same ID to train one object.
total_iteration 50001 Training iteration setting for each object.
batch_size, lr 24, 0.0002 Batch size per GPU and learning rate.
efficientnet_key None Backbone setting used by the training script.

For distributed data parallel (DDP) training, the total number of samples is:

TEXT
total samples = total iteration × batch size × GPU number

Run on one or more GPUs

The default ide_debug=True runs on a single GPU. Use it for debugging or a single-GPU training run:

TEXT
nohup python -u s4_p2_train_bf_pbr.py > log4.file 2>&1 &

For DDP, set ide_debug=False and choose --nproc_per_node to match the number of GPUs. This example uses six. Start the job in a separate terminal session so that pausing your IDE does not interrupt communication between training processes.

TEXT
screen -S train_ddp
nohup python -u -m torch.distributed.launch --nproc_per_node 6 s4_p2_train_bf_pbr.py > log4.file 2>&1 &

Find the weights and monitor training

The script saves checkpoints by object ID under the dataset’s HccePose/ directory. For example, demo-tex-objs uses this layout:

TEXT
demo-tex-objs
|--- HccePose
    |--- obj_01
    ...
    |--- obj_10
|--- models
|--- train_pbr
|--- train_pbr_xyz_GT_back
|--- train_pbr_xyz_GT_front

During training, test() samples 1% of the same train_pbr split to monitor progress. For benchmark scores, run BOP evaluation on the corresponding test split.

打开原图 ↗Open original ↗