This document describes the preparations required to operate the code of each book of "Deep Learning from scratch" (1) to (3). Basically, it is for those who have never written a program or who have little experience. It may also be useful for those who do not develop on Windows.
"Git, vscode, etc. are commonplace!" Please note that this document is not necessary for those who say.
Download the installer from the official website. https://www.python.org/
You can download it by pointing to'Donwloads' at the top of the page and clicking the link that appears under'Download for Windows'.
Don't forget to put it in the path during installation. Specifically, on the first screen of the installation wizard, check "Add Python 3.X to PATH".
If this is neglected, the pip command cannot be used. In addition, there may be problems such as misidentifying it as uninstalled Python in the Windows Store and not accepting commands (experience story).
Since the sample code is on github, I will download it with git clone. As a preparation for that, you need to install git.
To install git, go to the official website. https://git-scm.com/
You can download the installer by clicking the'Download x.xx.xx for Windows' link on the right side of the page.
Install the libraries required to execute the programs in this manual. The required libraries vary depending on the volume, but if you want to read only one volume first, you can install only two, numpy and matplotlab. Other libraries are needed to execute the code in Volumes 2 and 3.
Launch ** git bash ** from the start menu. (Also possible at the command prompt)
First, update pip itself. Since pip is updated frequently, we recommend that you update it even if you already have python installed.
bash
$ pip install --upgrade pip
Then install numpy. numpy is a Python numerical calculation library.
bash
$ pip install numpy
Next, install matplotlib. Although matplotlib is not related to the operation of the machine learning itself, it is used to display and evaluate the progress and performance of machine learning in a graph.
bash
$ pip install matplotlib
Volume 2 requires sklearn in addition to the above two. (You can execute the code without it, but it will take a long time to learn, so you should install it.) Not required for Volume 1.
bash
$ pip install sklearn
It is an option for 2 and 3 volumes, and it is not necessary for 1 volume. It's an option so you don't have to install it (even if you don't, it will fit in a realistic calculation time). However, it is better to introduce it when trying to make it complicated by modifying the program.
CuPy can only be used on PCs with NVIDIA GPUs.
See the separate article below for the installation method. https://qiita.com/BARANCE_TW/items/30abf85c55070a2bdc9d
Pillow is a library for image processing. It has a function to process the image by changing the color space and binarizing it.
bash
$ pip install pillow
graphviz is a tool for drawing graphs. The graph referred to here is not a general graph drawn by matplotlib, but a graph consisting of edges and nodes used in graph theory.
See the separate article below for the installation method. https://qiita.com/BARANCE_TW/items/c3f7816d38cc9e746bbd
Before cloning, create an appropriate working directory (folder).
In the following, it is assumed that a directory called "ai" is created directly under the C drive.
(That is, C: \ ai
becomes the workspace directory)
Next, open the repository URL in a browser, press the green button on the right side, and copy the displayed URL for clone.
The repository for each volume is below.
--Repository of "Deep Learning from scratch" https://github.com/oreilly-japan/deep-learning-from-scratch --Repository for "Deep Learning 2 from scratch" https://github.com/oreilly-japan/deep-learning-from-scratch-2 --Repository for "Deep Learning 3 from scratch" https://github.com/oreilly-japan/deep-learning-from-scratch-3
After copying the clone URL, open ** git bash **, paste the copied URL for clone in the following {clone URL}
, and execute it.
After a short while, the sample code will be cloned to the corresponding directory.
bash
$ cd /c/ai
$ git clone {clone URL}
Up to the beginning of Volume 1, the amount of code is sufficient even with an interactive console, but after the middle stage, the amount of code and the number of files will increase explosively, so it is recommended to use some kind of environment. I'll install vscode here, but if you have an IDE or editor you like, that's fine.
Download vscode from below.
After starting vscode, first open the directory you cloned earlier as a workspace. Click the File menu and select Open Folder. (Note that it is not "Open workspace")
Then go to the cloned directory and click "Select Folder" to open the workspace. Confirm that the list of cloned files is displayed in "Explorer" on the left side.
In vscode, you can execute the code with "Ctrl" + "F5" (or debug execution with "F5"). However, the execution directory at that time will be the root directory of the workspace by default. If left in this state, the following problems will occur.
--From / import that starts from the location of the file where the code is written does not work as expected. --The directory for reading / writing files with pickle etc. becomes the root directory of the workspace.
To solve this problem, edit launch.json to make the directory containing the files the execution directory. First, select the "Run" tab from the location where the icons on the left are lined up, and select "Create launch.json file".
Next, the message "Select a debug configuration" will appear, so click "Python File".
Then, the edit screen of launch.json is displayed. This file is stored in the ".vscode" directory directly under the workspace root directory.
Add the notation " cwd ":" $ {fileDirname} "
to the "configurations" value in this file.
The file after adding is as follows.
launch.json
{
//You can use IntelliSense to learn the available attributes.
//Hover and display the description of existing attributes.
//Check the following for more information: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal", //Add comma to the end
"cwd": "${fileDirname}" //Add here!!
}
]
}
Now, when you press "Ctrl" + "F5", the program will be executed after moving to the path where the file is located.
Recommended Posts