[Windows 10] "Deep Learning from scratch" environment construction

Introduction

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.

Python installation

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).

git installation

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.

Installation of Python modules

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) git_bash.png

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

numpy [Volumes 1-3]

Then install numpy. numpy is a Python numerical calculation library.

bash


$ pip install numpy

matplotlib [Volumes 1-3]

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

sklearn [Volume 2]

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

CuPy [Volumes 2 and 3]

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 [Volume 3]

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 [Volume 3]

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

Sample code clone

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. repo.png

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}

vscode installation

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.

Open workspace

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") workspace1.png

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.

Edit launch.json

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". launch1.png

Next, the message "Select a debug configuration" will appear, so click "Python File". launch2.png

Then, the edit screen of launch.json is displayed. This file is stored in the ".vscode" directory directly under the workspace root directory. launch3.png

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

[Windows 10] "Deep Learning from scratch" environment construction
Deep learning tutorial from environment construction
Deep Learning from scratch
Realize environment construction for "Deep Learning from scratch" with docker and Vagrant
Deep learning from scratch (cost calculation)
Deep Learning memos made from scratch
Create an environment for "Deep Learning from scratch" with Docker
[Learning memo] Deep Learning made from scratch [Chapter 7]
Deep learning / Deep learning from scratch 2-Try moving GRU
[Learning memo] Deep Learning made from scratch [Chapter 5]
[Learning memo] Deep Learning made from scratch [Chapter 6]
"Deep Learning from scratch" in Haskell (unfinished)
Deep learning / Deep learning made from scratch Chapter 7 Memo
Learning record of reading "Deep Learning from scratch"
[Deep Learning from scratch] About hyperparameter optimization
"Deep Learning from scratch" Self-study memo (Part 12) Deep learning
[Learning memo] Deep Learning made from scratch [~ Chapter 4]
python windows environment construction
"Deep Learning from scratch" Self-study memo (9) MultiLayerNet class
Deep Learning from scratch ① Chapter 6 "Techniques related to learning"
Good book "Deep Learning from scratch" on GitHub
Deep Learning from scratch Chapter 2 Perceptron (reading memo)
[Learning memo] Deep Learning from scratch ~ Implementation of Dropout ~
Python vs Ruby "Deep Learning from scratch" Summary
"Deep Learning from scratch" Self-study memo (10) MultiLayerNet class
"Deep Learning from scratch" Self-study memo (No. 11) CNN
Build a "Deep learning from scratch" learning environment on Cloud9 (jupyter miniconda python3)
[Deep Learning from scratch] I implemented the Affine layer
Prepare the environment for O'Reilly's book "Deep Learning from scratch" with apt-get (Debian 8)
"Deep Learning from scratch" Self-study memo (No. 19) Data Augmentation
"Deep Learning from scratch 2" Self-study memo (No. 21) Chapters 3 and 4
Python environment construction (Windows10 + Emacs)
Deep learning / LSTM scratch code
Application of Deep Learning 2 made from scratch Spam filter
[Tensorflow] Tensorflow environment construction on Windows 10
[Deep Learning from scratch] I tried to explain Dropout
Create a machine learning environment from scratch with Winsows 10
[Deep Learning from scratch] Implementation of Momentum method and AdaGrad method
OpenJTalk on Windows10 (Speak Japanese with Python from environment construction)
An amateur stumbled in Deep Learning from scratch Note: Chapter 1
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 5
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 2
An amateur stumbled in Deep Learning from scratch Note: Chapter 3
An amateur stumbled in Deep Learning from scratch Note: Chapter 7
An amateur stumbled in Deep Learning from scratch Note: Chapter 5
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 7
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 1
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 4
"Deep Learning from scratch" self-study memo (No. 18) One! Meow! Grad-CAM!
"Deep Learning from scratch" self-study memo (No. 19-2) Data Augmentation continued
An amateur stumbled in Deep Learning from scratch Note: Chapter 4
An amateur stumbled in Deep Learning from scratch Note: Chapter 2
I tried to implement Perceptron Part 1 [Deep Learning from scratch]
"Deep Learning from scratch" self-study memo (No. 15) TensorFlow beginner tutorial
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 6
Deep Learning / Deep Learning from Zero 2 Chapter 4 Memo
Python environment construction memo on Windows 10
Anaconda python environment construction on Windows 10
Python + Unity Reinforcement learning environment construction
Deep Learning / Deep Learning from Zero 2 Chapter 5 Memo
[Python3] Development environment construction << Windows edition >>