Pytorch depth learning framework Quick Start Tutorial (a, use google colaboratory) (ultra-detailed)

0. I assemble their own a computer?

As today is the most fiery depth study of technology, although the threshold is low, entry is easy, but is not required to calculate the amount of general computer can sustain, but you do not need to assemble a ultra-high performance computers

Many people, when just learning the depth of learning will face a very serious problem, inadequate machine performance , in which case you have several options

  1. The use of cloud computing service providers (such as AWS, AZure) resources for learning, most pay, and expensive
  2. Own to assemble a giant high-performance machines, you know the price
  3. Use google colaboratoryprice Guess? Is basically free of charge

google colaboraory official link: google colaboraory

1. Getting three main reasons to use the google colaboratory

When it comes to posture above you have three entry-depth study of why it is recommended that you use google Colaboratory it?

  1. It basically free, and powerful performance: According to statistical data, it can provide maximum 1080Ti general computing performance for most of the models are adequate, and he also provides a lot of extra space, so you can store more data
  2. It eliminates the tedious configuration steps: In the google colaboratorybuilt environment, all environments are good for you, you just importcan !!
  3. It provides jupyter notebooksupport, and support for jupyter notebookcustom

2. google colaboratory entry

If you are jupyter notebookmore familiar with this section, you can just skim

2.1 Overview

Enter the official website , you can probably look at the initial introduction page (if you compare English is good), but you do not understand all right, I'll take you step by step to use it

The following are referred tocolab

Into the top of this page and login you can see on the left there are three columns,

  • First column: article directories, colabis mardowndoes not provide a way to generate a table of contents, but you can browse here your markdownnotes directory
  • Second column: snippet you can copy some code snippets here, you can click it a try
  • The third column: catalog, the entire notebook is actually stored in a linuxsystem hard drive, if you are not careful the level back to the root directory, to be returned into the /content/directory can

(If you use Google browser and has landed here to insert a picture description)

Example 2.2: Import package pytorch

The following first be a small example, you can first follow suit later will explain the meaning of these operations

2.2.1 Create a notebook

Click on the top left 文件->新建笔记本, we have to create a new notebook, the next picture shows the way to establish good
Here Insert Picture Description

2.2.2 enter edit mode

Double-click the block edit mode, double-clicking ctrl+mthe block to the markdownmodel, add text markdown

###  导入pytorch包

Press alt+enter, and run the new row below the block

2.2.3 Import package pytorch

Enter the following block of code in the new pythoncode introduced into pytorchthe package

import torch
print(torch.cuda.is_available())
print(torch.rand(2,2)) 

You should see the following results

True
tensor([[0.0674, 0.4890],
        [0.1619, 0.0300]])

If you get False, try 代码执行程序(Runtime)->更改运行时类型(changeRunTimeType)->硬件加速(hardware accelorator)->改为GPU, try again then double-click to enter and alt+enterrun the code block is
good that you have successfully imported Pytorch package

2.2 colab mode

Similar jupyter notebook, colab also has two modes

  • 块模式: 按下ESC进入, 可以使用鼠标左键进行选择块
  • 编辑模式: 按下Enter进入当前块进行编辑, 也可以使用鼠标左键双击想要编辑的块进行编辑

同样的与jupyter notebook一样, 块也拥有两种块

  • markdown: 编辑markdown文本
  • 代码块: 编辑python代码

markdown用来记笔记, 代码块用来演示运行示例代码

2.3 在colab中移动自如

为了更好的使用colab, 我们至少需要记住如下的几个快捷键

  • 两下ctrl+m: 在python代码模式与markdown模式进行切换
  • ctrl+m+a: 在当前块上方插入一行代码块
  • ctrl+m+b: 在当前块下方插入一行代码块
  • ctrl+m+d: 删除代码块
  • ↑\↓: 在块模式下进行块之间的移动, 在编辑模式下移动光标进行编辑
  • alt+enter: 运行代码块并且新建一行
  • ctrl+enter: 只运行代码块

好了, 现在你可以利用这些快捷键自由的尝试建立一些markdown笔记, python代码并且尝试运行他们

3. 花里胡哨

好了, 如果你是个对外观没有要求的程序员可以跳过这一节, 但你会少去许多敲代码的快感

3.1 火花

你可以工具->设置->其他->威力等级来使你在代码块下敲代码时有火花特效, 有三种不同的威力等级
Here Insert Picture Description

  • no power: 敲代码不会蹦出火花
  • some power: 在你连续敲打30个字母后才会蹦出火花
  • many power: 敲代码总会蹦出火花

3.2 柯基犬/猫咪

工具->设置->其他还有两个额外选项

  • 柯基犬: 打开此选项会有两条柯基犬在你的工具栏上方游走
  • 猫咪: 打开此选项会有两条猫咪在你的工具栏上方游走
    全部打开,的话…就像这样
    Here Insert Picture Description
Published 18 original articles · won praise 17 · views 7583

Guess you like

Origin blog.csdn.net/qq_39816031/article/details/104640840