This is a project done in google colab. I’m given a .hdf5 file with robot trajectory demonstrations. The assignment is to film new trajectories using architectures we’ve learned about in class. I’ve done that, it’s the copying the new trajectory to a new .hdf5 file that seems to be an issue
def segment_data(f, filename, num_demos, testing):
keys = list(f["data"].keys()) # get all demonstration ids
for i in range(1, num_demos): # iterate over all demonstrations
subfile = filename + ".hdf5"
if os.path.exists(subfile):
os.remove(subfile)
f_new = h5py.File(subfile, "w")
grp = f_new.create_group("data")
grp.attrs.create("env_args", f["data"].attrs["env_args"]) # copy over the environment args
grp.attrs.create("total", f["data"].attrs["total"]) # copy over the "total" attribute
# copy over each of the next demonstrations to the new group
f.copy("data/{}".format(keys[i]), grp, name=keys[i])
# edit 'obs' data if it exists
if 'obs' in grp[keys[i]]:
# Modify 'robot_eef_pos' data here
grp[keys[i]]['obs']['robot0_eef_pos'][:] = [[1.1, 2.1, 3.1] for _ in range(len(grp[keys[i]]['obs']['robot0_eef_pos']))]
grp[keys[i]]['obs']['robot0_gripper_qpos'][:] = [[0.0, 0.0] for _ in range(len(grp[keys[i]]['obs']['robot0_gripper_qpos']))]
f_new.close()
f is a pointer pointing to the file that contains the robot trajectories, filename is the file I want to save it to, num_demos is the number of demonstrations in f (yes I know this code will overwrite every bit of data except the last demonstration. I plan to fix that later) testing is well, the new demonstrations I want to test. But currently I’m trying to make it so that ‘obs’ basically stays constant for every end effector position and gripper position. When I print out. When I have a pointer pointing to the new file and asking it what the values are, it correctly says the constants I put in, but when I use the function to play the video, the trajectory is identical used as a demonstration