Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
81c2ead
初次代码提交
2088376133zh Jan 14, 2026
7bfc7fa
提交论文第一章
2088376133zh Jan 15, 2026
b490c72
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng Apr 17, 2026
7483e6a
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng Apr 17, 2026
f07ceaf
初始化项目,上传基础文件
2088376133zh Apr 17, 2026
1114ad6
添加依赖配置与环境说明
2088376133zh Apr 18, 2026
3702d52
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng Apr 19, 2026
99653f8
更改文件夹名称
2088376133zh Apr 19, 2026
adc7ed1
添加生物力学肌肉双臂模型与XML文件
2088376133zh Apr 19, 2026
2046276
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng Apr 19, 2026
05babf0
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng Apr 19, 2026
285d64e
添加代码修改文件名
2088376133zh Apr 19, 2026
3a74583
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng Apr 22, 2026
2d0de79
删除旧文件并更新项目结构
2088376133zh Apr 22, 2026
a8a588b
提交代码文件
2088376133zh Apr 22, 2026
83fdb97
修改文件夹
2088376133zh Apr 22, 2026
481b33d
提交代码文件
2088376133zh Apr 22, 2026
d7d9dda
修改文件
2088376133zh Apr 22, 2026
63b9d5f
重新提交代码文件
2088376133zh Apr 22, 2026
4e961dc
分批上次代码文件
2088376133zh Apr 22, 2026
afd3b6f
部分
2088376133zh Apr 22, 2026
f361622
删除
2088376133zh Apr 22, 2026
f9fb3f7
提交代码
2088376133zh Apr 22, 2026
863961a
分批
2088376133zh Apr 22, 2026
e96cdcd
删除
2088376133zh Apr 22, 2026
06fb33d
代码
2088376133zh Apr 22, 2026
72dd0c2
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng Apr 24, 2026
c833d3b
提交
2088376133zh Apr 24, 2026
3c7f398
提交部分
2088376133zh Apr 24, 2026
6e536de
重新交
2088376133zh Apr 24, 2026
491d38b
提交部分
2088376133zh Apr 24, 2026
b3051e7
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng Apr 27, 2026
a9920ea
提交修改的代码
2088376133zh Apr 27, 2026
3862b2b
提交修改代码
2088376133zh Apr 27, 2026
0bf7afd
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng Apr 28, 2026
9a10e8c
修改不必要的提交
2088376133zh Apr 28, 2026
6b7f7e8
Merge branch 'master' of https://github.com/ZH1024-Heng/sim
2088376133zh Apr 28, 2026
ba9859e
提交修改
2088376133zh Apr 28, 2026
f29a394
提交修改
2088376133zh Apr 28, 2026
0826c22
1
2088376133zh Apr 28, 2026
d8363e9
提交模型文件和代码
2088376133zh Apr 28, 2026
09f0a6d
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng Apr 29, 2026
0f5517f
提交代码
2088376133zh Apr 30, 2026
466479f
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng May 5, 2026
b8c7795
添加模块文件
2088376133zh May 5, 2026
0951084
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng May 6, 2026
e61f953
提交文件
2088376133zh May 6, 2026
3c846b5
更改文件
2088376133zh May 6, 2026
32c9e73
Merge branch 'master' of https://github.com/ZH1024-Heng/sim
2088376133zh May 6, 2026
cb4f36f
提交部分代码文件
2088376133zh May 6, 2026
a3b7a42
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng May 7, 2026
66b4d61
添加模型和代码
2088376133zh May 7, 2026
adce73b
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng May 9, 2026
814e60d
提交代码
2088376133zh May 9, 2026
450c146
1
2088376133zh May 9, 2026
3885d51
Merge branch 'master' of https://github.com/ZH1024-Heng/sim
2088376133zh May 9, 2026
9f7bedc
提交代码
2088376133zh May 9, 2026
0083f6e
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng May 10, 2026
76d955d
替换修改论文内容
2088376133zh May 10, 2026
d5d1e24
Merge branch 'master' of https://github.com/ZH1024-Heng/sim
2088376133zh May 10, 2026
892ffc1
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng May 10, 2026
979e1bd
修改
2088376133zh May 10, 2026
b8b9c4f
Merge branch 'OpenHUTB:master' into master
ZH1024-Heng May 11, 2026
c84c5ca
提交代码
2088376133zh May 11, 2026
b8c0b70
Merge branch 'master' of https://github.com/ZH1024-Heng/sim
2088376133zh May 11, 2026
9522ab3
修改
2088376133zh May 11, 2026
60822c0
提交代码
2088376133zh May 11, 2026
a81aa44
1
2088376133zh May 11, 2026
e293094
提交代码
2088376133zh May 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
121 changes: 121 additions & 0 deletions hci/user-in-the-box/uitb/train/trainer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import sys
import os, shutil
import logging
from datetime import datetime

import wandb
from wandb.integration.sb3 import WandbCallback

from uitb.simulator import Simulator
from uitb.utils.functions import output_path, timeout_input

from stable_baselines3.common.save_util import load_from_zip_file

import argparse

