For this project, you will train an agent to navigate (and collect bananas!) in a large, square world.
A reward of +1 is provided for collecting a yellow banana, and a reward of -1 is provided for collecting a blue banana. Thus, the goal of your agent is to collect as many yellow bananas as possible while avoiding blue bananas.
The state space has 37 dimensions and contains the agent's velocity, along with ray-based perception of objects around agent's forward direction. Given this information, the agent has to learn how to best select actions. Four discrete actions are available, corresponding to:
0
- move forward.1
- move backward.2
- turn left.3
- turn right.
The task is episodic, and in order to solve the environment, your agent must get an average score of +13 over 100 consecutive episodes.
-
Download the environment from one of the links below. You need only select the environment that matches your operating system:
- Linux: click here
- Mac OSX: click here
- Windows (32-bit): click here
- Windows (64-bit): Nothing to do
(For Windows users) Check out this link if you need help with determining if your computer is running a 32-bit version or 64-bit version of the Windows operating system.
(For AWS) If you'd like to train the agent on AWS (and have not enabled a virtual screen), then please use this link to obtain the environment.
-
Place the file in the GitHub repository, and unzip (or decompress) the file.
Follow the instructions in Navigation.ipynb
to get started with training your own agent!
If you want to test it by yourself :)
!pip -q install ./python
from unityagents import UnityEnvironment
import numpy as np
import torch
from collections import deque
import matplotlib.pyplot as plt
%matplotlib inline
from Dqn_agent import Agent
env = UnityEnvironment(file_name="Banana_Windows_x86_64/Banana.exe")
INFO:unityagents:
'Academy' started successfully!
Unity Academy name: Academy
Number of Brains: 1
Number of External Brains : 1
Lesson number : 0
Reset Parameters :
Unity brain name: BananaBrain
Number of Visual Observations (per agent): 0
Vector Observation space type: continuous
Vector Observation space size (per agent): 37
Number of stacked Vector Observation: 1
Vector Action space type: discrete
Vector Action space size (per agent): 4
Vector Action descriptions: , , ,
brain_name = env.brain_names[0] # get the name of the brains from the Unity environment
brain = env.brains[brain_name]
env_info = env.reset(train_mode=False)[brain_name] # reset the environment and obtain info on state/action space
# initialize agent with state size and action size.
agent = Agent(len(env_info.vector_observations[0]), brain.vector_action_space_size, seed=0)
# load the trained weights
agent.qnetwork_local.load_state_dict(torch.load('Dueling_model.pth'))
state = env_info.vector_observations[0] # get the first state
score = 0 # initialize the score
while True: # loop until the episode ends
action = agent.act(state, 0).astype(np.int32) # select a greedy action
env_info = env.step(action)[brain_name] # take that action
score += env_info.rewards[0] # update the score with the reward for taking that action
next_state = env_info.vector_observations[0] # the next state
state = next_state # set current state to next state
done = env_info.local_done[0] # get the value of the done bool, indicating the episode is over
# end episode if done is true
if done:
break