|
249 | 249 | " # First Dense layer\n",
|
250 | 250 | " tf.keras.layers.Dense(units=32, activation='relu'),\n",
|
251 | 251 | "\n",
|
252 |
| - " # TODO: Define the last Dense layer, which will provide the network's output.\n", |
253 |
| - " # Think about the space the agent needs to act in!\n", |
| 252 | + " ''' TODO: Define the last Dense layer, which will provide the network's output.\n", |
| 253 | + " # Think about the space the agent needs to act in! '''\n", |
254 | 254 | " tf.keras.layers.Dense(units=n_actions, activation=None) # TODO\n",
|
255 |
| - " # [TODO Dense layer to output action probabilities]\n", |
| 255 | + " # ['''TODO''' Dense layer to output action probabilities]\n", |
256 | 256 | " ])\n",
|
257 | 257 | " return model\n",
|
258 | 258 | "\n",
|
|
720 | 720 | },
|
721 | 721 | {
|
722 | 722 | "cell_type": "code",
|
723 |
| - "execution_count": null, |
| 723 | + "execution_count": 3, |
724 | 724 | "metadata": {
|
725 | 725 | "scrolled": true,
|
726 |
| - "id": "JrTpTBJsJ9Bp" |
| 726 | + "colab": { |
| 727 | + "base_uri": "https://localhost:8080/", |
| 728 | + "height": 530 |
| 729 | + }, |
| 730 | + "id": "JrTpTBJsJ9Bp", |
| 731 | + "outputId": "c6a7e93c-a9c1-4a15-b550-0dd4db94d05c" |
727 | 732 | },
|
728 |
| - "outputs": [], |
| 733 | + "outputs": [ |
| 734 | + { |
| 735 | + "output_type": "stream", |
| 736 | + "name": "stdout", |
| 737 | + "text": [ |
| 738 | + "vista_traces.zip 29%[====> ] 180.35M 68.8MB/s ^C\n", |
| 739 | + "Unzipping data...\n", |
| 740 | + "[vista_traces.zip]\n", |
| 741 | + " End-of-central-directory signature not found. Either this file is not\n", |
| 742 | + " a zipfile, or it constitutes one disk of a multi-part archive. In the\n", |
| 743 | + " latter case the central directory and zipfile comment will be found on\n", |
| 744 | + " the last disk(s) of this archive.\n", |
| 745 | + "unzip: cannot find zipfile directory in one of vista_traces.zip or\n", |
| 746 | + " vista_traces.zip.zip, and cannot find vista_traces.zip.ZIP, period.\n", |
| 747 | + "Done downloading and unzipping data!\n" |
| 748 | + ] |
| 749 | + }, |
| 750 | + { |
| 751 | + "output_type": "error", |
| 752 | + "ename": "NameError", |
| 753 | + "evalue": "ignored", |
| 754 | + "traceback": [ |
| 755 | + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
| 756 | + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", |
| 757 | + "\u001b[0;32m<ipython-input-3-06a67e1ffe73>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0;34m\"20210726-184956_lexus_devens_center_reverse\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 13\u001b[0m ]\n\u001b[0;32m---> 14\u001b[0;31m \u001b[0mtrace_path\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrace_root\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mp\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mp\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mtrace_path\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 15\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0;31m# Create a virtual world with VISTA, the world is defined by a series of data traces\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
| 758 | + "\u001b[0;32m<ipython-input-3-06a67e1ffe73>\u001b[0m in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0;34m\"20210726-184956_lexus_devens_center_reverse\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 13\u001b[0m ]\n\u001b[0;32m---> 14\u001b[0;31m \u001b[0mtrace_path\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrace_root\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mp\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mp\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mtrace_path\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 15\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0;31m# Create a virtual world with VISTA, the world is defined by a series of data traces\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
| 759 | + "\u001b[0;31mNameError\u001b[0m: name 'os' is not defined" |
| 760 | + ] |
| 761 | + } |
| 762 | + ], |
729 | 763 | "source": [
|
730 | 764 | "# Download and extract the data for vista (auto-skip if already downloaded)\n",
|
731 | 765 | "!wget -nc -q --show-progress https://www.dropbox.com/s/3qogfzuugi852du/vista_traces.zip\n",
|
|
735 | 769 | "\n",
|
736 | 770 | "trace_root = \"./vista_traces\"\n",
|
737 | 771 | "trace_path = [\n",
|
738 |
| - "# \"20210726-131322_lexus_devens_center\", \n", |
739 |
| - "# \"20210726-131912_lexus_devens_center_reverse\", \n", |
740 | 772 | " \"20210726-154641_lexus_devens_center\", \n",
|
741 | 773 | " \"20210726-155941_lexus_devens_center_reverse\", \n",
|
742 | 774 | " \"20210726-184624_lexus_devens_center\", \n",
|
|
1093 | 1125 | " # First, 32 5x5 filters and 2x2 stride\n",
|
1094 | 1126 | " Conv2D(filters=32, kernel_size=5, strides=2),\n",
|
1095 | 1127 | "\n",
|
1096 |
| - " # TODO: define convolutional layers with 48 5x5 filters and 2x2 stride\n", |
| 1128 | + " ''' TODO: define convolutional layers with 48 5x5 filters and 2x2 stride '''\n", |
1097 | 1129 | " Conv2D(filters=48, kernel_size=5, strides=2), # TODO\n",
|
1098 | 1130 | " # Conv2D('''TODO'''),\n",
|
1099 | 1131 | "\n",
|
1100 |
| - " # TODO: define two convolutional layers with 64 3x3 filters and 2x2 stride\n", |
| 1132 | + " ''' TODO: define two convolutional layers with 64 3x3 filters and 2x2 stride '''\n", |
1101 | 1133 | " Conv2D(filters=64, kernel_size=3, strides=2), # TODO\n",
|
1102 | 1134 | " Conv2D(filters=64, kernel_size=3, strides=2), # TODO\n",
|
1103 | 1135 | " # Conv2D('''TODO'''),\n",
|
|
1106 | 1138 | "\n",
|
1107 | 1139 | " # Fully connected layer and output\n",
|
1108 | 1140 | " Dense(units=128, activation=act),\n",
|
1109 |
| - " # TODO: define the output dimension of the last Dense layer. \n", |
1110 |
| - " # Pay attention to the space the agent needs to act in.\n", |
1111 |
| - " # Remember that this model is outputing *continuous* actions, \n", |
1112 |
| - " # which take a different shape than discrete actions (like in Cartpole).\n", |
| 1141 | + " ''' TODO: define the output dimension of the last Dense layer. \n", |
| 1142 | + " Pay attention to the space the agent needs to act in.\n", |
| 1143 | + " Remember that this model is outputing *continuous* actions, \n", |
| 1144 | + " which take a different shape than discrete actions (like in Cartpole). '''\n", |
1113 | 1145 | " Dense(units=2, activation=None) # TODO\n",
|
1114 | 1146 | " # Dense('''TODO''')\n",
|
1115 | 1147 | "\n",
|
|
1200 | 1232 | "## Training parameters ##\n",
|
1201 | 1233 | "## Re-run this cell to restart training from scratch ##\n",
|
1202 | 1234 | "\n",
|
1203 |
| - "# TODO: Learning rate and optimizer\n", |
| 1235 | + "''' TODO: Learning rate and optimizer '''\n", |
1204 | 1236 | "learning_rate = 5e-4\n",
|
1205 | 1237 | "# learning_rate = '''TODO'''\n",
|
1206 | 1238 | "optimizer = tf.keras.optimizers.Adam(learning_rate)\n",
|
|
1256 | 1288 | " observation = grab_and_preprocess_obs(car)\n",
|
1257 | 1289 | "\n",
|
1258 | 1290 | " while True:\n",
|
1259 |
| - " # TODO: using the car's current observation compute the desired \n", |
1260 |
| - " # action (curvature) distribution by feeding it into our \n", |
1261 |
| - " # driving model (use the function you already built to do this!)\n", |
| 1291 | + " '''TODO: using the car's current observation compute the desired \n", |
| 1292 | + " action (curvature) distribution by feeding it into our \n", |
| 1293 | + " driving model (use the function you already built to do this!) '''\n", |
1262 | 1294 | " curvature_dist = run_driving_model(observation)\n",
|
1263 | 1295 | " # curvature_dist = '''TODO'''\n",
|
1264 | 1296 | " \n",
|
1265 |
| - " # TODO: sample from the action distribution to decide how to step\n", |
1266 |
| - " # the car in the environment. You may want to check the documentation\n", |
1267 |
| - " # for tfp.distributions.Normal online. Remember that the sampled action\n", |
1268 |
| - " # should be a single scalar value after this step.\n", |
| 1297 | + " ''' TODO: sample from the action distribution to decide how to step\n", |
| 1298 | + " the car in the environment. You may want to check the documentation\n", |
| 1299 | + " for tfp.distributions.Normal online. Remember that the sampled action\n", |
| 1300 | + " should be a single scalar value after this step.'''\n", |
1269 | 1301 | " curvature_action = curvature_dist.sample()[0,0]\n",
|
1270 | 1302 | " # curvature_action = '''TODO'''\n",
|
1271 | 1303 | " \n",
|
1272 | 1304 | " # Step the simulated car with the same action\n",
|
1273 | 1305 | " vista_step(curvature_action)\n",
|
1274 | 1306 | " observation = grab_and_preprocess_obs(car)\n",
|
1275 | 1307 | " \n",
|
1276 |
| - " # TODO: Compute the reward for this iteration. You define \n", |
1277 |
| - " # the reward function for this policy, start with something \n", |
1278 |
| - " # simple - for example, give a reward of 1 if the car did not \n", |
1279 |
| - " # crash and a reward of 0 if it did crash.\n", |
| 1308 | + " '''TODO: Compute the reward for this iteration. You define \n", |
| 1309 | + " the reward function for this policy, start with something \n", |
| 1310 | + " simple - for example, give a reward of 1 if the car did not \n", |
| 1311 | + " crash and a reward of 0 if it did crash.'''\n", |
1280 | 1312 | " reward = 1.0 if not check_crash(car) else 0.0\n",
|
1281 | 1313 | " # reward = '''TODO'''\n",
|
1282 | 1314 | " \n",
|
|
0 commit comments