|
- '''
- 使用说明:
- 此程序会根据information.yaml文件创建collection路径及其子路径,用于存放采集数据,并检查information.yaml文件中的配置信息是否有误
- python create_from_information.py -i 'information.yaml'
- 执行后,将在当前路径下创建collection文件夹,并创建子文件夹和相关文件,然后需要把commit.yaml、information.yaml、description.yaml放在对应提示路径下,并把(to-be-deleted)文件删掉
- '''
-
- import yaml
- import os
- import argparse
-
- def recursive_chmod(path, filemode):
- os.chmod(path, filemode)
- for root, dirs, files in os.walk(path):
- for d in dirs:
- os.chmod(os.path.join(root, d), filemode)
- for f in files:
- os.chmod(os.path.join(root, f), filemode)
-
- parser = argparse.ArgumentParser(description='获取输入参数')
- parser.add_argument('-i', '--information_path', help='information_path', default='information.yaml')
- args = parser.parse_args()
- filename = args.information_path
-
- with open(filename, 'r') as file:
- data = yaml.safe_load(file)
-
- folder_path = 'collection/series-1/task-1/episode-1'
- os.makedirs(folder_path, exist_ok=True)
-
- assert data['series_name'] != '', "series_name should not be empty!"
- assert data['scene'] != '', "scene should not be empty!"
-
- if data['pan_tilt']:
- assert data['pan_tilt_control'] != [], "pan_tilt_control should not be empty!"
- file_path = os.path.join(folder_path, 'pan_tilt.txt')
- with open(file_path, 'w') as file:
- pass
-
- arm_gripper = ['right_master_gripper', 'left_master_gripper', 'right_slave_gripper', 'left_slave_gripper']
- for idx in range(data['arm_num']):
- file_path = os.path.join(folder_path, arm_gripper[idx]+'.txt')
- with open(file_path, 'w') as file:
- pass
- if data['arm_num'] > 0:
- assert len(data['arm_operation_mode']) == data['arm_num'], "arm_operation_mode length must be equal to arm_num"
-
- for idx in range(data['camera_num']):
- fpath = os.path.join(folder_path, 'cam-'+str(idx+1))
- os.makedirs(fpath, exist_ok=True)
- if data['camera_num'] > 0:
- assert len(data['cam_view']) == data['camera_num'], "cam_view length must be equal to camera_num"
-
- for idx in range(data['lidar_num']):
- fpath = os.path.join(folder_path, 'lidar-'+str(idx+1))
- os.makedirs(fpath, exist_ok=True)
- if data['lidar_num'] > 0:
- assert len(data['lidar_position']) == data['lidar_num'], "lidar_position length must be equal to lidar_num"
-
- for idx in range(data['rgbd_num']):
- fpath = os.path.join(folder_path, 'rgbd-'+str(idx+1))
- os.makedirs(fpath, exist_ok=True)
- if data['rgbd_num'] > 0:
- assert len(data['rgbd_view']) == data['rgbd_num'], "rgbd_view length must be equal to rgbd_num"
-
- for idx in range(data['touch_num']):
- fpath = os.path.join(folder_path, 'touch-'+str(idx+1))
- os.makedirs(fpath, exist_ok=True)
- if data['touch_num'] > 0:
- assert len(data['touch_position']) == data['touch_num'], "touch_position length must be equal to touch_num"
-
- if 'recorded_left_master_arm_joints' in data:
- assert len(data['recorded_left_master_arm_joints']) <= data['num_joints_per_arm'], \
- "recorded_left_master_arm_joints length must be less or equal to num_joints_per_arm"
- for idx in data['recorded_left_master_arm_joints']:
- file_path = os.path.join(folder_path, 'left_master_arm_joint-'+str(idx)+'.txt')
- with open(file_path, 'w') as file:
- pass
-
- if 'recorded_left_slave_arm_joints' in data:
- assert len(data['recorded_left_slave_arm_joints']) <= data['num_joints_per_arm'], \
- "recorded_left_slave_arm_joints length must be less or equal to num_joints_per_arm"
- for idx in data['recorded_left_slave_arm_joints']:
- file_path = os.path.join(folder_path, 'left_slave_arm_joint-'+str(idx)+'.txt')
- with open(file_path, 'w') as file:
- pass
-
- if 'recorded_right_master_arm_joints' in data:
- assert len(data['recorded_right_master_arm_joints']) <= data['num_joints_per_arm'], \
- "recorded_right_master_arm_joints length must be less or equal to num_joints_per_arm"
- for idx in data['recorded_right_master_arm_joints']:
- file_path = os.path.join(folder_path, 'right_master_arm_joint-'+str(idx)+'.txt')
- with open(file_path, 'w') as file:
- pass
-
- if 'recorded_right_slave_arm_joints' in data:
- assert len(data['recorded_right_slave_arm_joints']) <= data['num_joints_per_arm'], \
- "recorded_right_slave_arm_joints length must be less or equal to num_joints_per_arm"
- for idx in data['recorded_right_slave_arm_joints']:
- file_path = os.path.join(folder_path, 'right_slave_arm_joint-'+str(idx)+'.txt')
- with open(file_path, 'w') as file:
- pass
-
- if data['audio_num'] > 0:
- assert len(data['audio_frequency']) == data['audio_num'], "audio_frequency length must be equal to audio_num"
-
- for idx in range(data['IMU_num']):
- file_path = os.path.join(folder_path, 'IMU-'+str(idx+1)+'.txt')
- with open(file_path, 'w') as file:
- pass
- if data['IMU_num'] > 0:
- assert len(data['IMU_position']) == data['IMU_num'], "IMU_position length must be equal to IMU_num"
-
- file_path = os.path.join('collection', 'commit(to-be-deleted).yaml')
- with open(file_path, 'w') as file:
- pass
- file_path = os.path.join('collection/series-1', 'information(to-be-deleted).yaml')
- with open(file_path, 'w') as file:
- pass
- file_path = os.path.join('collection/series-1/task-1', 'description(to-be-deleted).yaml')
- with open(file_path, 'w') as file:
- pass
- file_path = os.path.join('collection/series-1/task-1', 'task_record(to-be-deleted).mp4')
- with open(file_path, 'w') as file:
- pass
- recursive_chmod('collection', 0o777)
|