From 2357756572a03066b0ee2f58dba08252b0d1577c Mon Sep 17 00:00:00 2001 From: mtrang Date: Thu, 29 Jun 2023 15:35:27 -0400 Subject: [PATCH] initial notebook for running a single OVMM agent --- projects/habitat_ovmm/eval_episode.ipynb | 203 +++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 projects/habitat_ovmm/eval_episode.ipynb diff --git a/projects/habitat_ovmm/eval_episode.ipynb b/projects/habitat_ovmm/eval_episode.ipynb new file mode 100644 index 000000000..aa2d0fd43 --- /dev/null +++ b/projects/habitat_ovmm/eval_episode.ipynb @@ -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 +}