Last active
February 3, 2022 09:32
-
-
Save x1001000/ac28c8879da1e861d2460c686f376315 to your computer and use it in GitHub Desktop.
樹莓派學開車
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "樹莓派學開車", | |
"provenance": [], | |
"collapsed_sections": [ | |
"FNJPVrXDXWBY", | |
"Uwl-Ct1QZapS", | |
"JopyWPttXqAa", | |
"8IYt3nB5a-DH", | |
"fXFZtafMdoKh", | |
"v7lKyuc5juu3", | |
"TdQg-bwNT2da", | |
"T2sD9AvSEFzy", | |
"_vrmSOjtIOFT" | |
], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"accelerator": "GPU" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/x1001000/ac28c8879da1e861d2460c686f376315/donkeycar.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "FNJPVrXDXWBY" | |
}, | |
"source": [ | |
"# Colab 基本操作" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "oGXyqGncjp8b" | |
}, | |
"source": [ | |
"## 先另存這個 notebook (.ipynb)\n", | |
"1. 存雲端 Google Drive,用 Colab 就能編輯和執行\n", | |
"2. 載下來,電腦需安裝 Jupyter 才能編輯和執行\n", | |
"3. [CC BY](http://creativecommons.org/licenses/by/3.0/tw/) [十百千實驗室](https://medium.com/十百千實驗室)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Uwl-Ct1QZapS" | |
}, | |
"source": [ | |
"## 進、出、換 cell\n", | |
"1. ENTER進cell\n", | |
"2. ESC出cell\n", | |
"3. ↑↓換cell" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "JopyWPttXqAa" | |
}, | |
"source": [ | |
"## 上增、下增、刪除、轉換 cell\n", | |
"1. CMD/CTRL+m a (above的意思)\n", | |
"2. CMD/CTRL+m b (below的意思)\n", | |
"3. CMD/CTRL+m d (delete的意思)\n", | |
"4. CMD/CTRL+m m/y (轉成text/code)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "8IYt3nB5a-DH" | |
}, | |
"source": [ | |
"## 在 cell 內\n", | |
"1. ENTER換行編輯cell\n", | |
"2. SHIFT+ENTER執行cell" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "fXFZtafMdoKh" | |
}, | |
"source": [ | |
"## 上一步、下一步\n", | |
"1. 在cell內:CMD/CTRL+z/y\n", | |
"2. 在cell外:CMD/CTRL+SHIFT+z/y" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "v7lKyuc5juu3" | |
}, | |
"source": [ | |
"## Runtime\n", | |
"1. restart 重開機\n", | |
"2. reset 重置、重灌\n", | |
"3. 換GPU能加快訓練速度數十倍" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "YahOeLaofN_x" | |
}, | |
"source": [ | |
"## Linux 指令\n", | |
"1. 你的Google雲端硬碟裡的Colab Notebook是跑在1.5hr/12hr自動重置的Linux虛擬機上\n", | |
"2. 資料科學、機器學習、深度學習(神經網路)、Google Cloud API相關的Python函式庫皆已安裝\n", | |
"3. 現成的AI實驗開發環境,使用Python程式語言\n", | |
"4. 前置一個驚嘆號,使用Linux指令操作虛擬機\n", | |
"5. 用 && 解決無法停留在 cd 後的工作目錄的問題" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "n30Jtvif9pHn" | |
}, | |
"source": [ | |
"! pip list" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "pAjvOA6vYUs2" | |
}, | |
"source": [ | |
"! ls" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "RKwWj1mRVWG5" | |
}, | |
"source": [ | |
"! touch HELLO.txt" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "PuzCWkuOWB0W" | |
}, | |
"source": [ | |
"! mkdir WORLD" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "7zLMsr7CWQZv" | |
}, | |
"source": [ | |
"! mv HELLO.txt WORLD" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "ilr4F1QKWWWN" | |
}, | |
"source": [ | |
"! cd WORLD " | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "7nmmnAiZGlBW" | |
}, | |
"source": [ | |
"## 有用、有趣の設定\n", | |
"1. Settings -> Site -> Theme -> dark\n", | |
"2. Settings -> Miscellaneous -> Power / Corgi / Kitty" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "TdQg-bwNT2da" | |
}, | |
"source": [ | |
"# 訓練 / 學習" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "6Vdqfu2hCqux" | |
}, | |
"source": [ | |
"## 安裝 Donkeycar 開發套件及 PS3 藍芽手把驅動程式" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "nZQCTMl45KLJ" | |
}, | |
"source": [ | |
"! pip install git+https://github.com/autorope/donkeycar@0812f83" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "qxskIwLvPIiu" | |
}, | |
"source": [ | |
"! pip install git+https://github.com/raspberrypi-tw/donkeypart_ps3_controller" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "MrTdaCR4FFzs" | |
}, | |
"source": [ | |
"## 完整複製(git clone)或下載差異(git pull)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "aWaMVOZJIWD7" | |
}, | |
"source": [ | |
"! git clone https://github.com/x1001000/mycar" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "bZt6MZLmteBb" | |
}, | |
"source": [ | |
"! cd mycar && git pull" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "BVEb-VpfGPFw" | |
}, | |
"source": [ | |
"## Training / Testing\n", | |
"1. model 自行命名,但副檔名必須是.h5\n", | |
"2. type 選項 \n", | |
"https://github.com/autorope/donkeycar/blob/master/donkeycar/templates/complete.py#L7\n", | |
"3. DonkeyCar已實作的各種模型的說明和比較 \n", | |
"http://docs.donkeycar.com/parts/keras/\n", | |
"4. TRAIN_TEST_SPLIT = 0.8 \n", | |
"BATCH_SIZE = 128 \n", | |
"MAX_EPOCHS = 100" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Ht18T-X4BJLP" | |
}, | |
"source": [ | |
"! ls mycar" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "nbntNALiOSD7" | |
}, | |
"source": [ | |
"! cd mycar && mkdir models" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "tTGjZ1ORIkIH" | |
}, | |
"source": [ | |
"# 確認已更換為 GPU 的 runtime,訓練時間快\b上數十倍\n", | |
"! cd mycar && python3 manage.py train --type rnn --model models/rnn_1.h5" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "gDvO4snm2b7x" | |
}, | |
"source": [ | |
"# 確認已更換為 GPU 的 runtime,訓練時間快\b上數十倍\n", | |
"! cd mycar && python3 manage.py train --type rnn --model models/rnn_2.h5 --transfer models/rnn_1.h5 --tub data/tub資料夾名稱,data/tub資料夾名稱,..." | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "T2sD9AvSEFzy" | |
}, | |
"source": [ | |
"# 推論 / 應用" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "UH00QYOjHxSP" | |
}, | |
"source": [ | |
"## 上傳差異(git push)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "udSxSLPXJiz-" | |
}, | |
"source": [ | |
"! git config --global user.email \"you@example.com\"\n", | |
"! git config --global user.name \"Your Name\"" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "HljiqCRcJd_p" | |
}, | |
"source": [ | |
"! cd mycar && git add .\n", | |
"! cd mycar && git commit -m 'rnn_1'" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "dQ1DwuiFKCLz" | |
}, | |
"source": [ | |
"! cd mycar && git push https://帳:密@github.com/帳/mycar" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "_vrmSOjtIOFT" | |
}, | |
"source": [ | |
"## 回樹莓派下載差異(git pull)\n", | |
"```\n", | |
"溫馨提醒:\n", | |
"這是在樹莓派做\n", | |
"不是在Colab做\n", | |
"git pull\n", | |
"python manage.py drive --type rnn --model models/rnn_1.h5\n", | |
"```" | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment