# Embodied acting and speaking This code was based on these repositories: [`gym-minigrid`](https://github.com/maximecb/gym-minigrid) [`torch-ac`](https://github.com/lcswillems/torch-ac) [`rl-starter-files`](add_url) ## Features - **Script to train**, including: - Log in txt, CSV and Tensorboard - Save model - Stop and restart training - Use A2C or PPO algorithms - **Script to visualize**, including: - Act by sampling or argmax - Save as Gif - **Script to evaluate**, including: - Act by sampling or argmax - List the worst performed episodes ## Installation ### Option 1 [comment]: <> todo: add this part [comment]: <> (Clone the repo) [comment]: <> (```) [comment]: <> (git clone https://gitlab.inria.fr/gkovac/act-and-speak.git) [comment]: <> (```) Create and activate your conda env ``` conda create --name act_and_speak python=3.6 conda activate act_and_speak ``` Install the required packages ``` pip install -r requirements.txt pip install -e torch-ac pip install -e gym-minigrid --use-feature=2020-resolver ``` ### Option 2 Alternative use the conda yaml file: ``` TODO: ``` ## Example of use Train, visualize and evaluate an agent on the `MiniGrid-DoorKey-5x5-v0` environment:
1. Train the agent on the `MiniGrid-DoorKey-5x5-v0` environment with PPO algorithm: ``` python3 -m scripts.train --algo ppo --env MiniGrid-DoorKey-5x5-v0 --model DoorKey --save-interval 10 --frames 80000 ``` 2. Visualize agent's behavior: ``` python3 -m scripts.visualize --env MiniGrid-DoorKey-5x5-v0 --model DoorKey ``` 3. Evaluate agent's performance: ``` python3 -m scripts.evaluate --env MiniGrid-DoorKey-5x5-v0 --model DoorKey ``` **Note:** More details on the commands are given below. ## Other examples ### Handle textual instructions In the `GoToDoor` environment, the agent receives an image along with a textual instruction. To handle the latter, add `--text` to the command: ``` python3 -m scripts.train --algo ppo --env MiniGrid-GoToDoor-5x5-v0 --model GoToDoor --text --save-interval 10 --frames 1000000 ``` ### Handle dialogue with multi a multi headed agent In the `GoToDoorTalk` environment, the agent receives an image along with the dialogue. To handle the latter, add `--dialogue` and, to use the multi headed agent, add `--multi-headed-agent` to the command: ``` python3 -m scripts.train --algo ppo --env MiniGrid-GoToDoorTalk-5x5-v0 --model GoToDoorMultiHead --dialogue --multi-headed-agent --save-interval 10 --frames 1000000 ``` ### Add memory In the `RedBlueDoors` environment, the agent has to open the red door then the blue one. To solve it efficiently, when it opens the red door, it has to remember it. To add memory to the agent, add `--recurrence X` to the command: ``` python3 -m scripts.train --algo ppo --env MiniGrid-RedBlueDoors-6x6-v0 --model RedBlueDoors --recurrence 4 --save-interval 10 --frames 1000000 ``` ## Files This package contains: - scripts to: - train an agent \ in `script/train.py` ([more details](#scripts-train)) - visualize agent's behavior \ in `script/visualize.py` ([more details](#scripts-visualize)) - evaluate agent's performances \ in `script/evaluate.py` ([more details](#scripts-evaluate)) - a default agent's model \ in `model.py` ([more details](#model)) - utilitarian classes and functions used by the scripts \ in `utils` These files are suited for [`gym-minigrid`](https://github.com/maximecb/gym-minigrid) environments and [`torch-ac`](https://github.com/lcswillems/torch-ac) RL algorithms. They are easy to adapt to other environments and RL algorithms by modifying: - `model.py` - `utils/format.py`