|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Unity ML-Agents Toolkit\n",
- "## Environment Basics\n",
- "This notebook contains a walkthrough of the basic functions of the Python API for the Unity ML-Agents toolkit. For instructions on building a Unity environment, see [here](https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Getting-Started-with-Balance-Ball.md)."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 1. Set environment parameters\n",
- "\n",
- "Be sure to set `env_name` to the name of the Unity environment file you want to launch. Ensure that the environment build is in `../envs`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "env_name = \"../envs/Bachelorarbeit-Cozmo\" # Name of the Unity environment binary to launch\n",
- "train_mode = True # Whether to run the environment in training or inference mode"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 2. Load dependencies\n",
- "\n",
- "The following loads the necessary dependencies and checks the Python version (at runtime). ML-Agents Toolkit (v0.3 onwards) requires Python 3."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Python version:\n",
- "3.6.7 |Anaconda, Inc.| (default, Oct 28 2018, 19:44:12) [MSC v.1915 64 bit (AMD64)]\n"
- ]
- }
- ],
- "source": [
- "import matplotlib.pyplot as plt\n",
- "import numpy as np\n",
- "import sys\n",
- "\n",
- "from mlagents.envs import UnityEnvironment\n",
- "\n",
- "%matplotlib inline\n",
- "\n",
- "print(\"Python version:\")\n",
- "print(sys.version)\n",
- "\n",
- "# check Python version\n",
- "if (sys.version_info[0] < 3):\n",
- " raise Exception(\"ERROR: ML-Agents Toolkit (v0.3 onwards) requires Python 3\")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 3. Start the environment\n",
- "`UnityEnvironment` launches and begins communication with the environment when instantiated.\n",
- "\n",
- "Environments contain _brains_ which are responsible for deciding the actions of their associated _agents_. Here we check for the first brain available, and set it as the default brain we will be controlling from Python."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "INFO:mlagents.envs:\n",
- "'Academy' started successfully!\n",
- "Unity Academy name: Academy\n",
- " Number of Brains: 1\n",
- " Number of Training Brains : 1\n",
- " Reset Parameters :\n",
- "\t\t\n",
- "Unity brain name: CozmoLearningBrain\n",
- " Number of Visual Observations (per agent): 1\n",
- " Vector Observation space size (per agent): 0\n",
- " Number of stacked Vector Observation: 1\n",
- " Vector Action space type: discrete\n",
- " Vector Action space size (per agent): [4]\n",
- " Vector Action descriptions: \n"
- ]
- }
- ],
- "source": [
- "env = UnityEnvironment(file_name=env_name)\n",
- "\n",
- "# Set the default brain to work with\n",
- "default_brain = env.brain_names[0]\n",
- "brain = env.brains[default_brain]"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 4. Examine the observation and state spaces\n",
- "We can reset the environment to be provided with an initial set of observations and states for all the agents within the environment. In ML-Agents, _states_ refer to a vector of variables corresponding to relevant aspects of the environment for an agent. Likewise, _observations_ refer to a set of relevant pixel-wise visuals for an agent."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Agent state looks like: \n",
- "[]\n",
- "Agent observations look like:\n"
- ]
- },
- {
- "data": {
- "image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wF8A3iR3q+6Pzvuz31O5u3Ao23M2eT5VvN4bvbfTds+9ybTFLC/+ewfAja1LSe9A/X/AWyc09eqjKt9eKWoJHWEV4pKUkdY0CWpIyzoktQRFnRJ6ggLuiR1hAVdkjrCgi5JHWFBl6SO+D9r6A1+Eo63fQAAAABJRU5ErkJggg==\n",
- "text/plain": [
- "<Figure size 432x288 with 1 Axes>"
- ]
- },
- "metadata": {
- "needs_background": "light"
- },
- "output_type": "display_data"
- }
- ],
- "source": [
- "# Reset the environment\n",
- "env_info = env.reset(train_mode=train_mode)[default_brain]\n",
- "\n",
- "# Examine the state space for the default brain\n",
- "print(\"Agent state looks like: \\n{}\".format(env_info.vector_observations[0]))\n",
- "\n",
- "# Examine the observation space for the default brain\n",
- "for observation in env_info.visual_observations:\n",
- " print(\"Agent observations look like:\") \n",
- " \n",
- " #change to numpy array instead of list\n",
- " #observation = cv2.Canny(observation,100,100)\n",
- " observation = np.array(observation)\n",
- " #slice1Copy = np.uint8(observation)\n",
- " #edges = cv2.Canny(slice1Copy,100,100)\n",
- " \n",
- " \n",
- " #if edges.shape[3] == 3:\n",
- " #plt.imshow(observation[0])\n",
- " #else:\n",
- " # plt.imshow(edges[0,:,:,0])\n",
- " \n",
- " if observation.shape[3] == 3:\n",
- " plt.imshow(observation[0,:,:,:])\n",
- " else:\n",
- " plt.imshow(observation[0,:,:,0])"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 5. Take random actions in the environment\n",
- "Once we restart an environment, we can step the environment forward and provide actions to all of the agents within the environment. Here we simply choose random actions based on the `action_space_type` of the default brain. \n",
- "\n",
- "Once this cell is executed, 10 messages will be printed that detail how much reward will be accumulated for the next 10 episodes. The Unity environment will then pause, waiting for further signals telling it what to do next. Thus, not seeing any animation is expected when running this cell."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Total reward this episode: -366.90000158548355\n"
- ]
- },
- {
- "ename": "KeyError",
- "evalue": "'CozmoLearningBrain'",
- "output_type": "error",
- "traceback": [
- "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
- "\u001b[1;32m<ipython-input-5-3140409a1130>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[0maction\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumn_stack\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrandint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maction_size\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msize\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0menv_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0magents\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maction_size\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[0menv_info\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0menv\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maction\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mdefault_brain\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 13\u001b[0m \u001b[0mepisode_rewards\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[0menv_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrewards\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 14\u001b[0m \u001b[0mdone\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0menv_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlocal_done\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32mc:\\users\\tobi\\downloads\\ml-agents-0.8.1\\ml-agents-envs\\mlagents\\envs\\environment.py\u001b[0m in \u001b[0;36mstep\u001b[1;34m(self, vector_action, memory, text_action, value, custom_action)\u001b[0m\n\u001b[0;32m 439\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_global_done\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mstate\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 440\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0m_b\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_external_brain_names\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 441\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_n_agents\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0m_b\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstate\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0m_b\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0magents\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 442\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mstate\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 443\u001b[0m \u001b[1;32melif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_loaded\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;31mKeyError\u001b[0m: 'CozmoLearningBrain'"
- ]
- }
- ],
- "source": [
- "for episode in range(100):\n",
- " env_info = env.reset(train_mode=train_mode)[default_brain]\n",
- " done = False\n",
- " episode_rewards = 0\n",
- " while not done:\n",
- " action_size = brain.vector_action_space_size\n",
- " if brain.vector_action_space_type == 'continuous':\n",
- " env_info = env.step(np.random.randn(len(env_info.agents), \n",
- " action_size[0]))[default_brain]\n",
- " else:\n",
- " action = np.column_stack([np.random.randint(0, action_size[i], size=(len(env_info.agents))) for i in range(len(action_size))])\n",
- " env_info = env.step(action)[default_brain]\n",
- " episode_rewards += env_info.rewards[0]\n",
- " done = env_info.local_done[0]\n",
- " print(\"Total reward this episode: {}\".format(episode_rewards))"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 6. Close the environment when finished\n",
- "When we are finished using an environment, we can close it with the function below."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [],
- "source": [
- "env.close()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "anaconda-cloud": {},
- "kernelspec": {
- "display_name": "Python 3",
- "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.6.7"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 1
- }
|