debug
看gluoncv网络的笔记
from gluoncv.model_zoo import get_model import mxnet as mx from mxnet import autograd # net = get_model('center_net_resnet50_v1b_coco',pretrained=False, pretrained_base=False) # net = get_model('center_net_resnet50_v1b_dcnv2_coco',pretrained=False, pretrained_base=False) #mxnet1.7版本才开始支持dcnv2 # print(net) # net.initialize() #1.看网络结构 # x = mx.nd.uniform(shape=(1, 3, 512, 512)) # ids, scores, bboxes = net(x) # print(net) #2.看中间层网络输出特征尺寸 # resnet = net.base_network.base_network(mx.sym.var(name="data1")) # decov = net.base_network.deconv(mx.sym.var(name="data2")) # fshape1 = resnet.infer_shape(data1=(1, 3, 512, 512))[1][0] #(1, 2048, 16, 16) # fshape2 = decov.infer_shape(data2=(1, 2048, 16, 16))[1][0] #(1, 64, 128, 128) # # print(fshape1) # print(len(fshape2[0]), fshape2[0]) # print(fshape2[1]) #3.看训练时最后输出结果尺寸 x = mx.nd.uniform(shape=(1, 3, 512, 512)) ids, scores, bboxes = net(x) with autograd.train_mode(): heatmap_pred, wh_pred, center_reg_pred = net(x) print(heatmap_pred.shape, wh_pred.shape, center_reg_pred.shape)
卷积和池化过程中
输出size计算:N=(image_h + 2*pad_h – kernel_h)/stride_h+ 1
N不为整数时:卷积向下取整数,池化向上取整数(不同框架实现不同,mxnet默认卷积和池化都像下取整)
Debug deep learning program¶
In this tutorial we'll walk through some common issues during deep learning application development and methods to resolve.
We pick handwritten digit recognition application with multilayer perceptron as example.
In [ ]:
from __future__ import print_function
import mxnet as mx
from mxnet import gluon
from mxnet.gluon import nn, data
from mxnet import autograd as ag
class Net(gluon.HybridBlock):
def __init__(self, **kwargs):
super(Net, self).__init__(**kwargs)
with self.name_scope():
self.conv1 = nn.Conv2D(20, kernel_size=(5,5))
self.pool1 = nn.MaxPool2D(pool_size=(2,2), strides = (2,2))
self.conv2 = nn.Conv2D(50, kernel_size=(5,5))
self.pool2 = nn.MaxPool2D(pool_size=(2,2), strides = (2,2))
self.fc1 = nn.Dense(500)
self.fc2 = nn.Dense(10)
def hybrid_forward(self, F, x):
x = self.pool1(F.tanh(self.conv1(x)))
print("pool1 output: %s" % str(x))
x = self.pool2(F.tanh(self.conv2(x)))
x = x.reshape((0, -1))
x = F.tanh(self.fc1(x))
x = F.tanh(self.fc2(x))