{"id":19184225,"url":"https://github.com/princeton-vl/packit","last_synced_at":"2025-05-08T00:03:54.183Z","repository":{"id":39725767,"uuid":"274701676","full_name":"princeton-vl/PackIt","owner":"princeton-vl","description":"Code for reproducing results in ICML 2020 paper \"PackIt: A Virtual Environment for Geometric Planning\"","archived":false,"fork":false,"pushed_at":"2024-12-12T21:50:05.000Z","size":6406,"stargazers_count":52,"open_issues_count":4,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-20T05:32:07.735Z","etag":null,"topics":["computer-vision","icml-2020","open-ai-gym","unity-ml-agents","virtual-environments"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/princeton-vl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-06-24T15:18:35.000Z","updated_at":"2024-12-12T21:50:10.000Z","dependencies_parsed_at":"2024-12-12T22:39:56.481Z","dependency_job_id":null,"html_url":"https://github.com/princeton-vl/PackIt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princeton-vl%2FPackIt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princeton-vl%2FPackIt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princeton-vl%2FPackIt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princeton-vl%2FPackIt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/princeton-vl","download_url":"https://codeload.github.com/princeton-vl/PackIt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252973678,"owners_count":21834107,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","icml-2020","open-ai-gym","unity-ml-agents","virtual-environments"],"created_at":"2024-11-09T11:06:46.931Z","updated_at":"2025-05-08T00:03:54.110Z","avatar_url":"https://github.com/princeton-vl.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"images/packit.gif\" align=\"right\" width=\"30%\"/\u003e\n\n[**PackIt: A Virtual Environment for Geometric Planning**](http://arxiv.org/abs/2007.11121)   \n[Ankit Goyal](http://imankgoyal.github.io), [Jia Deng](https://www.cs.princeton.edu/~jiadeng/)  \n*International Conference on Machine Learning (ICML), 2020*\n\n## Getting Started\n\nFirst clone the repository. We would refer to the directory containing the code as `\u003cpackit_dir\u003e`.\n\n```\ngit clone git@github.com:princeton-vl/PackIt.git\n```\n\n#### Requirements\nThe PackIt environment is build using [Unity ML-agents](https://github.com/Unity-Technologies/ml-agents/tree/0.4.0) version **0.4.0**. \nTo train the neural network model, we recommend using a machine with GPU. \nThe code is tested on Linux OS with Python version **3.5**, CUDA version **8.0**, and cuDNN version **5.1**.\nWe provide standlone [Unity builds for Linux x86_64 platform](https://docs.unity3d.com/2017.4/Documentation/Manual/BuildSettingsStandalone.html).\nFor visualization, we also provide a Unity build for Mac OS.\n\n#### Install Libraries\nWe recommend to first install [Anaconda](https://anaconda.org/) and create a virtual environment.\n```\nconda create --name packit python=3.5\n```\n\nActivate the virtual environment and install the libraries. Make sure you are in `\u003cpackit_dir\u003e`.\n```\nconda activate packit\npip install -r requirements.txt\n```\n\n#### Download Datasets and Pre-trained Models\nMake sure you are in `\u003cpackit_dir\u003e`. `download.sh` script downloads all the data, unzips them, and places them at correct locations. Note that symbolic links are created between the `data` folder and appropriate locations inside the unity data directory. This is necessary so that the data is accessible from the build unity game.\n```\nchmod +x download.sh\n./download.sh\n```\n\n## Code Organization\n- `\u003cpackit_dir\u003e/main.py`: Python script for training and evaluating learning based-models on PackIt and PackIt-Easy. \n\n- `\u003cpackit_dir\u003e/main_heuristic.py`: Python script for training and evaluating heuritic-based models on PackIt and PackIt-Easy. \n\n- `\u003cpackit_dir\u003e/stable-baselines`: Adapted from [stable-baselines](https://github.com/hill-a/stable-baselines) with some modification. We use it for our PPO baselines. \n\n- `\u003cpackit_dir\u003e/unity`: Adapted from [Unity ML-agents](https://github.com/Unity-Technologies/ml-agents/tree/0.4.0) with minor modification. It is required to run the PackIt environment. It communicates with the game built using Unity using sockets and provides a python interface for interacting with the environment.\n\n- `\u003cpackit_dir\u003e/packing`: Contains code for creating and evaluating OpenAI gym compatible PackIt environment as well as various baselines.\n\n- `\u003cpackit_dir\u003e/log`: Created after `download.sh` is run. Stores the pretrained learning-based models according to the naming convention [here](https://github.com/princeton-vl/PackIt/blob/master/main.py#L81).  \n\n- `\u003cpackit_dir\u003e/unity/envs`: Created after `download.sh` is run. Stores the unity game build. `\u003cpackit_dir\u003e/unity/envs/packit.x86_64` is game build for the main unity environment while `\u003cpackit_dir\u003e/unity/envs/packit.x86_64` is the game build for the visualization environment.\n\n- `\u003cpackit_dir\u003e/data`: Created after `download.sh` is executed. Contains information about the shapes and packs. This folder is symbolically linked to `\u003cpackit_dir\u003e/unity/envs/packit_Data/StreamingAssets` and `\u003cpackit_dir\u003e/unity/envs/packit_viz_Data/StreamingAssets` so that it can be accessed by the unity game build. More information about StreamingAssets in Unity can be found [here](https://docs.unity3d.com/2017.4/Documentation/Manual/StreamingAssets.html).\n\n- `\u003cpackit_dir\u003e/data/data_\u003ctr/va/te\u003e`: Contains the shapenet shapes as [asset bundles](https://docs.unity3d.com/Manual/AssetBundlesIntro.html). This helps in faster loading for data.\n\n- `\u003cpackit_dir\u003e/data/pack_\u003cab/te/tr/va\u003e`: Contains information about packs in json format. Each file (like `\u003cpackit_dir\u003e/data/pack_tr/0_tr`) can have information about multiple packs. We refer to the order of the pack inside this file as its `id`. On average, each file has information about 5 packs.\n\n- `\u003cpackit_dir\u003e/data/pack_\u003cab/te/tr/va\u003e_precompute_\u003cpython/unity\u003e`: Contains information about packs so that they can be loaded faster. We precompute things like voxel representation of shapes and store here.\n\n- `\u003cpackit_dir\u003e/data/visualize`: Contains some saved actions for different baselines. These can be used during visualization. For more information refer to the visualization section.\n\n- `\u003cpackit_dir\u003e/results`: Created after `download.sh` is executed. It contains the reward of various agents. Once an agent is evaluated, a pickle file with rewards is saved here based on the naming [here](https://github.com/princeton-vl/PackIt/blob/master/main.py#L185) and [here](https://github.com/princeton-vl/PackIt/blob/master/main_heuristic.py#L105). We also provide precomputed rewards for our agents. Change [this](https://github.com/princeton-vl/PackIt/blob/master/results.py#L30) line to the result you want to see and run `python results.py`.\n \n## Testing\nTo debug whether everything is set up correctly, use the `test_packing_env.ipynb` jupyter notebook. It runs a packing environment with ground-truth actions.  Make sure you have downloaded everything properly before this step. Note that the plotting of voxels in matplotlib is slow. \n\n\n## Running Experiments\nTo run any experiment, refer to the `command` dictionary inside `commands.py`. For example to run heuristic-based baseline same as row 1 in table 1 of the paper use the command `python main_heuristic.py --eval_va_or_te 0 --pol_1 sha_rand`. For some experiments, like `tab_3_row_2_3`, the dictionary contains a list of commands. Essentially, we break the evaluation into multiple commands so that they can be run in parallel. Depending on the computing infrastructure, these commands can be run in parallel or serial.\n\n\n## Visualization\nMake sure you have downloded everything before this step. Follow the steps below:\n\n1. Save the actions. Follow the python script `\u003cpackit_dir\u003e/visualize.py`. It saves the agents actions in a json file. We also provide some prerecorded actions in `\u003cpackit_dir\u003e/data/visualize`\n1. Run the unity visulization build like this `./\u003cpackit_dir\u003e/unity/evns/packit_viz.x86_64 -getSavedAct true -fileName pack_va/0_va -packID 1 -actFileName visualize/pack_va_0_va_1_gt`. This would run visualization for the pack inside `pack_va/0_va` with ID `1` using the groundtruth actions. When the unity build opens up, press `a` to execute the actions. Only for visualization, we also provide a Mac OS unity build which could be used for visualization on Mac OS. The Mac OS visualizer could be run as `./\u003cpackit_dir\u003e/unity/evns/packit_viz_mac.app/Contents/MacOS/EgpGame3 -getSavedAct true -fileName pack_va/0_va -packID 1 -actFileName visualize/pack_va_0_va_1_gt`.\n\n\n## Notes\n- We train our learning-based model with 8 parallel environments. We recommend using a system with at least 8 CUPs to do the same with 4 GB of RAM each.\n\n- Unity environment communicated with the python process using ports. The `--id-start` flag inside `main.py` and `main_heuristic.py` could be used to start a process with different port id. The code will crash in case multiple unity environments are using the same port. This is the reason why we give different `--id-start` for different commands while running multiple environments in parallel. `--id-start 0` corresponds to port `5005` on OS (as defined [here](https://github.com/princeton-vl/PackIt/blob/master/unity/unityagents/environment.py#L33)). Any increment in `--id-start` updates the port incrementally. For example, `--id-start 10` corresponds to port `5015`.\n\n- `--eval_start_id` and `--eval_end_id` flags inside `main.py` and `main_heuristic.py` are used to specify the id of the packing files which we want to evaluate. While running multiple parallel environments of evaluation, we can use these flags to specify the id of packing files on which we want to evaluate. \n\n- When the unity environnment is running, you might get a terminal log similar to the following. It is expected and the environment would still run fine. \n```\nALSA lib confmisc.c:767:(parse_card) cannot find card '0'\nALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_card_driver returned error: Permission denied\nALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings\nALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_concat returned error: Permission denied\nALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name\nALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: Permission denied\nALSA lib conf.c:5047:(snd_config_expand) Evaluate error: Permission denied\nALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM default\n```\n\n- Apart from the stdout, unity log is written in `\u003cpackit_dir\u003e/log/unity/\u003cport\u003e`, which might be useful for debugging.\n\n- For generating more data or making your own unity build refer to [this repository](https://github.com/princeton-vl/PackIt_Extra).\n\n## Acknowledgment\nThis repository uses code from [ML-Agents](https://github.com/Unity-Technologies/ml-agents/tree/0.4.0) and [stable-baselines](https://github.com/hill-a/stable-baselines).\n\nIf you find our research useful, consider citing it:\n```\n@inproceedings{goyal2020packit,\n  title={PackIt: A Virtual Environment for Geometric Planning},\n  author={Goyal, Ankit and Deng, Jia},\n  booktitle={International Conference on Machine Learning},\n  year={2020},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprinceton-vl%2Fpackit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprinceton-vl%2Fpackit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprinceton-vl%2Fpackit/lists"}