real robot not working
这个提交包含在:
@ -159,6 +159,9 @@ CUDA_VISIBLE_DEVICES=1 python3 imitate_episodes.py \
|
|||||||
|
|
||||||
###### Diffusion Real ######
|
###### Diffusion Real ######
|
||||||
|
|
||||||
|
## deploy
|
||||||
|
python3 imitate_episodes.py --task_name aloha_mobile_wipe_wine --ckpt_dir /home/mobile-aloha/interbotix_ws/src/act/ckpts/wipe_wine_diffusion_augmentation_seed0/ --policy_class Diffusion --chunk_size 32 --batch_size 32 --lr 1e-4 --seed 0 --num_steps 1000000 --eval_every 1000000 --validate_every 5000 --save_every 5000 --eval
|
||||||
|
|
||||||
conda activate mobile
|
conda activate mobile
|
||||||
export MUJOCO_GL=egl
|
export MUJOCO_GL=egl
|
||||||
cd /home/tonyzhao/Research/act-plus-plus
|
cd /home/tonyzhao/Research/act-plus-plus
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import wandb
|
|||||||
import time
|
import time
|
||||||
import ray
|
import ray
|
||||||
from ray.util.queue import Queue
|
from ray.util.queue import Queue
|
||||||
|
from torchvision import transforms
|
||||||
|
|
||||||
from constants import FPS
|
from constants import FPS
|
||||||
from constants import PUPPET_GRIPPER_JOINT_OPEN
|
from constants import PUPPET_GRIPPER_JOINT_OPEN
|
||||||
@ -206,13 +207,25 @@ def make_optimizer(policy_class, policy):
|
|||||||
return optimizer
|
return optimizer
|
||||||
|
|
||||||
|
|
||||||
def get_image(ts, camera_names):
|
def get_image(ts, camera_names, rand_crop_resize=False):
|
||||||
curr_images = []
|
curr_images = []
|
||||||
for cam_name in camera_names:
|
for cam_name in camera_names:
|
||||||
curr_image = rearrange(ts.observation['images'][cam_name], 'h w c -> c h w')
|
curr_image = rearrange(ts.observation['images'][cam_name], 'h w c -> c h w')
|
||||||
curr_images.append(curr_image)
|
curr_images.append(curr_image)
|
||||||
curr_image = np.stack(curr_images, axis=0)
|
curr_image = np.stack(curr_images, axis=0)
|
||||||
curr_image = torch.from_numpy(curr_image / 255.0).float().unsqueeze(0)
|
curr_image = torch.from_numpy(curr_image / 255.0).float().unsqueeze(0)
|
||||||
|
|
||||||
|
if rand_crop_resize:
|
||||||
|
print('rand crop resize is used!')
|
||||||
|
original_size = curr_image.shape[-2:]
|
||||||
|
ratio = 0.95
|
||||||
|
curr_image = curr_image[..., int(original_size[0] * (1 - ratio) / 2): int(original_size[0] * (1 + ratio) / 2),
|
||||||
|
int(original_size[1] * (1 - ratio) / 2): int(original_size[1] * (1 + ratio) / 2)]
|
||||||
|
curr_image = curr_image.squeeze(0)
|
||||||
|
resize_transform = transforms.Resize(original_size, antialias=True)
|
||||||
|
curr_image = resize_transform(curr_image)
|
||||||
|
curr_image = curr_image.unsqueeze(0)
|
||||||
|
|
||||||
return curr_image
|
return curr_image
|
||||||
|
|
||||||
|
|
||||||
@ -329,7 +342,7 @@ def eval_bc(config, ckpt_name, save_episode=True, num_rollouts=50):
|
|||||||
query_frequency = 1
|
query_frequency = 1
|
||||||
num_queries = policy_config['num_queries']
|
num_queries = policy_config['num_queries']
|
||||||
if real_robot:
|
if real_robot:
|
||||||
BASE_DELAY = 15
|
BASE_DELAY = 13
|
||||||
query_frequency -= BASE_DELAY
|
query_frequency -= BASE_DELAY
|
||||||
|
|
||||||
max_timesteps = int(max_timesteps * 1) # may increase for real-world tasks
|
max_timesteps = int(max_timesteps * 1) # may increase for real-world tasks
|
||||||
@ -391,7 +404,7 @@ def eval_bc(config, ckpt_name, save_episode=True, num_rollouts=50):
|
|||||||
qpos = torch.from_numpy(qpos).float().unsqueeze(0)
|
qpos = torch.from_numpy(qpos).float().unsqueeze(0)
|
||||||
# qpos_history[:, t] = qpos
|
# qpos_history[:, t] = qpos
|
||||||
if t % query_frequency == 0:
|
if t % query_frequency == 0:
|
||||||
curr_image = get_image(ts, camera_names)
|
curr_image = get_image(ts, camera_names, rand_crop_resize=(config['policy_class'] == 'Diffusion'))
|
||||||
# print('get image: ', time.time() - time2)
|
# print('get image: ', time.time() - time2)
|
||||||
if not async_query:
|
if not async_query:
|
||||||
qpos = qpos.cuda()
|
qpos = qpos.cuda()
|
||||||
@ -451,7 +464,7 @@ def eval_bc(config, ckpt_name, save_episode=True, num_rollouts=50):
|
|||||||
# raw_action[0, -2:] = 0
|
# raw_action[0, -2:] = 0
|
||||||
elif config['policy_class'] == "Diffusion":
|
elif config['policy_class'] == "Diffusion":
|
||||||
if async_query:
|
if async_query:
|
||||||
freq_mult = 0.5
|
freq_mult = 0.8
|
||||||
if t == 0 or (t % int(query_frequency*freq_mult) == 0):
|
if t == 0 or (t % int(query_frequency*freq_mult) == 0):
|
||||||
print(f'{t}: Put')
|
print(f'{t}: Put')
|
||||||
input_queue.put({'qpos': qpos, 'obs': curr_image, 'query_wall_t': time.time(), 'query_t': t})
|
input_queue.put({'qpos': qpos, 'obs': curr_image, 'query_wall_t': time.time(), 'query_t': t})
|
||||||
@ -473,7 +486,9 @@ def eval_bc(config, ckpt_name, save_episode=True, num_rollouts=50):
|
|||||||
query_wall_t = res_dict['query_wall_t']
|
query_wall_t = res_dict['query_wall_t']
|
||||||
query_t = res_dict['query_t']
|
query_t = res_dict['query_t']
|
||||||
all_actions = res_dict['action']
|
all_actions = res_dict['action']
|
||||||
all_time_actions[query_t, query_t:query_t+num_queries] = all_actions
|
if real_robot:
|
||||||
|
all_actions = torch.cat([all_actions[:, :-BASE_DELAY, :-2], all_actions[:, BASE_DELAY:, -2:]], dim=2)
|
||||||
|
all_time_actions[query_t, query_t:query_t+len(all_actions)] = all_actions
|
||||||
|
|
||||||
all_time_curr_actions = all_time_actions[:, t]
|
all_time_curr_actions = all_time_actions[:, t]
|
||||||
has_action = all_time_curr_actions.any(dim=1)
|
has_action = all_time_curr_actions.any(dim=1)
|
||||||
@ -531,7 +546,9 @@ def eval_bc(config, ckpt_name, save_episode=True, num_rollouts=50):
|
|||||||
target_qpos_list.append(target_qpos)
|
target_qpos_list.append(target_qpos)
|
||||||
rewards.append(ts.reward)
|
rewards.append(ts.reward)
|
||||||
duration = time.time() - time1
|
duration = time.time() - time1
|
||||||
time.sleep(max(0, DT - duration))
|
sleep_time = max(0, DT - duration)
|
||||||
|
# print(sleep_time)
|
||||||
|
time.sleep(sleep_time)
|
||||||
# time.sleep(max(0, DT - duration - culmulated_delay))
|
# time.sleep(max(0, DT - duration - culmulated_delay))
|
||||||
if duration >= DT and real_robot:
|
if duration >= DT and real_robot:
|
||||||
culmulated_delay += (duration - DT)
|
culmulated_delay += (duration - DT)
|
||||||
@ -556,6 +573,7 @@ def eval_bc(config, ckpt_name, save_episode=True, num_rollouts=50):
|
|||||||
plt.xticks([])
|
plt.xticks([])
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
plt.savefig(os.path.join(ckpt_dir, f'qpos_{log_id}.png'))
|
plt.savefig(os.path.join(ckpt_dir, f'qpos_{log_id}.png'))
|
||||||
|
plt.close()
|
||||||
|
|
||||||
|
|
||||||
rewards = np.array(rewards)
|
rewards = np.array(rewards)
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户