Skip to content

Commit

Permalink
add import sys, sys.path.insert(0, ..), rm gluonbook dep in env
Browse files Browse the repository at this point in the history
  • Loading branch information
astonzhang committed Jul 31, 2018
1 parent bfdb8b3 commit a8630b0
Show file tree
Hide file tree
Showing 55 changed files with 160 additions and 2 deletions.
1 change: 0 additions & 1 deletion build/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ dependencies:
- recommonmark==0.4.0
- https://github.com/mli/notedown/tarball/master
- mxnet-cu80==1.2.1
- gluonbook==0.7.4
- jieba==0.39
4 changes: 4 additions & 0 deletions build/build_doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ conda env update -f build/build.yml

conda activate gluon_zh_docs


pip uninstall gluonbook


pip list

make html
Expand Down
3 changes: 3 additions & 0 deletions chapter_computational-performance/multiple-gpus-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
先导入本节实验需要的包或模块。同上一节,运行本节中的程序需要至少两块GPU。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
import mxnet as mx
from mxnet import autograd, gluon, init, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_computational-performance/multiple-gpus.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
为了从零开始实现多GPU训练中的数据并行,让我们先导入需要的包或模块。

```{.python .input}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
import mxnet as mx
from mxnet import autograd, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_computer-vision/anchor.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
导入本小节需要的包。注意我们新引入了`contrib`这个模块,以及使用numpy修改了打印精度,这是因为NDArray的打印实际上调用了numpy的打印函数。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import contrib, gluon, image, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_computer-vision/bounding-box.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
在接下来的数小节里我们将介绍物体检测里的多个深度学习模型。在此之前,让我们先讨论物体位置这个概念。首先导入本节实验所需的包或模块。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import image
Expand Down
3 changes: 3 additions & 0 deletions chapter_computer-vision/fcn.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
但在语义分割里,我们需要对每个像素预测类别,也就是需要输出形状需要是$1000\times 224\times 224$。如果仍然使用全连接层作为输出,那么这一层权重将多达数百GB。本小节我们将介绍利用卷积神经网络解决语义分割的一个开创性工作之一:全卷积网络(fully convolutional network,简称FCN)[1]。FCN里将最后的全连接层修改称转置卷积层(transposed convolution)来得到所需大小的输出。

```{.python .input n=2}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import gluon, init, nd, image
Expand Down
3 changes: 3 additions & 0 deletions chapter_computer-vision/fine-tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
我们首先将数据下载到`../data`。在当前目录解压后得到`hotdog/train``hotdog/test`这两个文件夹。每个下面有`hotdog``not-hotdog`这两个类别文件夹,里面是对应的图片文件。

```{.python .input n=4}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import zipfile
import gluonbook as gb
Expand Down
3 changes: 3 additions & 0 deletions chapter_computer-vision/image-augmentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
首先,导入本节实验所需的包或模块。

```{.python .input n=21}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
import mxnet as mx
Expand Down
3 changes: 3 additions & 0 deletions chapter_computer-vision/kaggle-gluon-cifar10.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ CIFAR-10是计算机视觉领域的一个重要的数据集。本节中,我们
首先,导入实验所需的包或模块。

```{.python .input}
import sys
sys.path.insert(0, '..')
import datetime
import gluonbook as gb
from mxnet import autograd, gluon, init
Expand Down
3 changes: 3 additions & 0 deletions chapter_computer-vision/kaggle-gluon-dog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
首先,导入实验所需的包或模块。

```{.python .input}
import sys
sys.path.insert(0, '..')
import collections
import datetime
import gluonbook as gb
Expand Down
3 changes: 3 additions & 0 deletions chapter_computer-vision/neural-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
![使用神经网络进行样式迁移。](../img/neural-style.svg)