if __name__=="__main__":

parser = argparse.ArgumentParser(description='Train an agent.')
parser.add_argument('config_file_path', type=str,
help='path to the config file')
parser.add_argument('--checkpoint', type=str, default=None,
help='filename of a specific checkpoint to resume training at '
'(default: None, start training from the scratch)')
parser.add_argument('--resume', action='store_true', help='resume at latest checkpoint')
parser.add_argument('--eval', type=int, default=None, const=400000, nargs='?', help='run and store evaluations at a specific frequency (every ``eval`` timestep)')
parser.add_argument('--eval_info_keywords', type=str, nargs='*', default=[], help='additional keys of ``info`` dict that should be logged at the end of each evaluation episode')
args = parser.parse_args()

# Get config file path
config_file_path = args.config_file_path

# Build the simulator
simulator_folder = Simulator.build(config_file_path)

# Initialise
simulator = Simulator.get(simulator_folder)

# Get the config
config = simulator.config

# Get simulator name
name = config.get("simulator_name", None)

# Get checkpoint dir
checkpoint_dir = os.path.join(simulator._simulator_folder, 'checkpoints')

# Restore wandb run_id from checkpoint if available
checkpoint = args.checkpoint
resume_training = args.resume or (checkpoint is not None)
if resume_training:
if os.path.isdir(checkpoint_dir):
existing_checkpoints = [os.path.join(checkpoint_dir, f) for f in os.listdir(checkpoint_dir) if
os.path.isfile(os.path.join(checkpoint_dir, f))]
else:
raise FileNotFoundError(f"Checkpoint directory does not exist: {checkpoint_dir}\nTry to run without --checkpoint or --resume.")

if checkpoint is not None:
checkpoint_path = os.path.join(checkpoint_dir, checkpoint)
if not os.path.isfile(checkpoint_path):
raise FileNotFoundError(f"Checkpoint does not exist: {checkpoint_path}")
else:
assert len(existing_checkpoints) > 0, f"There are no checkpoints found in checkpoint directory: {checkpoint_dir}\n" \
f"Maybe existing checkpoints were moved to a backup directory, " \
f"which can be renamed to 'checkpoints/' to resume training."
# # find largest checkpoint
# checkpoint_path = sorted(existing_checkpoints, key=lambda f: int(f.split("_steps")[0].split("_")[-1]))[-1]
# find latest checkpoint
checkpoint_path = sorted(existing_checkpoints, key=os.path.getctime)[-1]
try:
_data, _, _ = load_from_zip_file(checkpoint_path)
wandb_id = _data["policy_kwargs"]["wandb_id"]
print(f"Resume wandb run {wandb_id} starting at checkpoint {checkpoint_path}.")
except Exception:
logging.warning("Cannot reliably identify wandb run id. Will resume training, but with new wandb instance and with step counter reset to zero.")
wandb_id = None
else:
checkpoint_path = None
wandb_id = None
# Backup existing checkpoint directory
if os.path.isdir(checkpoint_dir):
existing_checkpoints = [os.path.join(checkpoint_dir, f) for f in os.listdir(checkpoint_dir) if
os.path.isfile(os.path.join(checkpoint_dir, f))]
if len(existing_checkpoints) > 0:
last_checkpoint_time = max([os.path.getctime(f) for f in existing_checkpoints])
last_checkpoint_time = datetime.fromtimestamp(last_checkpoint_time).strftime('%Y%m%d_%H%M%S')
checkpoint_dir_backup = os.path.join(simulator._simulator_folder, f'checkpoints_{last_checkpoint_time}')
shutil.move(checkpoint_dir, checkpoint_dir_backup)

if name is None:
# Ask user to name this run
name = timeout_input("Give a name for this run. Input empty string or wait for 30 seconds for a random name.",
timeout=30, default="")
config["simulator_name"] = name.replace("-", "_")

# Get project name
project = config.get("project", "uitb")

# Prepare evaluation by storing custom log tags
with_evaluation = args.eval is not None
eval_freq = args.eval
eval_info_keywords = tuple(args.eval_info_keywords)

# Initialise wandb
if wandb_id is None:
wandb_id = wandb.util.generate_id()
run = wandb.init(id=wandb_id, resume="allow", project=project, name=name, config=config, sync_tensorboard=True, save_code=True, dir=output_path())

# Initialise RL model
rl_cls = simulator.get_class("rl", config["rl"]["algorithm"])
rl_model = rl_cls(simulator, checkpoint_path=checkpoint_path, wandb_id=wandb_id)

# Haven't figured out how to periodically save rl in wandb; this is currently done inside the rl_model class
# TODO this doesn't seem to work; do the files need to be in wandb.run.dir?
#wandb.save(os.path.join(model_folder, run.name, 'checkpoints', "model_*_steps.zip"),
# base_path=os.path.join(model_folder, run.name, 'checkpoints'))

# Start the training
# rl_model.learn(WandbCallback(verbose=2))
rl_model.learn(WandbCallback(verbose=2),
with_evaluation=with_evaluation, eval_freq=eval_freq, eval_info_keywords=eval_info_keywords)
run.finish()