使用重复元素的网络(VGG) 讨论区


#1

http://zh.diveintodeeplearning.org/chapter_convolutional-neural-networks/vgg.html


于置顶 #2

#3

示例教程有误?运行后报错

TypeError Traceback (most recent call last)
in ()
11 batch_size = 64
12 train_data, test_data = utils.load_data_fashion_mnist(
—> 13 batch_size, transform)
14
15 from mxnet import autograd

TypeError: load_data_fashion_mnist() takes 1 positional argument but 2 were given


#4

我更新了下 根目录下的 utils.py


#5

试试更新下教程


#6

请问一个batch的gradient求和后会取平均吗?
我测了一下backward函数,好像不会取平均
如果default是不取平均,那如果增大batch size, 是不是需要减小learning rate?


#7

Gluon一般在更新参数的时候对gradient求平均:https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/gluon/trainer.py#L154
当然也可以在算loss的时候直接求平均。


#8

多谢,看来跟backward的default behavior不一样


#9

报错啊,Traceback (most recent call last):
File “D:/pycharm/mxnet_kc/kc_3/5.py”, line 48, in
utils.train(train_data, test_data, net, loss,trainer, ctx, num_epochs=1)
File “D:\pycharm\mxnet_kc\utils.py”, line 58, in train
output = net(data.as_in_context(ctx))
File “C:\Users\guoyunpeng.it\AppData\Local\Continuum\Anaconda2\lib\site-packages\mxnet\gluon\block.py”, line 287, in call
return self.forward(*args)
File “C:\Users\guoyunpeng.it\AppData\Local\Continuum\Anaconda2\lib\site-packages\mxnet\gluon\nn\basic_layers.py”, line 46, in forward
x = block(x)
File “C:\Users\guoyunpeng.it\AppData\Local\Continuum\Anaconda2\lib\site-packages\mxnet\gluon\block.py”, line 287, in call
return self.forward(*args)
File “C:\Users\guoyunpeng.it\AppData\Local\Continuum\Anaconda2\lib\site-packages\mxnet\gluon\nn\basic_layers.py”, line 46, in forward
x = block(x)
File “C:\Users\guoyunpeng.it\AppData\Local\Continuum\Anaconda2\lib\site-packages\mxnet\gluon\block.py”, line 287, in call
return self.forward(*args)
File “C:\Users\guoyunpeng.it\AppData\Local\Continuum\Anaconda2\lib\site-packages\mxnet\gluon\nn\basic_layers.py”, line 46, in forward
x = block(x)
File “C:\Users\guoyunpeng.it\AppData\Local\Continuum\Anaconda2\lib\site-packages\mxnet\gluon\block.py”, line 287, in call
return self.forward(*args)
File “C:\Users\guoyunpeng.it\AppData\Local\Continuum\Anaconda2\lib\site-packages\mxnet\gluon\block.py”, line 429, in forward
return self.hybrid_forward(ndarray, x, *args, **params)
File “C:\Users\guoyunpeng.it\AppData\Local\Continuum\Anaconda2\lib\site-packages\mxnet\gluon\nn\conv_layers.py”, line 669, in hybrid_forward
return F.Pooling(x, name=‘fwd’, **self._kwargs)
File “”, line 31, in Pooling
File “C:\Users\guoyunpeng.it\AppData\Local\Continuum\Anaconda2\lib\site-packages\mxnet_ctypes\ndarray.py”, line 92, in imperative_invoke
ctypes.byref(out_stypes)))
File “C:\Users\guoyunpeng.it\AppData\Local\Continuum\Anaconda2\lib\site-packages\mxnet\base.py”, line 143, in check_call
raise MXNetError(py_str(LIB.MXGetLastError()))
mxnet.base.MXNetError: [15:27:34] c:\projects\mxnet-distro-win\mxnet-build\src\operator./pooling-inl.h:214: Check failed: param
.kernel[0] <= dshape[2] + 2 * param
.pad[0] kernel size (2) exceeds input (1 padded to 1)


#10

对比了一下代码 都一样啊 为什么会报这个错误呢????


#11

怎样更新教程


#12

参考http://zh.gluon.ai/chapter_prerequisite/install.html里新加的一节


#13

谢谢, 已经查看


#14

分享一个用VGG刷FashionMnist的网络,迭代了100轮,测试准确率可以达到0.953以上。

from mxnet.gluon import nn
from mxnet import nd
from mxnet import gluon
from mxnet import init
import sys
sys.path.append('..')
import utils

net = nn.Sequential()
with net.name_scope():
    net.add(
        nn.Conv2D(channels=32, kernel_size=3, padding=1),
        nn.BatchNorm(axis=1),
        nn.Activation(activation='relu'),
        nn.Dropout(0.2),
        nn.Conv2D(channels=32, kernel_size=3, padding=1),
        nn.BatchNorm(axis=1),
        nn.Activation(activation='relu'),
        nn.MaxPool2D(pool_size=2),
        nn.Dropout(0.5),
        
        nn.Conv2D(channels=64, kernel_size=3, padding=1),
        nn.BatchNorm(axis=1),
        nn.Activation(activation='relu'),
        nn.Dropout(0.2),
        nn.Conv2D(channels=64, kernel_size=3, padding=1),
        nn.BatchNorm(axis=1),
        nn.Activation(activation='relu'),
        nn.MaxPool2D(pool_size=2),
        nn.Dropout(0.5),
        
        nn.Flatten(),
        
        nn.Dense(256),
        nn.BatchNorm(axis=1),
        nn.Activation(activation='relu'),
        nn.Dropout(0.5),
        
        nn.Dense(256),
        nn.BatchNorm(axis=1),
        nn.Activation(activation='relu'),
        nn.Dropout(0.5),
        
        nn.Dense(10)
    )
net.initialize(ctx=ctx, init=init.Xavier())
train_data, test_data = utils.load_data_fashion_mnist(batch_size=512)
loss = gluon.loss.SoftmaxCrossEntropyLoss()
trainer = gluon.Trainer(net.collect_params(),'adam', {'learning_rate': 0.001})  
utils.train(train_data, test_data, net, loss, trainer, ctx, num_epochs=100)

主要是Dropout层起了作用,如果不加Dropout,差不多只有0.94左右


#15

QQ截图20171021233635

默认的代码,没改过。。。大佬们日常写bug?坏笑


#16

参考这里的说明更新一下 http://zh.gluon.ai/chapter_preface/install.html


#17

木有看出来要怎么弄,求大佬指教。。。吃


#18

按照上面页面的"更新教程"部分做一下


#19

image
是这里吗?下载那个zip包。。。我更新过了。。。还是一样报错。。。


#20

你是不是git clone下来的,如果是的话可以直接git pull,然后merge就行了
如果不是的话,你可以先把gluon-zh那个文件夹删了,然后按照image这个方式重新生成一次就好了;
或者下载下来解压以后直接create试一试,应该是有一种可以用的。(我用的是中间这一种)