Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions reference/RoboVLMs/eval/libero/evaluate_libero_emu.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ def parser_args():
],
help="select evaluate LIBREO TASK SUITE",
)
parser.add_argument("--norm_stats_path", type=str, default=None,
help="Path to the normalization statistics JSON file. If not provided, will use default path relative to project root.")
parser.add_argument("--device_id", default=0, type=int, help="CUDA device")
parser.add_argument("--no_cache", action="store_true")
parser.add_argument("--debug_model", action="store_true")
Expand Down Expand Up @@ -324,6 +326,7 @@ def main():
vq_hub=args.vq_hub,
vision_hub=args.vision_hub,
device=torch.device("cuda"),
norm_stats_path=args.norm_stats_path,
)

sr_path = os.path.join(eval_log_dir, f"success_rate_calvin.txt")
Expand Down
50 changes: 30 additions & 20 deletions reference/RoboVLMs/eval/libero/model_wrapper_emu.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def __init__(
emu_hub,
vq_hub,
vision_hub,
device
device,
norm_stats_path=None
):

self.emu_hub = emu_hub
Expand All @@ -60,6 +61,10 @@ def __init__(
self.use_cot = False # always disable CoT

self.video_mode = False

# Load normalization statistics from config file
self.norm_stats_path = norm_stats_path
self.load_norm_stats()

# load model and tokenizer
self.init_config(device=device)
Expand Down Expand Up @@ -87,6 +92,28 @@ def __init__(
temperature=0.8,
)

def load_norm_stats(self):
"""Load normalization statistics from config file"""
# Use relative path if no path is provided
if self.norm_stats_path is None:
# Assume the script is in reference/RoboVLMs/eval/libero/
# The norm_stats.json is in configs/normalizer_libero/ relative to project root
import os
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
self.norm_stats_path = os.path.join(
project_root,
"configs",
"normalizer_libero",
"norm_stats.json"
)

with open(self.norm_stats_path, 'r') as f:
norm_stats = json.load(f)

# Extract q01 (lower bound) and q99 (upper bound) for libero
self.action_low = np.array(norm_stats['norm_stats']['libero']['q01'])
self.action_high = np.array(norm_stats['norm_stats']['libero']['q99'])

def init_config(self, device):

self.model = Emu3MoE.from_pretrained(
Expand Down Expand Up @@ -299,23 +326,6 @@ def step(self, image, goal):
return action_pred

def unormalize_action(self, action):
action_high = np.array([
0.93712500009996,
0.86775000009256,
0.93712500009996,
0.13175314309916836,
0.19275000005139997,
0.3353504997073735,
0.9996000000999599
])
action_low = np.array([
-0.7046250000751599,
-0.80100000008544,
-0.9375000001,
-0.11467779149968735,
-0.16395000004372,
-0.2240490058320433,
-1.0000000001
])
action = 0.5 * (action + 1) * (action_high - action_low) + action_low
"""Unnormalize actions using the loaded normalization statistics"""
action = 0.5 * (action + 1) * (self.action_high - self.action_low) + self.action_low
return action