fixed env eval setup

This commit is contained in:
2026-07-31 18:35:09 +02:00
parent a3e46c3abf
commit 5317ef1299
5 changed files with 105 additions and 72 deletions
+5 -30
View File
@@ -13,7 +13,7 @@ def evaluate(
model_path: str,
episodes: int = 5,
use_gui: bool = True,
num_robots: int = 1,
num_robots: int = 16, # Default to 16 to match your trained (352,) observation space
robot_spacing: float = 0.5,
start_pose: str = "init_deg",
random_command: bool = True,
@@ -29,9 +29,10 @@ def evaluate(
from .env import JackBotEnv
print(f"[Eval] Loading policy model from: {model_path}")
model = PPO.load(model_path)
# Force device="cpu" to prevent AMD ROCm/hipBLASLt matrix multiplication crashes
model = PPO.load(model_path, device="cpu")
# Initialize environment with active command sampling so robot actually walks
# Initialize standard environment (returns single array of shape (352,))
env = JackBotEnv(
use_gui=use_gui,
random_command=random_command,
@@ -52,7 +53,6 @@ def evaluate(
print(f"\n--- Starting Evaluation Episode {ep + 1}/{episodes} ---")
while not done:
# Deterministic evaluation (no exploration noise)
action, _ = model.predict(obs, deterministic=True)
obs, reward, terminated, truncated, _ = env.step(action)
@@ -60,7 +60,6 @@ def evaluate(
total_reward += float(reward)
steps += 1
# Give PyBullet GUI frame pacing if running visually
if use_gui:
time.sleep(1.0 / 240.0)
@@ -70,7 +69,6 @@ def evaluate(
env.close()
# Calculate summary statistics
metrics = {
"model_path": str(model_path),
"episodes_evaluated": episodes,
@@ -87,7 +85,6 @@ def evaluate(
print(f"Mean Episode Length: {metrics['mean_episode_length']:.1f} steps")
print("=" * 50)
# Optional JSON metrics export
if save_json:
out_path = Path(save_json)
out_path.parent.mkdir(parents=True, exist_ok=True)
@@ -95,26 +92,4 @@ def evaluate(
json.dump(metrics, f, indent=4)
print(f"[Eval] Saved evaluation metrics to: {out_path.resolve()}")
return metrics
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Evaluate a trained JackBot policy.")
parser.add_argument("--model-path", type=str, required=True, help="Path to trained PPO model zip")
parser.add_argument("--episodes", type=int, default=5, help="Number of evaluation rounds")
parser.add_argument("--gui", action="store_true", help="Render GUI simulation")
parser.add_argument("--num-robots", type=int, default=1, help="Number of robots in sim")
parser.add_argument("--robot-spacing", type=float, default=0.5, help="Spacing between robots in meters")
parser.add_argument("--start-pose", type=str, choices=["init_deg", "init90_deg"], default="init_deg")
parser.add_argument("--save-json", type=str, default=None, help="Optional output JSON path for metrics")
args = parser.parse_args()
evaluate(
model_path=args.model_path,
episodes=args.episodes,
use_gui=args.gui,
num_robots=args.num_robots,
robot_spacing=args.robot_spacing,
start_pose=args.start_pose,
save_json=args.save_json,
)
return metrics