```{.python .input}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import autograd, gluon, image, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_computer-vision/object-detection-dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
打包好的数据集可以直接在网上下载。下载数据集的操作定义在`_download_pikachu`函数中。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import gluon, image
Expand Down
3 changes: 3 additions & 0 deletions chapter_computer-vision/semantic-segmentation-and-dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
[Pascal VOC2012](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/)来介绍这个应用。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import gluon, image, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_computer-vision/ssd.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
我们将介绍的第一个模型是单发多框检测(single shot multibox detection,简称SSD)[1]。它并不是第一个提出来的基于深度学习的物体检测模型,也不是精度最高的,但因为其简单快速而被大量使用。我们将使用SSD来详解目标检测的实现细节。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import autograd, contrib, gluon, image, init, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_convolutional-neural-networks/alexnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ AlextNet与LeNet的设计理念非常相似。但也有非常显著的区别。
下面我们实现(稍微简化过的)Alexnet:

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import nd, init, gluon
from mxnet.gluon import data as gdata, loss as gloss, nn
Expand Down
3 changes: 3 additions & 0 deletions chapter_convolutional-neural-networks/batch-norm-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
相比于前小节定义的BatchNorm类,`nn`模块定义的BatchNorm使用更加简单。它不需要指定输出数据的维度和特征维的大小,这些都将通过延后初始化来获取。我们实现同前小节一样的批量归一化的LeNet。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import gluon, init
from mxnet.gluon import loss as gloss, nn
Expand Down
3 changes: 3 additions & 0 deletions chapter_convolutional-neural-networks/batch-norm.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ $$y_i \leftarrow \gamma \hat{x}_i + \beta.$$
下面我们通过NDArray来实现这个计算。

```{.python .input n=72}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import nd, gluon, init, autograd
from mxnet.gluon import loss as gloss, nn
Expand Down
3 changes: 3 additions & 0 deletions chapter_convolutional-neural-networks/densenet.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ DenseNet的主要构建模块是稠密块和过渡块,前者定义了输入和
DeseNet使用了ResNet改良版的“批量归一化、激活和卷积”结构(参见上一节习题),我们首先在`conv_block`函数里实现这个结构。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import nd, gluon, init
from mxnet.gluon import loss as gloss, nn
Expand Down
3 changes: 3 additions & 0 deletions chapter_convolutional-neural-networks/googlenet.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ GoogLeNet中的基础卷积块叫做Inception,得名于同名电影《盗梦
Inception块中可以自定义的超参数是每个层的输出通道数,我们以此来控制模型复杂度。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import nd, init, gluon
from mxnet.gluon import loss as gloss, nn
Expand Down
3 changes: 3 additions & 0 deletions chapter_convolutional-neural-networks/lenet.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ LeNet分为卷积层块和全连接层块两个部分。卷积层块里的基本
卷积层块把每个样本输出拉升成向量输入到全连接层块中。全连接层块由两个输出大小分别为120和84的全连接层,然后接上输出大小为10(因为数字的类别一共为10)的输出层构成。下面我们通过Sequential类来实现LeNet。

```{.python .input}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
import mxnet as mx
from mxnet import autograd, nd, gluon, init
Expand Down
3 changes: 3 additions & 0 deletions chapter_convolutional-neural-networks/nin.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
NiN中的一个基础块由一个卷积层外加两个充当全连接层的$1\times 1$卷积层构成。第一个卷积层我们可以设置它的超参数,而第二和第三卷积层则使用固定超参数。

```{.python .input n=2}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import nd, gluon, init
from mxnet.gluon import loss as gloss, nn
Expand Down
3 changes: 3 additions & 0 deletions chapter_convolutional-neural-networks/resnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ ResNet沿用了VGG全$3\times 3$卷积层设计。残差块里首先是两个有
残差块的实现如下。它可以设定输出通道数,是否使用额外的卷积层来修改输入通道数,以及卷积层的步幅大小。我们将`Residual`类定义在`gluonbook`包中供后面章节调用。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import nd, gluon, init
from mxnet.gluon import loss as gloss, nn
Expand Down
3 changes: 3 additions & 0 deletions chapter_convolutional-neural-networks/vgg.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ AlexNet在LeNet的基础上增加了三个卷积层。但作者对它们的卷
VGG模型的基础组成规律是:连续使用数个相同的填充为1的$3\times 3$卷积层后接上一个步幅为2的$2\times 2$最大池化层。卷积层保持输入高宽,而池化层则对其减半。我们使用`vgg_block`函数来实现这个基础块,它可以指定使用卷积层的数量和其输出通道数。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import nd, init, gluon
from mxnet.gluon import loss as gloss, nn
Expand Down
3 changes: 3 additions & 0 deletions chapter_deep-learning-basics/dropout-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
在多层感知机中Gluon实现的基础上,我们只需要在全连接层后添加Dropout层并指定丢弃概率。在训练模型时,Dropout层将以指定的丢弃概率随机丢弃上一层的输出元素;在测试模型时,Dropout层并不发挥作用。

