概要
若想訓練自己的場景,數(shù)據(jù)集的重要性不做過多贅述,下面就基于 robomimic
和 robosuite
構建自己的數(shù)據(jù)集進行講解,同時,也會附上 train
和 run
的流程,這樣,就形成了閉環(huán)。
自建數(shù)據(jù)集
采集數(shù)據(jù)
采集數(shù)據(jù)可使用腳本 collect_human_demonstrations.py
完成,在采集過程中,需要自己定義 env
的相關信息,在實際使用時,存在以下幾個問題:
- 無法控制機器人精準的完成抓取工作
- 機器人在某些姿態(tài)下,運動會出現(xiàn)漂移的情況
格式轉換
該功能腳本為 convert_robosuite.py
,在進行執(zhí)行是:
$ python conversion/convert_robosuite.py --dataset /path/to/demo.hdf5
生成OBS用于訓練
python dataset_states_to_obs.py --dataset demo_myliftdraw.hdf5 --output AAA.hdf5
BUG記錄
Bug1
在進行 conver_to_robosuite
時,也有個小bug
,當數(shù)據(jù)集中 demo
數(shù)量較少時,比如為1,那么 convert
就會失敗,這是因為在進行 split
時數(shù)據(jù)太少導致的,
"""
Helper script to convert a dataset collected using robosuite into an hdf5 compatible with
this repository. Takes a dataset path corresponding to the demo.hdf5 file containing the
demonstrations. It modifies the dataset in-place. By default, the script also creates a
90-10 train-validation split.
For more information on collecting datasets with robosuite, see the code link and documentation
link below.
Code: https://github.com/ARISE-Initiative/robosuite/blob/offline_study/robosuite/scripts/collect_human_demonstrations.py
Documentation: https://robosuite.ai/docs/algorithms/demonstrations.html
Example usage:
python convert_robosuite.py --dataset /path/to/your/demo.hdf5
"""
import h5py
import json
import argparse
import robomimic.envs.env_base as EB
from robomimic.scripts.split_train_val import split_train_val_from_hdf5
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--dataset",
type=str,
help="path to input hdf5 dataset",
)
args = parser.parse_args()
f = h5py.File(args.dataset, "a") # edit mode
# import ipdb; ipdb.set_trace()
# store env meta
env_name = f["data"].attrs["env"]
env_info = json.loads(f["data"].attrs["env_info"])
env_meta = dict(
type=EB.EnvType.ROBOSUITE_TYPE,
env_name=env_name,
env_version=f["data"].attrs["repository_version"],
env_kwargs=env_info,
)
if "env_args" in f["data"].attrs:
del f["data"].attrs["env_args"]
f["data"].attrs["env_args"] = json.dumps(env_meta, indent=4)
print("====== Stored env meta ======")
print(f["data"].attrs["env_args"])
# store metadata about number of samples
total_samples = 0
for ep in f["data"]:
# ensure model-xml is in per-episode metadata
assert "model_file" in f["data/{}".format(ep)].attrs
# add "num_samples" into per-episode metadata
if "num_samples" in f["data/{}".format(ep)].attrs:
del f["data/{}".format(ep)].attrs["num_samples"]
n_sample = f["data/{}/actions".format(ep)].shape[0]
f["data/{}".format(ep)].attrs["num_samples"] = n_sample
total_samples += n_sample
# add total samples to global metadata
if "total" in f["data"].attrs:
del f["data"].attrs["total"]
f["data"].attrs["total"] = total_samples
f.close()
# create 90-10 train-validation split in the dataset
split_train_val_from_hdf5(hdf5_path=args.dataset, val_ratio=0.1)
最后一行,只需要將 val_ration = 1
就可以了。
Bug2
描述:同樣的操作過程,用自己新建的 env
環(huán)境類生成數(shù)據(jù),在進行 obs
生成時報錯,但是用官方的 env
是沒有問題的
解決方法:不要試圖隨性構建自己的模型庫,因為這玩意是按照固定路徑搜索的,坑坑坑,忙了半天,發(fā)現(xiàn)是路徑的問題,里面有個 robosuite
的固定關鍵詞,這個會影響 to obs
的。
Train && Test
Train
需要調用的腳本是:
$ python robomimic/robomimic/scripts/train.py --config bc_rnn.json
Test
調用的腳本為:
$ python robomimic/robomimic/scripts/un_trained_agent.py --agent /path/to/model.pth --n_rollouts 50 --horizon 400 --seed 0 --video_path /path/to/output.mp4 --camera_names agentview robot0_eye_in_hand
在進行訓練時,需要對算法進行配置,即導入的 json
文件,以下是一個配置文件的案例,該文件來源于 mimicgen
生成的,其中,里面 有對于算法的部分參數(shù), 比如 "algo_name": "bc",
如果功底不夠深厚的話,建議大家只改下數(shù)據(jù)集的 path
就可以了:
{
"algo_name": "bc",
"experiment": {
"name": "source_draw_low_dim",
"validate": false,
"logging": {
"terminal_output_to_txt": true,
"log_tb": true,
"log_wandb": false,
"wandb_proj_name": "debug"
},
"save": {
"enabled": true,
"every_n_seconds": null,
"every_n_epochs": 50,
"epochs": [],
"on_best_validation": false,
"on_best_rollout_return": false,
"on_best_rollout_success_rate": true
},
"epoch_every_n_steps": 100,
"validation_epoch_every_n_steps": 10,
"env": null,
"additional_envs": null,
"render": false,
"render_video": true,
"keep_all_videos": false,
"video_skip": 5,
"rollout": {
"enabled": true,
"n": 50,
"horizon": 400,
"rate": 50,
"warmstart": 0,
"terminate_on_success": true
}
},
"train": {
"data": "/home/idm/Documents/mimicgen/robosuite/robosuite/scripts/generate_dataset/tmp/draw_data/demo_obs.hdf5",
"output_dir": "/home/idm/Documents/mimicgen/robosuite/robosuite/scripts/generate_dataset/tmp/draw_data/trained_models",
"num_data_workers": 0,
"hdf5_cache_mode": "all",
"hdf5_use_swmr": true,
"hdf5_load_next_obs": false,
"hdf5_normalize_obs": false,
"hdf5_filter_key": null,
"hdf5_validation_filter_key": null,
"seq_length": 10,
"pad_seq_length": true,
"frame_stack": 1,
"pad_frame_stack": true,
"dataset_keys": [
"actions",
"rewards",
"dones"
],
"goal_mode": null,
"cuda": true,
"batch_size": 100,
"num_epochs": 2000,
"seed": 1
},
"algo": {
"optim_params": {
"policy": {
"optimizer_type": "adam",
"learning_rate": {
"initial": 0.001,
"decay_factor": 0.1,
"epoch_schedule": [],
"scheduler_type": "multistep"
},
"regularization": {
"L2": 0.0
}
}
},
"loss": {
"l2_weight": 1.0,
"l1_weight": 0.0,
"cos_weight": 0.0
},
"actor_layer_dims": [],
"gaussian": {
"enabled": false,
"fixed_std": false,
"init_std": 0.1,
"min_std": 0.01,
"std_activation": "softplus",
"low_noise_eval": true
},
"gmm": {
"enabled": true,
"num_modes": 5,
"min_std": 0.0001,
"std_activation": "softplus",
"low_noise_eval": true
},
"vae": {
"enabled": false,
"latent_dim": 14,
"latent_clip": null,
"kl_weight": 1.0,
"decoder": {
"is_conditioned": true,
"reconstruction_sum_across_elements": false
},
"prior": {
"learn": false,
"is_conditioned": false,
"use_gmm": false,
"gmm_num_modes": 10,
"gmm_learn_weights": false,
"use_categorical": false,
"categorical_dim": 10,
"categorical_gumbel_softmax_hard": false,
"categorical_init_temp": 1.0,
"categorical_temp_anneal_step": 0.001,
"categorical_min_temp": 0.3
},
"encoder_layer_dims": [
300,
400
],
"decoder_layer_dims": [
300,
400
],
"prior_layer_dims": [
300,
400
]
},
"rnn": {
"enabled": true,
"horizon": 10,
"hidden_dim": 400,
"rnn_type": "LSTM",
"num_layers": 2,
"open_loop": false,
"kwargs": {
"bidirectional": false
}
},
"transformer": {
"enabled": false,
"context_length": 10,
"embed_dim": 512,
"num_layers": 6,
"num_heads": 8,
"emb_dropout": 0.1,
"attn_dropout": 0.1,
"block_output_dropout": 0.1,
"sinusoidal_embedding": false,
"activation": "gelu",
"supervise_all_steps": false,
"nn_parameter_for_timesteps": true
}
},
"observation": {
"modalities": {
"obs": {
"low_dim": [
"robot0_eef_pos",
"robot0_eef_quat",
"robot0_gripper_qpos",
"object"
],
"rgb": [],
"depth": [],
"scan": []
},
"goal": {
"low_dim": [],
"rgb": [],
"depth": [],
"scan": []
}
},
"encoder": {
"low_dim": {
"core_class": null,
"core_kwargs": {},
"obs_randomizer_class": null,
"obs_randomizer_kwargs": {}
},
"rgb": {
"core_class": "VisualCore",
"core_kwargs": {},
"obs_randomizer_class": null,
"obs_randomizer_kwargs": {}
},
"depth": {
"core_class": "VisualCore",
"core_kwargs": {},
"obs_randomizer_class": null,
"obs_randomizer_kwargs": {}
},
"scan": {
"core_class": "ScanCore",
"core_kwargs": {},
"obs_randomizer_class": null,
"obs_randomizer_kwargs": {}
}
}
},
"meta": {
"hp_base_config_file": null,
"hp_keys": [],
"hp_values": []
}
}
部分訓練截圖如下,可以看出,因數(shù)據(jù)太少,導致模型不收斂:文章來源:http://www.zghlxwxcb.cn/news/detail-794869.html
參考資料
RoboMimic文章來源地址http://www.zghlxwxcb.cn/news/detail-794869.html
到了這里,關于機器人技能學習-構建自己的數(shù)據(jù)集并進行訓練的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!