Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial notebook for running a single OVMM agent #260

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
203 changes: 203 additions & 0 deletions projects/habitat_ovmm/eval_episode.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Imports"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# home-robot imports\n",
"import argparse\n",
"import json\n",
"import os\n",
"import sys\n",
"import time\n",
"from collections import defaultdict\n",
"from pathlib import Path\n",
"\n",
"import numpy as np\n",
"from config_utils import get_config\n",
"from omegaconf import DictConfig, OmegaConf\n",
"\n",
"\n",
"from habitat import make_dataset\n",
"from habitat.core.environments import get_env_class\n",
"from habitat.core.vector_env import VectorEnv\n",
"from habitat.core.env import Env\n",
"from habitat.utils.gym_definitions import _get_env_name\n",
"from habitat_baselines.rl.ppo.ppo_trainer import PPOTrainer\n",
"\n",
"from home_robot.agent.ovmm_agent.ovmm_agent import OpenVocabManipAgent\n",
"from home_robot_sim.env.habitat_ovmm_env.habitat_ovmm_env import (\n",
" HabitatOpenVocabManipEnv,\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"All code should be ran from the root home-robot directory"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"os.chdir(\"../..\") # change directory to $HOME_ROBOT_ROOT\n",
"#os.chdir(os.environ['HOME_ROBOT_ROOT'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pwd"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Setup config "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"config_path = \"ovmm/ovmm_eval.yaml\"\n",
"config, config_str = get_config(config_path)\n",
"OmegaConf.set_readonly(config, False)\n",
"\n",
"config.habitat_baselines.num_environments = 1\n",
"OmegaConf.set_struct(config.habitat_baselines, False)\n",
"config.habitat_baselines.print_images = 1\n",
"config.habitat.dataset.split = \"val\"\n",
"config.habitat_baselines.exp_name = \"debug_notebook\"\n",
"\n",
"OmegaConf.set_readonly(config, True)\n",
"baseline_config = OmegaConf.load(\n",
" \"projects/habitat_ovmm/configs/agent/hssd_eval.yaml\"\n",
")\n",
"config = DictConfig({**config, **baseline_config})\n",
"config.VISUALIZE = 1\n",
"print(config)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"habitat_config = config.habitat\n",
"dataset = make_dataset(habitat_config.dataset.type, config=habitat_config.dataset)\n",
"env_class_name = _get_env_name(config)\n",
"env_class = get_env_class(env_class_name)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Create the agent and environment"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"agent = OpenVocabManipAgent(config=config)\n",
"\n",
"habitat_env = env_class(config=habitat_config, dataset=dataset) # TODO: This line stalls on first execution. \n",
" # current workaround is to interrupt after a few seconds and rerun\n",
"habitat_env.seed(habitat_config.seed)\n",
"env = HabitatOpenVocabManipEnv(habitat_env, config, dataset=dataset)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t = 0\n",
"env.reset()\n",
"agent.reset()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t += 1\n",
"obs = env.get_observation()\n",
"action, info, act_obs = agent.act(obs)\n",
"print(t, action)\n",
"env.apply_action(action, info)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Step all the way\n",
"#while not env.episode_over:\n",
"for _ in range(100):\n",
" t += 1\n",
" obs = env.get_observation()\n",
" action, info, act_obs = agent.act(obs)\n",
" print(t, action)\n",
" env.apply_action(action, info)\n",
"\n",
"print(env.get_episode_metrics())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}