Skip to content

Commit

Permalink
add gluonbook dep, rm sys.append(..)
Browse files Browse the repository at this point in the history
  • Loading branch information
astonzhang committed Jul 23, 2018
1 parent dccdbdb commit b29c626
Show file tree
Hide file tree
Showing 56 changed files with 10 additions and 110 deletions.
1 change: 1 addition & 0 deletions build/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ dependencies:
- recommonmark==0.4.0
- https://github.com/mli/notedown/tarball/master
- mxnet-cu80==1.2.0
- gluonbook==0.7.0
- jieba==0.39
2 changes: 0 additions & 2 deletions chapter_computational-performance/multiple-gpus-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
先导入本节实验需要的包或模块。同上一节,运行本节中的程序需要至少两块GPU。

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

```{.python .input}
import sys
sys.path.append('..')
import gluonbook as gb
import mxnet as mx
from mxnet import autograd, nd
Expand Down
2 changes: 0 additions & 2 deletions chapter_computer-vision/anchor.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

```{.python .input n=1}
%matplotlib inline
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import contrib, gluon, image, nd
import numpy as np
Expand Down
2 changes: 0 additions & 2 deletions chapter_computer-vision/bounding-box.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

```{.python .input n=1}
%matplotlib inline
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import image
```
Expand Down
3 changes: 1 addition & 2 deletions chapter_computer-vision/fcn.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

```{.python .input n=1}
%matplotlib inline
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import gluon, init, nd, image
from mxnet.gluon import data as gdata, loss as gloss, model_zoo, nn
import numpy as np
import sys
```

## 转置卷积层
Expand Down
2 changes: 0 additions & 2 deletions chapter_computer-vision/fine-tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

```{.python .input n=4}
%matplotlib inline
import sys
sys.path.insert(0, '..')
import zipfile
import gluonbook as gb
from mxnet import gluon, init, nd
Expand Down
2 changes: 0 additions & 2 deletions chapter_computer-vision/image-augmentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

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

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

```{.python .input}
import sys
sys.path.append('..')
import collections
import datetime
import gluonbook as gb
Expand Down
4 changes: 1 addition & 3 deletions chapter_computer-vision/neural-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

```{.python .input}
%matplotlib inline
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import autograd, gluon, image, nd
from mxnet.gluon import model_zoo, nn
Expand Down Expand Up @@ -256,4 +254,4 @@ gb.plt.imsave('../img/neural-style-2.png', postprocess(z).asnumpy())

## 参考文献

[1] Gatys, Leon A., Alexander S. Ecker, and Matthias Bethge. "Image style transfer using convolutional neural networks." CVPR. 2016.
[1] Gatys, L. A., Ecker, A. S., & Bethge, M. (2016). Image style transfer using convolutional neural networks. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (pp. 2414-2423).
2 changes: 0 additions & 2 deletions chapter_computer-vision/object-detection-dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

```{.python .input n=1}
%matplotlib inline
import sys
sys.path.insert(0, '..')
import gluonbook as gb
from mxnet import gluon, image
from mxnet.gluon import utils as gutils
Expand Down
3 changes: 1 addition & 2 deletions chapter_computer-vision/semantic-segmentation-and-dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@

```{.python .input n=1}
%matplotlib inline
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import gluon, image, nd
from mxnet.gluon import data as gdata, utils as gutils
import os
import sys
import tarfile
```

Expand Down
2 changes: 0 additions & 2 deletions chapter_computer-vision/ssd.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

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

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

```{.python .input n=1}
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import nd, gluon, init
from mxnet.gluon import loss as gloss, nn
Expand Down
2 changes: 0 additions & 2 deletions chapter_convolutional-neural-networks/batch-norm.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ $$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
2 changes: 0 additions & 2 deletions chapter_convolutional-neural-networks/conv-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
下面我们将上述过程实现在`corr2d`函数里,它接受`X``K`,输出`Y`

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

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

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

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

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

```{.python .input n=5}
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import autograd, gluon, init, nd
from mxnet.gluon import loss as gloss, nn
Expand Down
2 changes: 0 additions & 2 deletions chapter_deep-learning-basics/dropout.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ $$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.append('..')
import gluonbook as gb
from mxnet import autograd, gluon, nd
from mxnet.gluon import loss as gloss
Expand Down
2 changes: 0 additions & 2 deletions chapter_deep-learning-basics/kaggle-house-price.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ Kaggle(网站地址:https://www.kaggle.com )是一个著名的供机器学

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

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

```{.python .input}
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import autograd, gluon, nd
from mxnet.gluon import loss as gloss
Expand Down
2 changes: 0 additions & 2 deletions chapter_deep-learning-basics/mlp.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ $$\text{relu}(x) = \max(x, 0).$$
```{.python .input}
# 将图打印在 Jupyter notebook 的文本之间。
%matplotlib inline
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import nd
Expand Down
2 changes: 0 additions & 2 deletions chapter_deep-learning-basics/softmax-regression-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
首先导入本节实现所需的包或模块。

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

```{.python .input n=1}
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import autograd, nd
from mxnet.gluon import data as gdata
import sys
```

## 获取Fashion-MNIST数据集
Expand Down
2 changes: 0 additions & 2 deletions chapter_deep-learning-basics/underfit-overfit.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ $$\hat{y} = b + \sum_{k=1}^K x^k w_k$$

```{.python .input}
%matplotlib inline
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import autograd, gluon, nd
from mxnet.gluon import data as gdata, loss as gloss, nn
Expand Down
2 changes: 0 additions & 2 deletions chapter_deep-learning-basics/weight-decay-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

```{.python .input n=1}
%matplotlib inline
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import autograd, gluon, init, nd
from mxnet.gluon import data as gdata, loss as gloss, nn
Expand Down
2 changes: 0 additions & 2 deletions chapter_deep-learning-basics/weight-decay.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ $$y = 0.05 + \sum_{i = 1}^p 0.01x_i + \epsilon,$$

```{.python .input n=2}
%matplotlib inline
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import autograd, gluon, nd
Expand Down
4 changes: 2 additions & 2 deletions chapter_natural-language-processing/sentiment-analysis-cnn.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 文本分类:情感分析

TODO(@astonzhang): edits

在之前的章节中介绍了卷积神经网络用于计算机视觉领域。
在本节将介绍如何将卷积神经网络应用于自然语言处理领域。以及参考textCNN模型使用Gluon创建一个卷积神经网络用于文本情感分类。

Expand All @@ -24,8 +26,6 @@
在实验开始前,导入所需的包或模块。

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

```{.python .input n=1}
import sys
sys.path.append('..')
import collections
import gluonbook as gb
import mxnet as mx
Expand Down
2 changes: 0 additions & 2 deletions chapter_optimization/adadelta-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

```{.python .input}
%matplotlib inline
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import gluon, init, nd
from mxnet.gluon import nn
Expand Down
2 changes: 0 additions & 2 deletions chapter_optimization/adadelta.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def adadelta(params, sqrs, deltas, rho, batch_size):

```{.python .input}
%matplotlib inline
import sys
sys.path.append('..')
import gluonbook as gb
from mxnet import autograd, nd
import numpy as np
Expand Down
2 changes: 0 additions & 2 deletions chapter_optimization/adagrad-gluon.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

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

0 comments on commit b29c626

Please sign in to comment.