diff --git a/.gitignore b/.gitignore index 673af7ec..be96fe1a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ outputs/* /MUJOCO_LOG.TXT wandb experiments/ +experiments_saved/ clip/ gpt/ bert/ @@ -14,3 +15,4 @@ logs/ *.mp4 libero.egg-info/ +.vscode/ diff --git a/README.md b/README.md index 2ef7a1dd..f17c9fb6 100644 --- a/README.md +++ b/README.md @@ -36,14 +36,15 @@ https://github.com/Lifelong-Robot-Learning/LIBERO/assets/8097542/cbb1522f-0831-4 Please run the following commands in the given order to install the dependency for **LIBERO**. ``` conda create -n libero python=3.8.13 +conda activate libero +git clone https://github.com/Lifelong-Robot-Learning/LIBERO.git +cd LIBERO pip install -r requirements.txt pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113 ``` Then install the `libero` package: ``` -git clone https://github.com/Lifelong-Robot-Learning/LIBERO.git -cd LIBERO pip install -e . ``` @@ -116,7 +117,7 @@ then run the following: export CUDA_VISIBLE_DEVICES=GPU_ID && \ export MUJOCO_EGL_DEVICE_ID=GPU_ID && \ python libero/lifelong/main.py seed=SEED \ - benchmark_name=BENCHMARK + benchmark_name=BENCHMARK \ policy=POLICY \ lifelong=ALGO ``` @@ -131,7 +132,10 @@ python libero/lifelong/evaluate.py --benchmark BENCHMARK_NAME \ --task_id TASK_ID \ --algo ALGO_NAME \ --policy POLICY_NAME \ - --seed SEED + --seed SEED \ + --ep EPOCH \ + --load_task LOAD_TASK \ + --device_id CUDA_ID ``` # Citation diff --git a/libero/libero/__init__.py b/libero/libero/__init__.py index ded48f05..426ccc5c 100644 --- a/libero/libero/__init__.py +++ b/libero/libero/__init__.py @@ -8,8 +8,11 @@ config_file = os.path.join(libero_config_path, "config.yaml") -def get_default_path_dict(): - benchmark_root_path = os.path.dirname(os.path.abspath(__file__)) +def get_default_path_dict(custom_location=None): + if custom_location is None: + benchmark_root_path = os.path.dirname(os.path.abspath(__file__)) + else: + benchmark_root_path = custom_location # This is a default path for localizing all the default bddl files bddl_files_default_path = os.path.join(benchmark_root_path, "./bddl_files") diff --git a/libero/lifelong/evaluate.py b/libero/lifelong/evaluate.py index 7a59890c..d4db4dd9 100644 --- a/libero/lifelong/evaluate.py +++ b/libero/lifelong/evaluate.py @@ -167,7 +167,7 @@ def main(): if cfg.lifelong.algo == "PackNet": algo.eval() for module_idx, module in enumerate(algo.policy.modules()): - if isinstance(module, nn.Conv2d) or isinstance(module, nn.Linear): + if isinstance(module, torch.nn.Conv2d) or isinstance(module, torch.nn.Linear): weight = module.weight.data mask = algo.previous_masks[module_idx].to(cfg.device) weight[mask.eq(0)] = 0.0 diff --git a/notebooks/quick_walkthrough.ipynb b/notebooks/quick_walkthrough.ipynb index d6c88071..b5752491 100644 --- a/notebooks/quick_walkthrough.ipynb +++ b/notebooks/quick_walkthrough.ipynb @@ -21,9 +21,18 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/zuxin/anaconda3/envs/libero/lib/python3.8/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n" + ] + } + ], "source": [ - "from libero.libero import benchmark, get_libero_path, set_libero_path\n", + "from libero.libero import benchmark, get_libero_path, set_libero_default_path\n", "import os\n", "from termcolor import colored" ] @@ -53,9 +62,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "Default benchmark root path: /home/yifengz/workspace/libero-dev/libero/libero\n", - "Default dataset root path: /home/yifengz/workspace/libero-dev/libero/libero/../datasets\n", - "Default bddl files root path: /home/yifengz/workspace/libero-dev/libero/libero/./bddl_files\n" + "Default benchmark root path: /home/zuxin/repo/LIBERO/libero/libero\n", + "Default dataset root path: /home/zuxin/repo/LIBERO/libero/libero/../datasets\n", + "Default bddl files root path: /home/zuxin/repo/LIBERO/libero/libero/./bddl_files\n" ] } ], @@ -79,21 +88,46 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Default benchmark root path: /home/yifengz/custom_project\n", - "Default dataset root path: /home/yifengz/custom_project/../datasets\n", - "Default bddl files root path: /home/yifengz/custom_project/./bddl_files\n" + "[Warning] You are changing the default path for Libero config. This will affect all the paths in the config file.\n", + "[Warning]: assets path /home/zuxin/custom_project/./assets does not exist!\n", + "[Warning]: bddl_files path /home/zuxin/custom_project/./bddl_files does not exist!\n", + "[Warning]: benchmark_root path /home/zuxin/custom_project does not exist!\n", + "[Warning]: datasets path /home/zuxin/custom_project/../datasets does not exist!\n", + "[Warning]: init_states path /home/zuxin/custom_project/./init_files does not exist!\n", + "[Warning]: assets path /home/zuxin/custom_project/./assets does not exist!\n", + "[Warning]: bddl_files path /home/zuxin/custom_project/./bddl_files does not exist!\n", + "[Warning]: benchmark_root path /home/zuxin/custom_project does not exist!\n", + "[Warning]: datasets path /home/zuxin/custom_project/../datasets does not exist!\n", + "[Warning]: init_states path /home/zuxin/custom_project/./init_files does not exist!\n", + "[Warning]: assets path /home/zuxin/custom_project/./assets does not exist!\n", + "[Warning]: bddl_files path /home/zuxin/custom_project/./bddl_files does not exist!\n", + "[Warning]: benchmark_root path /home/zuxin/custom_project does not exist!\n", + "[Warning]: datasets path /home/zuxin/custom_project/../datasets does not exist!\n", + "[Warning]: init_states path /home/zuxin/custom_project/./init_files does not exist!\n", + "[Warning]: assets path /home/zuxin/custom_project/./assets does not exist!\n", + "[Warning]: bddl_files path /home/zuxin/custom_project/./bddl_files does not exist!\n", + "[Warning]: benchmark_root path /home/zuxin/custom_project does not exist!\n", + "[Warning]: datasets path /home/zuxin/custom_project/../datasets does not exist!\n", + "[Warning]: init_states path /home/zuxin/custom_project/./init_files does not exist!\n", + "Default benchmark root path: /home/zuxin/custom_project\n", + "Default dataset root path: /home/zuxin/custom_project/../datasets\n", + "Default bddl files root path: /home/zuxin/custom_project/./bddl_files\n", + "[Warning] You are changing the default path for Libero config. This will affect all the paths in the config file.\n", + "Default benchmark root path: /home/zuxin/repo/LIBERO/libero/libero\n", + "Default dataset root path: /home/zuxin/repo/LIBERO/libero/libero/../datasets\n", + "Default bddl files root path: /home/zuxin/repo/LIBERO/libero/libero/./bddl_files\n" ] } ], "source": [ - "set_libero_path(os.path.join(os.path.expanduser(\"~\"), \"custom_project\"))\n", + "set_libero_default_path(os.path.join(os.path.expanduser(\"~\"), \"custom_project\"))\n", "benchmark_root_path = get_libero_path(\"benchmark_root\")\n", "init_states_default_path = get_libero_path(\"init_states\")\n", "datasets_default_path = get_libero_path(\"datasets\")\n", @@ -102,13 +136,16 @@ "print(\"Default dataset root path: \", datasets_default_path)\n", "print(\"Default bddl files root path: \", bddl_files_default_path)\n", "\n", - "# If nothing is specified in the `set_libero_path` function, the path will be changed back to the default path\n", + "# If nothing is specified in the `set_libero_default_path` function, the path will be changed back to the default path\n", "# We will set back the path to the default path for the subsequent examples\n", - "set_libero_path()\n", + "set_libero_default_path()\n", "benchmark_root_path = get_libero_path(\"benchmark_root\")\n", "init_states_default_path = get_libero_path(\"init_states\")\n", "datasets_default_path = get_libero_path(\"datasets\")\n", - "bddl_files_default_path = get_libero_path(\"bddl_files\")" + "bddl_files_default_path = get_libero_path(\"bddl_files\")\n", + "print(\"Default benchmark root path: \", benchmark_root_path)\n", + "print(\"Default dataset root path: \", datasets_default_path)\n", + "print(\"Default bddl files root path: \", bddl_files_default_path)" ] }, { @@ -129,7 +166,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -155,7 +192,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -165,16 +202,16 @@ "[info] using task orders [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n", "10 tasks in the benchmark libero_10: \n", "The benchmark contains the following tasks:\n", - "\t LIVING_ROOM_SCENE2_put_both_the_alphabet_soup_and_the_tomato_sauce_in_the_basket, detail definition stored in /home/yifengz/workspace/libero-dev/libero/libero/./bddl_files/libero_10/LIVING_ROOM_SCENE2_put_both_the_alphabet_soup_and_the_tomato_sauce_in_the_basket.bddl\n", - "\t LIVING_ROOM_SCENE2_put_both_the_cream_cheese_box_and_the_butter_in_the_basket, detail definition stored in /home/yifengz/workspace/libero-dev/libero/libero/./bddl_files/libero_10/LIVING_ROOM_SCENE2_put_both_the_cream_cheese_box_and_the_butter_in_the_basket.bddl\n", - "\t KITCHEN_SCENE3_turn_on_the_stove_and_put_the_moka_pot_on_it, detail definition stored in /home/yifengz/workspace/libero-dev/libero/libero/./bddl_files/libero_10/KITCHEN_SCENE3_turn_on_the_stove_and_put_the_moka_pot_on_it.bddl\n", - "\t KITCHEN_SCENE4_put_the_black_bowl_in_the_bottom_drawer_of_the_cabinet_and_close_it, detail definition stored in /home/yifengz/workspace/libero-dev/libero/libero/./bddl_files/libero_10/KITCHEN_SCENE4_put_the_black_bowl_in_the_bottom_drawer_of_the_cabinet_and_close_it.bddl\n", - "\t LIVING_ROOM_SCENE5_put_the_white_mug_on_the_left_plate_and_put_the_yellow_and_white_mug_on_the_right_plate, detail definition stored in /home/yifengz/workspace/libero-dev/libero/libero/./bddl_files/libero_10/LIVING_ROOM_SCENE5_put_the_white_mug_on_the_left_plate_and_put_the_yellow_and_white_mug_on_the_right_plate.bddl\n", - "\t STUDY_SCENE1_pick_up_the_book_and_place_it_in_the_back_compartment_of_the_caddy, detail definition stored in /home/yifengz/workspace/libero-dev/libero/libero/./bddl_files/libero_10/STUDY_SCENE1_pick_up_the_book_and_place_it_in_the_back_compartment_of_the_caddy.bddl\n", - "\t LIVING_ROOM_SCENE6_put_the_white_mug_on_the_plate_and_put_the_chocolate_pudding_to_the_right_of_the_plate, detail definition stored in /home/yifengz/workspace/libero-dev/libero/libero/./bddl_files/libero_10/LIVING_ROOM_SCENE6_put_the_white_mug_on_the_plate_and_put_the_chocolate_pudding_to_the_right_of_the_plate.bddl\n", - "\t LIVING_ROOM_SCENE1_put_both_the_alphabet_soup_and_the_cream_cheese_box_in_the_basket, detail definition stored in /home/yifengz/workspace/libero-dev/libero/libero/./bddl_files/libero_10/LIVING_ROOM_SCENE1_put_both_the_alphabet_soup_and_the_cream_cheese_box_in_the_basket.bddl\n", - "\t KITCHEN_SCENE8_put_both_moka_pots_on_the_stove, detail definition stored in /home/yifengz/workspace/libero-dev/libero/libero/./bddl_files/libero_10/KITCHEN_SCENE8_put_both_moka_pots_on_the_stove.bddl\n", - "\t KITCHEN_SCENE6_put_the_yellow_and_white_mug_in_the_microwave_and_close_it, detail definition stored in /home/yifengz/workspace/libero-dev/libero/libero/./bddl_files/libero_10/KITCHEN_SCENE6_put_the_yellow_and_white_mug_in_the_microwave_and_close_it.bddl\n" + "\t LIVING_ROOM_SCENE2_put_both_the_alphabet_soup_and_the_tomato_sauce_in_the_basket, detail definition stored in /home/zuxin/repo/LIBERO/libero/libero/./bddl_files/libero_10/LIVING_ROOM_SCENE2_put_both_the_alphabet_soup_and_the_tomato_sauce_in_the_basket.bddl\n", + "\t LIVING_ROOM_SCENE2_put_both_the_cream_cheese_box_and_the_butter_in_the_basket, detail definition stored in /home/zuxin/repo/LIBERO/libero/libero/./bddl_files/libero_10/LIVING_ROOM_SCENE2_put_both_the_cream_cheese_box_and_the_butter_in_the_basket.bddl\n", + "\t KITCHEN_SCENE3_turn_on_the_stove_and_put_the_moka_pot_on_it, detail definition stored in /home/zuxin/repo/LIBERO/libero/libero/./bddl_files/libero_10/KITCHEN_SCENE3_turn_on_the_stove_and_put_the_moka_pot_on_it.bddl\n", + "\t KITCHEN_SCENE4_put_the_black_bowl_in_the_bottom_drawer_of_the_cabinet_and_close_it, detail definition stored in /home/zuxin/repo/LIBERO/libero/libero/./bddl_files/libero_10/KITCHEN_SCENE4_put_the_black_bowl_in_the_bottom_drawer_of_the_cabinet_and_close_it.bddl\n", + "\t LIVING_ROOM_SCENE5_put_the_white_mug_on_the_left_plate_and_put_the_yellow_and_white_mug_on_the_right_plate, detail definition stored in /home/zuxin/repo/LIBERO/libero/libero/./bddl_files/libero_10/LIVING_ROOM_SCENE5_put_the_white_mug_on_the_left_plate_and_put_the_yellow_and_white_mug_on_the_right_plate.bddl\n", + "\t STUDY_SCENE1_pick_up_the_book_and_place_it_in_the_back_compartment_of_the_caddy, detail definition stored in /home/zuxin/repo/LIBERO/libero/libero/./bddl_files/libero_10/STUDY_SCENE1_pick_up_the_book_and_place_it_in_the_back_compartment_of_the_caddy.bddl\n", + "\t LIVING_ROOM_SCENE6_put_the_white_mug_on_the_plate_and_put_the_chocolate_pudding_to_the_right_of_the_plate, detail definition stored in /home/zuxin/repo/LIBERO/libero/libero/./bddl_files/libero_10/LIVING_ROOM_SCENE6_put_the_white_mug_on_the_plate_and_put_the_chocolate_pudding_to_the_right_of_the_plate.bddl\n", + "\t LIVING_ROOM_SCENE1_put_both_the_alphabet_soup_and_the_cream_cheese_box_in_the_basket, detail definition stored in /home/zuxin/repo/LIBERO/libero/libero/./bddl_files/libero_10/LIVING_ROOM_SCENE1_put_both_the_alphabet_soup_and_the_cream_cheese_box_in_the_basket.bddl\n", + "\t KITCHEN_SCENE8_put_both_moka_pots_on_the_stove, detail definition stored in /home/zuxin/repo/LIBERO/libero/libero/./bddl_files/libero_10/KITCHEN_SCENE8_put_both_moka_pots_on_the_stove.bddl\n", + "\t KITCHEN_SCENE6_put_the_yellow_and_white_mug_in_the_microwave_and_close_it, detail definition stored in /home/zuxin/repo/LIBERO/libero/libero/./bddl_files/libero_10/KITCHEN_SCENE6_put_the_yellow_and_white_mug_in_the_microwave_and_close_it.bddl\n" ] } ], @@ -207,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -255,9 +292,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[1m\u001b[33m[robosuite WARNING] \u001b[0mNo private macro file found! (__init__.py:7)\n", - "\u001b[1m\u001b[33m[robosuite WARNING] \u001b[0mIt is recommended to use a private macro file (__init__.py:8)\n", - "\u001b[1m\u001b[33m[robosuite WARNING] \u001b[0mTo setup, run: python /home/yifengz/workspace/robosuite-master/robosuite/scripts/setup_macros.py (__init__.py:9)\n" + "[robosuite WARNING] No private macro file found! (__init__.py:7)\n", + "[robosuite WARNING] It is recommended to use a private macro file (__init__.py:8)\n", + "[robosuite WARNING] To setup, run: python /home/zuxin/anaconda3/envs/libero/lib/python3.8/site-packages/robosuite/scripts/setup_macros.py (__init__.py:9)\n" ] }, { @@ -328,18 +365,26 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\u001b[1m\u001b[32m[X] Dataset libero_object is complete\u001b[0m\n", - "\u001b[1m\u001b[32m[X] Dataset libero_goal is complete\u001b[0m\n", - "\u001b[1m\u001b[32m[X] Dataset libero_spatial is complete\u001b[0m\n", - "\u001b[1m\u001b[32m[X] Dataset libero_10 is complete\u001b[0m\n", - "\u001b[1m\u001b[32m[X] Dataset libero_90 is complete\u001b[0m\n" + "[ ] Dataset libero_object not found!!!\n", + "[ ] Dataset libero_goal not found!!!\n", + "[X] Dataset libero_spatial is complete\n", + "[X] Dataset libero_10 is complete\n", + "[X] Dataset libero_90 is complete\n", + "Downloading libero_spatial\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "04k94hyizn4huhbv5sz4ev9p2h1p6s7f.zip: 2.88GB [02:56, 16.3MB/s] \n" ] } ], @@ -371,7 +416,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -1178,7 +1223,7 @@ "" ] }, - "execution_count": 11, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -1222,7 +1267,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -1231,14 +1276,6 @@ "text": [ "Number of tasks in the benchmark libero_10: 10\n" ] - }, - { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31mThe Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click here for more info. View Jupyter log for further details." - ] } ], "source": [ @@ -1279,9 +1316,11 @@ } ], "metadata": { + "interpreter": { + "hash": "64fd624917382b0c0ee6e40067ed4768d5d5501e9a56437104405cabbecfa898" + }, "kernelspec": { - "display_name": "new-continual-learning", - "language": "python", + "display_name": "Python 3.8.13 64-bit ('libero': conda)", "name": "python3" }, "language_info": { @@ -1294,7 +1333,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.5" + "version": "3.8.13" }, "orig_nbformat": 4 }, diff --git a/test.py b/test.py new file mode 100644 index 00000000..25c08d27 --- /dev/null +++ b/test.py @@ -0,0 +1,36 @@ +import os + +from libero.libero import benchmark +from libero.libero.envs import OffScreenRenderEnv + + +benchmark_dict = benchmark.get_benchmark_dict() +task_suite_name = "libero_10" # can also choose libero_spatial, libero_object, etc. +task_suite = benchmark_dict[task_suite_name]() + +# retrieve a specific task +task_id = 0 +task = task_suite.get_task(task_id) +task_name = task.name +task_description = task.language +task_bddl_file = os.path.join(benchmark.get_libero_path("bddl_files"), task.problem_folder, task.bddl_file) +print(f"[info] retrieving task {task_id} from suite {task_suite_name}, the " + \ + f"language instruction is {task_description}, and the bddl file is {task_bddl_file}") + +# step over the environment +env_args = { + "bddl_file_name": task_bddl_file, + "camera_heights": 128, + "camera_widths": 128 +} +env = OffScreenRenderEnv(**env_args) +env.seed(0) +env.reset() +init_states = task_suite.get_task_init_states(task_id) # for benchmarking purpose, we fix the a set of initial states +init_state_id = 0 +env.set_init_state(init_states[init_state_id]) + +dummy_action = [0.] * 7 +for step in range(10): + obs, reward, done, info = env.step(dummy_action) +env.close() \ No newline at end of file