update postprocess_episodes for base_action, skip_mirrored_data option
这个提交包含在:
@ -73,6 +73,7 @@ def get_args_parser():
|
|||||||
parser.add_argument('--save_every', action='store', type=int, default=500, help='save_every', required=False)
|
parser.add_argument('--save_every', action='store', type=int, default=500, help='save_every', required=False)
|
||||||
parser.add_argument('--resume_ckpt_path', action='store', type=str, help='load_ckpt_path', required=False)
|
parser.add_argument('--resume_ckpt_path', action='store', type=str, help='load_ckpt_path', required=False)
|
||||||
parser.add_argument('--no_encoder', action='store_true')
|
parser.add_argument('--no_encoder', action='store_true')
|
||||||
|
parser.add_argument('--skip_mirrored_data', action='store_true')
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|||||||
@ -127,7 +127,7 @@ def main(args):
|
|||||||
print()
|
print()
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
train_dataloader, val_dataloader, stats, _ = load_data(dataset_dir, name_filter, camera_names, batch_size_train, batch_size_val, args['chunk_size'])
|
train_dataloader, val_dataloader, stats, _ = load_data(dataset_dir, name_filter, camera_names, batch_size_train, batch_size_val, args['chunk_size'], args['skip_mirrored_data'])
|
||||||
|
|
||||||
# save dataset stats
|
# save dataset stats
|
||||||
stats_path = os.path.join(ckpt_dir, f'dataset_stats.pkl')
|
stats_path = os.path.join(ckpt_dir, f'dataset_stats.pkl')
|
||||||
@ -475,6 +475,7 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('--validate_every', action='store', type=int, default=500, help='validate_every', required=False)
|
parser.add_argument('--validate_every', action='store', type=int, default=500, help='validate_every', required=False)
|
||||||
parser.add_argument('--save_every', action='store', type=int, default=500, help='save_every', required=False)
|
parser.add_argument('--save_every', action='store', type=int, default=500, help='save_every', required=False)
|
||||||
parser.add_argument('--resume_ckpt_path', action='store', type=str, help='resume_ckpt_path', required=False)
|
parser.add_argument('--resume_ckpt_path', action='store', type=str, help='resume_ckpt_path', required=False)
|
||||||
|
parser.add_argument('--skip_mirrored_data', action='store_true')
|
||||||
|
|
||||||
# for ACT
|
# for ACT
|
||||||
parser.add_argument('--kl_weight', action='store', type=int, help='KL Weight', required=False)
|
parser.add_argument('--kl_weight', action='store', type=int, help='KL Weight', required=False)
|
||||||
|
|||||||
@ -15,8 +15,8 @@ e = IPython.embed
|
|||||||
JOINT_NAMES = ["waist", "shoulder", "elbow", "forearm_roll", "wrist_angle", "wrist_rotate"]
|
JOINT_NAMES = ["waist", "shoulder", "elbow", "forearm_roll", "wrist_angle", "wrist_rotate"]
|
||||||
STATE_NAMES = JOINT_NAMES + ["gripper"]
|
STATE_NAMES = JOINT_NAMES + ["gripper"]
|
||||||
|
|
||||||
MIRROR_STATE_MULTIPLY = np.array([-1, 1, 1, -1, 1, -1, 1])[None, ...].astype('float32')
|
MIRROR_STATE_MULTIPLY = np.array([-1, 1, 1, -1, 1, -1, 1]).astype('float32')
|
||||||
|
MIRROR_BASE_MULTIPLY = np.array([1, -1]).astype('float32')
|
||||||
|
|
||||||
def load_hdf5(dataset_dir, dataset_name):
|
def load_hdf5(dataset_dir, dataset_name):
|
||||||
dataset_path = os.path.join(dataset_dir, dataset_name + '.hdf5')
|
dataset_path = os.path.join(dataset_dir, dataset_name + '.hdf5')
|
||||||
@ -32,8 +32,13 @@ def load_hdf5(dataset_dir, dataset_name):
|
|||||||
image_dict = dict()
|
image_dict = dict()
|
||||||
for cam_name in root[f'/observations/images/'].keys():
|
for cam_name in root[f'/observations/images/'].keys():
|
||||||
image_dict[cam_name] = root[f'/observations/images/{cam_name}'][()]
|
image_dict[cam_name] = root[f'/observations/images/{cam_name}'][()]
|
||||||
|
if 'base_action' in root.keys():
|
||||||
|
print('base_action exists')
|
||||||
|
base_action = root['/base_action'][()]
|
||||||
|
else:
|
||||||
|
base_action = None
|
||||||
|
|
||||||
return qpos, qvel, action, image_dict
|
return qpos, qvel, action, base_action, image_dict
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
dataset_dir = args['dataset_dir']
|
dataset_dir = args['dataset_dir']
|
||||||
@ -42,22 +47,40 @@ def main(args):
|
|||||||
for episode_idx in range(num_episodes):
|
for episode_idx in range(num_episodes):
|
||||||
dataset_name = f'episode_{episode_idx}'
|
dataset_name = f'episode_{episode_idx}'
|
||||||
|
|
||||||
qpos, qvel, action, image_dict = load_hdf5(dataset_dir, dataset_name)
|
qpos, qvel, action, base_action, image_dict = load_hdf5(dataset_dir, dataset_name)
|
||||||
|
|
||||||
# process proprioception
|
# process proprioception
|
||||||
qpos = np.concatenate([qpos[:, 7:] * MIRROR_STATE_MULTIPLY, qpos[:, :7] * MIRROR_STATE_MULTIPLY], axis=1)
|
qpos = np.concatenate([qpos[:, 7:] * MIRROR_STATE_MULTIPLY, qpos[:, :7] * MIRROR_STATE_MULTIPLY], axis=1)
|
||||||
qvel = np.concatenate([qvel[:, 7:] * MIRROR_STATE_MULTIPLY, qvel[:, :7] * MIRROR_STATE_MULTIPLY], axis=1)
|
qvel = np.concatenate([qvel[:, 7:] * MIRROR_STATE_MULTIPLY, qvel[:, :7] * MIRROR_STATE_MULTIPLY], axis=1)
|
||||||
action = np.concatenate([action[:, 7:] * MIRROR_STATE_MULTIPLY, action[:, :7] * MIRROR_STATE_MULTIPLY], axis=1)
|
action = np.concatenate([action[:, 7:] * MIRROR_STATE_MULTIPLY, action[:, :7] * MIRROR_STATE_MULTIPLY], axis=1)
|
||||||
|
if base_action is not None:
|
||||||
|
base_action = base_action * MIRROR_BASE_MULTIPLY
|
||||||
|
|
||||||
# mirror image obs
|
# mirror image obs
|
||||||
|
if 'left_wrist' in image_dict.keys():
|
||||||
image_dict['left_wrist'], image_dict['right_wrist'] = image_dict['right_wrist'][:, :, ::-1], image_dict['left_wrist'][:, :, ::-1]
|
image_dict['left_wrist'], image_dict['right_wrist'] = image_dict['right_wrist'][:, :, ::-1], image_dict['left_wrist'][:, :, ::-1]
|
||||||
|
elif 'cam_left_wrist':
|
||||||
|
image_dict['cam_left_wrist'], image_dict['cam_right_wrist'] = image_dict['cam_right_wrist'][:, :, ::-1], image_dict['cam_left_wrist'][:, :, ::-1]
|
||||||
|
else:
|
||||||
|
raise Exception('No left_wrist or cam_left_wrist in image_dict')
|
||||||
|
|
||||||
|
if 'top' in image_dict.keys():
|
||||||
image_dict['top'] = image_dict['top'][:, :, ::-1]
|
image_dict['top'] = image_dict['top'][:, :, ::-1]
|
||||||
|
elif 'cam_high' in image_dict.keys():
|
||||||
|
image_dict['cam_high'] = image_dict['cam_high'][:, :, ::-1]
|
||||||
|
else:
|
||||||
|
raise Exception('No top or cam_high in image_dict')
|
||||||
|
|
||||||
# saving
|
# saving
|
||||||
data_dict = {
|
data_dict = {
|
||||||
'/observations/qpos': qpos,
|
'/observations/qpos': qpos,
|
||||||
'/observations/qvel': qvel,
|
'/observations/qvel': qvel,
|
||||||
'/action': action,
|
'/action': action,
|
||||||
|
'/base_action': base_action,
|
||||||
|
} if base_action is not None else {
|
||||||
|
'/observations/qpos': qpos,
|
||||||
|
'/observations/qvel': qvel,
|
||||||
|
'/action': action,
|
||||||
}
|
}
|
||||||
for cam_name in image_dict.keys():
|
for cam_name in image_dict.keys():
|
||||||
data_dict[f'/observations/images/{cam_name}'] = image_dict[cam_name]
|
data_dict[f'/observations/images/{cam_name}'] = image_dict[cam_name]
|
||||||
@ -78,6 +101,8 @@ def main(args):
|
|||||||
qpos = obs.create_dataset('qpos', (max_timesteps, 14))
|
qpos = obs.create_dataset('qpos', (max_timesteps, 14))
|
||||||
qvel = obs.create_dataset('qvel', (max_timesteps, 14))
|
qvel = obs.create_dataset('qvel', (max_timesteps, 14))
|
||||||
action = root.create_dataset('action', (max_timesteps, 14))
|
action = root.create_dataset('action', (max_timesteps, 14))
|
||||||
|
if base_action is not None:
|
||||||
|
base_action = root.create_dataset('base_action', (max_timesteps, 2))
|
||||||
|
|
||||||
for name, array in data_dict.items():
|
for name, array in data_dict.items():
|
||||||
root[name][...] = array
|
root[name][...] = array
|
||||||
|
|||||||
9
utils.py
9
utils.py
@ -146,16 +146,19 @@ def get_norm_stats(dataset_path_list):
|
|||||||
|
|
||||||
return stats, all_episode_len
|
return stats, all_episode_len
|
||||||
|
|
||||||
def find_all_hdf5(dataset_dir):
|
def find_all_hdf5(dataset_dir, skip_mirrored_data):
|
||||||
hdf5_files = []
|
hdf5_files = []
|
||||||
for root, dirs, files in os.walk(dataset_dir):
|
for root, dirs, files in os.walk(dataset_dir):
|
||||||
for filename in fnmatch.filter(files, '*.hdf5'):
|
for filename in fnmatch.filter(files, '*.hdf5'):
|
||||||
|
if skip_mirrored_data and 'mirror' in filename:
|
||||||
|
continue
|
||||||
hdf5_files.append(os.path.join(root, filename))
|
hdf5_files.append(os.path.join(root, filename))
|
||||||
|
print(f'Found {len(hdf5_files)} hdf5 files')
|
||||||
return hdf5_files
|
return hdf5_files
|
||||||
|
|
||||||
|
|
||||||
def load_data(dataset_dir, name_filter, camera_names, batch_size_train, batch_size_val, chunk_size):
|
def load_data(dataset_dir, name_filter, camera_names, batch_size_train, batch_size_val, chunk_size, skip_mirrored_data=False):
|
||||||
dataset_path_list = find_all_hdf5(dataset_dir)
|
dataset_path_list = find_all_hdf5(dataset_dir, skip_mirrored_data)
|
||||||
dataset_path_list = [n for n in dataset_path_list if name_filter(n)]
|
dataset_path_list = [n for n in dataset_path_list if name_filter(n)]
|
||||||
num_episodes = len(dataset_path_list)
|
num_episodes = len(dataset_path_list)
|
||||||
|
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户