
资料内容:
用卷积神经网络做图像识别
这个ipython notebook会搭建一个2层的卷积神经网络,然后在CIFAR-10是上测验效果。
我们在文件nn/classifiers/convnet.py中实现了two_layer_convnet函数,可以对2层的卷积神经
网络计算损失和梯度。需要稍微注意一下的是,这里用的是nn/layer_utils.py文件中定义
的"sandwich"层(即把卷积层,激励层,全连接层合在一个层里了)。
In [1l:
#准备工作
import numpy as np
import matplotlib.pyplot as,plt
from nn.classifier_trainer import ClassifierTrainer
from nn.gradient_check import eval_numerical_gradient
from nn.classifiers.convnet import *
matplotlib inline
plt.rcParams['figure.figsize'] = (l0.0, 8.0) # set default size of plots
plt.rcParams['image.interpolation'] ='nearest'
plt.rcParams['image.cmap'] ='gray'
# for auto-reloading external modules
#_see http://stackoverflow.com/questions/19o7993/autoreload-of-modules-in-ipython
&load_ext autoreload
sautoreload 2
def rel_error(x, y):
*.*returns relative error"""
return np.max (np.abs (x - y) / (np.maximum (le-18, np.abs (x) + np.abs (y))))