def log_visuals(self, paths, epoch, log_dir): # turn the xy pos into arrays you can work with # N_paths x path_len x 2 # xy_pos = np.array([[d['xy_pos'] for d in path["env_info"]] for path in paths]) # plot using seaborn heatmap xy_pos = [np.array([d['xy_pos'] for d in path["env_info"]]) for path in paths] xy_pos = np.array([d['xy_pos'] for path in paths for d in path['env_info']]) PLOT_BOUND = int(self.env_bound * 1.25) plot_seaborn_heatmap( xy_pos[:,0], xy_pos[:,1], 30, 'Point-Mass Heatmap Epoch %d'%epoch, os.path.join(log_dir, 'heatmap_epoch_%d.png'%epoch), [[-PLOT_BOUND,PLOT_BOUND], [-PLOT_BOUND,PLOT_BOUND]] ) plot_scatter( xy_pos[:,0], xy_pos[:,1], 30, 'Point-Mass Scatter Epoch %d'%epoch, os.path.join(log_dir, 'scatter_epoch_%d.png'%epoch), [[-PLOT_BOUND,PLOT_BOUND], [-PLOT_BOUND,PLOT_BOUND]] ) return {}
def log_new_ant_multi_statistics(self, paths, epoch, log_dir): # turn the xy pos into arrays you can work with # N_paths x path_len x 2 # xy_pos = np.array([[d['xy_pos'] for d in path["env_infos"]] for path in paths]) # plot using seaborn heatmap xy_pos = [ np.array([d['xy_pos'] for d in path["env_infos"]]) for path in paths ] xy_pos = np.array( [d['xy_pos'] for path in paths for d in path['env_infos']]) PLOT_BOUND = 6 plot_seaborn_heatmap( xy_pos[:, 0], xy_pos[:, 1], 30, 'Ant Heatmap Epoch %d' % epoch, os.path.join(log_dir, 'heatmap_epoch_%d.png' % epoch), [[-PLOT_BOUND, PLOT_BOUND], [-PLOT_BOUND, PLOT_BOUND]]) plot_scatter(xy_pos[:, 0], xy_pos[:, 1], 30, 'Ant Heatmap Epoch %d' % epoch, os.path.join(log_dir, 'scatter_epoch_%d.png' % epoch), [[-PLOT_BOUND, PLOT_BOUND], [-PLOT_BOUND, PLOT_BOUND]]) return {}
def gen_plus_sign(distance, num_points_per_direction, save_path): SCALE = 1.0 # CENTER_BUFFER = 3*SCALE # CENTER_BUFFER = 6*SCALE CENTER_BUFFER = 0.0 print(SCALE, CENTER_BUFFER) X = [] Y = [] # East for _ in range(num_points_per_direction): x = np.random.uniform(CENTER_BUFFER, float(distance)) y = np.random.normal(loc=0.0, scale=SCALE) X.append(x) Y.append(y) # West for _ in range(num_points_per_direction): x = np.random.uniform(-float(distance), -CENTER_BUFFER) y = np.random.normal(loc=0.0, scale=SCALE) X.append(x) Y.append(y) # North for _ in range(num_points_per_direction): y = np.random.uniform(CENTER_BUFFER, float(distance)) x = np.random.normal(loc=0.0, scale=SCALE) X.append(x) Y.append(y) # South for _ in range(num_points_per_direction): y = np.random.uniform(-float(distance), -CENTER_BUFFER) x = np.random.normal(loc=0.0, scale=SCALE) X.append(x) Y.append(y) plot_2dhistogram(X, Y, 30, 'test', 'plots/junk_vis/test_plus.png', [[-distance, distance], [-distance, distance]]) plot_scatter(X, Y, 30, 'test', 'plots/junk_vis/test_plus_scatter.png', [[-distance, distance], [-distance, distance]]) plot_seaborn_heatmap(X, Y, 30, 'test', 'plots/junk_vis/test_plus_sns.png', [[-distance, distance], [-distance, distance]]) XY_DATA = np.array([X, Y]).T print(XY_DATA.shape) print(np.mean(XY_DATA, axis=0).shape) print(np.std(XY_DATA, axis=0).shape) joblib.dump( { 'xy_data': XY_DATA, 'xy_mean': np.mean(XY_DATA, axis=0), 'xy_std': np.std(XY_DATA, axis=0) }, save_path, compress=3)
def log_new_ant_multi_statistics(self, paths, epoch, log_dir): xy_pos = np.array( [d['xy_pos'] for path in paths for d in path['env_infos']]) PLOT_BOUND = 60 plot_scatter(xy_pos[:, 0], xy_pos[:, 1], 30, 'XY Pos Epoch %d' % epoch, os.path.join(log_dir, 'xy_pos_epoch_%d.png' % epoch), [[-PLOT_BOUND, PLOT_BOUND], [-PLOT_BOUND, PLOT_BOUND]]) return {}
def gen_plus_sign(distance, num_points_per_direction, save_path): RADIUS = 2.0 SCALE = 1.0 # CENTER_BUFFER = 3*SCALE # CENTER_BUFFER = 6*SCALE CENTER_BUFFER = 0.0 print(SCALE, CENTER_BUFFER) X = [] Y = [] for _ in range(num_points_per_direction * 4): # y = np.random.uniform(-float(distance), -CENTER_BUFFER) # x = np.random.normal(loc=0.0, scale=SCALE) xy = np.random.normal(size=2) xy = xy / np.linalg.norm(xy) xy *= RADIUS xy += np.random.normal(size=2)*0.15 X.append(xy[0]) Y.append(xy[1]) plot_2dhistogram( X, Y, 30, 'test', 'plots/junk_vis/test_plus.png', [[-distance,distance], [-distance,distance]] ) plot_scatter( X, Y, 30, 'test', 'plots/junk_vis/test_plus_scatter.png', [[-distance,distance], [-distance,distance]] ) plot_seaborn_heatmap( X, Y, 30, 'test', 'plots/junk_vis/test_plus_sns.png', [[-distance,distance], [-distance,distance]] ) XY_DATA = np.array([X,Y]).T print(XY_DATA.shape) print(np.mean(XY_DATA, axis=0).shape) print(np.std(XY_DATA, axis=0).shape) joblib.dump( { 'xy_data': XY_DATA, 'xy_mean': np.mean(XY_DATA, axis=0), 'xy_std': np.std(XY_DATA, axis=0) }, save_path, compress=3 )
def log_visuals(self, paths, epoch, log_dir): xyz = np.array([d['xyz'] for path in paths for d in path['env_info']]) a = np.array([d['a'] for path in paths for d in path['env_info']]) plot_scatter( xyz[:,0], xyz[:,1], 30, 'Top-Down Epoch %d'%epoch, os.path.join(log_dir, 'top_down_epoch_%d.png'%epoch), [[-1,1], [-1.6,0.4]] ) plot_scatter( a.flatten(), xyz[:,2], 30, 'AZ Epoch %d'%epoch, os.path.join(log_dir, 'a_z_epoch%d.png'%epoch), [[-np.pi,np.pi], [-1,1]] ) return {}
def log_visuals(self, paths, epoch, log_dir): grip_pos = np.array( [d['grip_pos'] for path in paths for d in path['env_info']]) obj_pos = np.array( [d['obj_pos'] for path in paths for d in path['env_info']]) # PLOT_BOUND = 2 plot_scatter( grip_pos[:, 0], grip_pos[:, 1], 30, 'Grip Pos Epoch %d' % epoch, os.path.join(log_dir, 'grip_pos_epoch_%d.png' % epoch), # [[-PLOT_BOUND,PLOT_BOUND], [-PLOT_BOUND,PLOT_BOUND]] [ # [0.98697072 - 0.3, 0.98697072 + 0.175], # [0.74914774 - 0.35, 0.74914774 + 0.45] [1.34196849 - 0.3, 1.34196849 + 0.2], [0.74910081 - 0.35, 0.74910081 + 0.35] ]) plot_scatter( obj_pos[:, 0], obj_pos[:, 1], 30, 'Obj Pos Epoch %d' % epoch, os.path.join(log_dir, 'obj_pos_epoch_%d.png' % epoch), # [[-PLOT_BOUND,PLOT_BOUND], [-PLOT_BOUND,PLOT_BOUND]] [ # [0.98697072 - 0.3, 0.98697072 + 0.175], # [0.74914774 - 0.35, 0.74914774 + 0.45] [1.34196849 - 0.3, 1.34196849 + 0.2], [0.74910081 - 0.35, 0.74910081 + 0.35] ]) return {}
def log_visuals(self, paths, epoch, log_dir): arm_xyz = np.array([d['arm_xyz'] for path in paths for d in path['env_info']]) obj_xyz = np.array([d['obj_xyz'] for path in paths for d in path['env_info']]) min_arm_to_obj = np.array([min(-d['reward_near'] for d in path['env_info']) for path in paths]) min_obj_to_goal = np.array([min(-d['reward_dist'] for d in path['env_info']) for path in paths]) successes = [np.sum([d['success'] for d in path['env_info']]) > 0 for path in paths] success_rate = float(np.sum(successes)) / float(len(successes)) plot_scatter( arm_xyz[:,0], arm_xyz[:,1], 30, 'Pusher Arm X-Y Epoch %d'%epoch, os.path.join(log_dir, 'arm_x_y_epoch_%d.png'%epoch), [[-0.5,1], [-1,0.5]] ) plot_scatter( arm_xyz[:,1], arm_xyz[:,2], 30, 'Pusher Arm Y-Z Epoch %d'%epoch, os.path.join(log_dir, 'arm_y_z_epoch_%d.png'%epoch), [[-1,0.5], [-0.5,0.5]] ) plot_scatter( obj_xyz[:,0], obj_xyz[:,1], 30, 'Obj X-Y Epoch %d'%epoch, os.path.join(log_dir, 'obj_x_y_epoch_%d.png'%epoch), [[-0.5,1], [-1,0.5]] ) return {}
# XY_DATA = np.array([X,Y]).T # print(XY_DATA.shape) # print(np.mean(XY_DATA, axis=0).shape) # print(np.std(XY_DATA, axis=0).shape) # joblib.dump( # { # 'data': XY_DATA, # 'xy_mean': np.mean(XY_DATA, axis=0), # 'xy_std': np.std(XY_DATA, axis=0) # }, # save_path, # compress=3 # ) bound = 2 plot_scatter(pusher_points[:, 0], pusher_points[:, 1], 30, 'test', 'plots/data_gen/pusher_top_down.png', [[-1, 1], [-1.6, 0.4]]) plot_scatter( a, # np.arctan2(pusher_points[:,1], pusher_points[:,0]), pusher_points[:, 2], 30, 'test', 'plots/data_gen/pusher_a_z.png', [[-np.pi, np.pi], [-1, 1]]) print(pusher_points.shape) joblib.dump({ 'data': pusher_points, }, save_path, compress=3)
# save_path = '/scratch/hdd001/home/kamyar/expert_demos/data_gen/slide_column.pkl' # data = column(8000) save_path = '/scratch/hdd001/home/kamyar/expert_demos/data_gen/corl_box_pushing_from_center.pkl' data = uniform_box(10000) X = data[:,0] Y = data[:,1] plot_scatter( X, Y, 30, 'test', 'plots/data_gen/obj_scatter.png', [ [1.34196849 - 0.3, 1.34196849 + 0.2], [0.74910081 - 0.35, 0.74910081 + 0.35] ] ) X = data[:,2] Y = data[:,3] plot_scatter( X, Y, 30, 'test', 'plots/data_gen/grip_scatter.png', [ [1.34196849 - 0.3, 1.34196849 + 0.2], [0.74910081 - 0.35, 0.74910081 + 0.35] ] ) print(data.shape) joblib.dump(
all_samples.append(np.concatenate([arm_traj, obj_traj[:, :2]], axis=1)) all_samples = np.concatenate(all_samples, axis=0) return all_samples if __name__ == '__main__': # save_path = '/scratch/hdd001/home/kamyar/expert_demos/data_gen/pusher_task_states_200_eps_correct.pkl' # save_path = '/scratch/hdd001/home/kamyar/expert_demos/data_gen/test.pkl' # pusher_points = pusher_to_obj_to_goal(200) # save_path = '/scratch/hdd001/home/kamyar/expert_demos/data_gen/pusher_task_states_no_inbetween.pkl' save_path = '/scratch/hdd001/home/kamyar/expert_demos/data_gen/corl_pusher_push_states.pkl' pusher_points = pusher_to_obj_to_goal_gaussian_target(200) # save_path = '/scratch/hdd001/home/kamyar/expert_demos/data_gen/with_gaussian_line_pusher_task_states_no_inbetween.pkl' # pusher_points = pusher_to_obj_to_goal_gaussian_target_with_gaussian_line(200) plot_scatter(pusher_points[:, 0], pusher_points[:, 1], 30, 'test', 'plots/data_gen/pusher_arm_x_y.png', [[-0.5, 1], [-1, 0.5]]) plot_scatter(pusher_points[:, 1], pusher_points[:, 2], 30, 'test', 'plots/data_gen/pusher_arm_y_z.png', [[-1, 0.5], [-0.5, 0.5]]) plot_scatter(pusher_points[:, 3], pusher_points[:, 4], 30, 'test', 'plots/data_gen/pusher_obj.png', [[-0.5, 1], [-1, 0.5]]) print(pusher_points.shape) joblib.dump({ 'data': pusher_points, }, save_path, compress=3)