欢迎!


#21

discourse


#22

是的 手机端体验特别好


#23

discorse


#24

最近发现这个论坛和教程的网址都经常出现访问非常慢,或者无法访问,请问网站服务器是在国内吗?大家有遇到这个情况吗?


#25

开会期间的缘故?


#26

有可能是吧,等开会完了之后再观察看看:joy:


#27

大家好,为了解决 exp 结果过大的问题,我每次把 X - max(X),但是训练的时候遇到了点麻烦~~请大家给点建议

from mxnet import nd
import numpy as np
def softmax(X):
    tmp = X.asnumpy()
    tmp = nd.array(tmp.max(axis=1)[:, np.newaxis])
    X -= tmp
    exp = nd.exp(X)
    # 假设exp是矩阵,这里对行进行求和,并要求保留axis 1,
    # 就是返回 (nrows, 1) 形状的矩阵
    partition = exp.sum(axis=1, keepdims=True)
    return exp / partition

训练的时候报错:

MXNetError: [00:42:45] src/imperative/imperative.cc:192: Check failed: AGInfo::IsNone(*(outputs[i])) Assigning to NDArrays that are already in a computational graph will cause undefined behavior when evaluating gradients. Please call backward first to clear the graph or do this out side of a record section.


#28

问题是出在in-place操作,X -= tmp,把它改成X = X - tmp就可以了


#29

好的,多谢 :)


#30
from mxnet.gluon import nn
import mxnet as mx
ctx = mx.gpu()
def layer1():
out=nn.Sequential()
for channels in range(3):
out.add(nn.Conv2D(channels=32*2**channels,kernel_size=3))
out.add(nn.BatchNorm(axis=1))
out.add(nn.Activation(activation='relu'))
out.add(nn.Conv2D(channels=32*2**channels,kernel_size=3))
out.add(nn.BatchNorm(axis=1))
out.add(nn.Activation(activation='relu'))
out.add(nn.MaxPool2D(pool_size=2))
out.add(nn.Flatten(),nn.Dropout(0.25))
return out
class Conv(nn.Block):
def __init__(self,n,**kwargs):
super(Conv,self).__init__(**kwargs)
self.dense0=layer1()
self.dense1 = nn.Dense(n, activation='relu')
def forward(self,x):
x=self.dense0(x)
p1 = nd.argmax(nd.softmax(self.dense1(x)),axis = 1)
p2 = nd.argmax(nd.softmax(self.dense1(x)),axis = 1)
p3 = nd.argmax(nd.softmax(self.dense1(x)),axis = 1)
p4 = nd.argmax(nd.softmax(self.dense1(x)),axis = 1)
p5 = nd.argmax(nd.softmax(self.dense1(x)),axis = 1)
p6 = nd.argmax(nd.softmax(self.dense1(x)),axis = 1)
p7 = nd.argmax(nd.softmax(self.dense1(x)),axis = 1)
p8 = nd.argmax(nd.softmax(self.dense1(x)),axis = 1)

#print(nd.stack(p1, p2, p3, p4,p5,p6,p7,p8, axis=1))
return nd.stack(p1, p2, p3, p4,p5,p6,p7,p8, axis=1)
net = nn.Sequential()
with net.name_scope():
net.add(Conv(13))


from mxnet import init
net.initialize(ctx=ctx,init=init.Xavier())
softmax_cross_entropy = gluon.loss.SoftmaxCrossEntropyLoss()

trainer = gluon.Trainer(net.collect_params(), 'adam', {'learning_rate': 1e-4, 'wd': 1e-5})

from mxnet import autograd
for epoch in range(50):
train_loss = 0.
train_acc = 0.
steps = len(data_iter_train)
for data, label in data_iter_train:
data, label = data.as_in_context(ctx), label.as_in_context(ctx)
print(data.shape)
with autograd.record():
    output = net(data)
    loss = gluon.loss.SoftmaxCrossEntropyLoss()(output,label)
loss.backward()
trainer.step(batch_size)
train_loss += nd.mean(loss).asscalar()

train_acc += accuracy(output, label)
print(data_iter_val.shape)
val_loss, val_acc = evaluate(net, data_iter_val)
print("Epoch %d. loss: %.4f, acc: %.2f%%, val_loss %.4f, val_acc %.2f%%" % (
epoch+1, train_loss/steps, train_acc/steps*100, val_loss, val_acc*100))

错误如下:loss那一行:
MXNetError: Shape inconsistent, Provided=[16,8], inferred shape=[16,1]
怎么解决?

#31

今天开始学习啦


#32

学习了。。。感谢!


#33

Thanks


#34

相见恨晚啊