```{.python .input n=5}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import gluon, init
from mxnet.gluon import loss as gloss, nn
Expand Down
3 changes: 3 additions & 0 deletions chapter_deep-learning-basics/dropout.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ $$h_i = \frac{\xi_i}{1-p} \phi(x_1 w_1^{(i)} + x_2 w_2^{(i)} + x_3 w_3^{(i)} + x
根据丢弃法的定义,我们可以很容易地实现它。下面的`dropout`函数将以`drop_prob`的概率丢弃NDArray输入`X`中的元素。

```{.python .input}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import autograd, nd
from mxnet.gluon import loss as gloss
Expand Down
3 changes: 3 additions & 0 deletions chapter_deep-learning-basics/kaggle-house-price.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Kaggle(网站地址:https://www.kaggle.com )是一个著名的供机器学
下面,我们通过使用`pandas`读入数据。请确保已安装`pandas` (命令行执行`pip install pandas`)。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import autograd, init, gluon, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_deep-learning-basics/mlp-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
下面我们使用Gluon来实现上一节中的多层感知机。首先我们导入所需的包或模块。

```{.python .input}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import gluon, init
from mxnet.gluon import loss as gloss, nn
Expand Down
3 changes: 3 additions & 0 deletions chapter_deep-learning-basics/mlp-scratch.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
我们已经从上一章里了解了多层感知机的原理。下面,我们一起来动手实现一个多层感知机。首先导入实现所需的包或模块。

```{.python .input}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import nd
from mxnet.gluon import loss as gloss
Expand Down
3 changes: 3 additions & 0 deletions chapter_deep-learning-basics/mlp.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ $$\text{relu}(x) = \max(x, 0).$$
可以看出,ReLU函数只保留正数元素,并将负数元素清零。为了直观地观察这一非线性变换,我们先定义一个绘图函数`xyplot`

```{.python .input}
import sys
sys.path.insert(0, '..')
# 将图打印在 Jupyter notebook 的文本之间。
%matplotlib inline
import gluonbook as gb
Expand Down
3 changes: 3 additions & 0 deletions chapter_deep-learning-basics/softmax-regression-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
首先导入本节实现所需的包或模块。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import gluon, init
from mxnet.gluon import loss as gloss, nn
Expand Down
3 changes: 3 additions & 0 deletions chapter_deep-learning-basics/softmax-regression-scratch.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
下面我们来动手实现Softmax回归。首先,导入实验所需的包或模块。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import autograd, nd
from mxnet.gluon import data as gdata
Expand Down
3 changes: 3 additions & 0 deletions chapter_deep-learning-basics/underfit-overfit.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ $$\hat{y} = b + \sum_{k=1}^K x^k w_k$$
为了理解模型复杂度和训练数据集大小对欠拟合和过拟合的影响,下面我们以多项式函数拟合为例来实验。首先导入实现需要的包或模块。

```{.python .input}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import autograd, gluon, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_deep-learning-basics/weight-decay-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
本节将介绍如何使用Gluon实现上一节介绍的权重衰减。首先导入实验所需的包或模块。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import autograd, gluon, init, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_deep-learning-basics/weight-decay.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ $$y = 0.05 + \sum_{i = 1}^p 0.01x_i + \epsilon,$$
其中噪音项$\epsilon$服从均值为0和标准差为0.1的正态分布。为了较容易地观察过拟合,我们考虑高维线性回归问题,例如设维度$p=200$;同时,我们特意把训练数据集的样本数设低,例如20。

```{.python .input n=2}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import autograd, gluon, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_natural-language-processing/sentiment-analysis-cnn.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ TODO(@astonzhang): edits
在实验开始前,导入所需的包或模块。

```{.python .input n=27}
import sys
sys.path.insert(0, '..')
import collections
import gluonbook as gb
from mxnet import autograd, gluon, init, metric, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_natural-language-processing/sentiment-analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
在实验开始前,导入所需的包或模块。

```{.python .input n=1}
import sys
sys.path.insert(0, '..')
import collections
import gluonbook as gb
from mxnet import autograd, gluon, init, metric, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_optimization/adadelta-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
首先,导入本节中实验所需的包或模块。

```{.python .input}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import gluon, init, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_optimization/adadelta.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def adadelta(params, sqrs, deltas, rho, batch_size):
首先,导入本节中实验所需的包或模块。

```{.python .input}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import autograd, nd
Expand Down
3 changes: 3 additions & 0 deletions chapter_optimization/adagrad-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
首先,导入本节中实验所需的包或模块。

```{.python .input}
import sys
sys.path.insert(0, '..')
%matplotlib inline
import gluonbook as gb
from mxnet import gluon, init, nd
Expand Down
Loading

0 comments on commit a8630b0

Please sign in to comment.