资源简介
使用python编写,代码简单,清晰,非常适合新手的入门!

代码片段和文件信息
from layer_utils import *
class ThreelayerConvNet(object):
“““
A three-layer convolutional network with the following architecture:
conv - relu - 2x2 max pool - affine - relu - affine - softmax
“““
def __init__(self input_dim=(3 32 32) num_filters=32 filter_size=7
hidden_dim=100 num_classes=10 weight_scale=1e-3 reg=0.0
dtype=np.float32):
self.params = {}
self.reg = reg
self.dtype = dtype
# Initialize weights and biases
C H W = input_dim
self.params[‘W1‘] = weight_scale * np.random.randn(num_filters C filter_size filter_size)
self.params[‘b1‘] = np.zeros(num_filters)
self.params[‘W2‘] = weight_scale * np.random.randn(num_filters*H*W/4 hidden_dim)
self.params[‘b2‘] = np.zeros(hidden_dim)
self.params[‘W3‘] = weight_scale * np.random.randn(hidden_dim num_classes)
self.params[‘b3‘] = np.zeros(num_classes)
for k v in self.params.iteritems():
self.params[k] = v.astype(dtype)
def loss(self X y=None):
W1 b1 = self.params[‘W1‘] self.params[‘b1‘]
W2 b2 = self.params[‘W2‘] self.params[‘b2‘]
W3 b3 = self.params[‘W3‘] self.params[‘b3‘]
# pass conv_param to the forward pass for the convolutional layer
filter_size = W1.shape[2]
conv_param = {‘stride‘: 1 ‘pad‘: (filter_size - 1) / 2}
# pass pool_param to the forward pass for the max-pooling layer
pool_param = {‘pool_height‘: 2 ‘pool_width‘: 2 ‘stride‘: 2}
# compute the forward pass
a1 cache1 = conv_relu_pool_forward(X W1 b1 conv_param pool_param)
a2 cache2 = affine_relu_forward(a1 W2 b2)
scores cache3 = affine_forward(a2 W3 b3)
if y is None:
return scores
# compute the backward pass
data_loss dscores = softmax_loss(scores y)
da2 dW3 db3 = affine_backward(dscores cache3)
da1 dW2 db2 = affine_relu_backward(da2 cache2)
dX dW1 db1 = conv_relu_pool_backward(da1 cache1)
# Add regularization
dW1 += self.reg * W1
dW2 += self.reg * W2
dW3 += self.reg * W3
reg_loss = 0.5 * self.reg * sum(np.sum(W * W) for W in [W1 W2 W3])
loss = data_loss + reg_loss
grads = {‘W1‘: dW1 ‘b1‘: db1 ‘W2‘: dW2 ‘b2‘: db2 ‘W3‘: dW3 ‘b3‘: db3}
return loss grads
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2491 2017-01-04 13:06 cnn.py
文件 6884 2017-01-04 14:37 data_utils.py
文件 2410 2017-01-04 12:45 la
文件 7691 2017-01-04 14:41 la
文件 3966 2017-01-03 12:05 optim.py
文件 9587 2017-01-04 14:35 solver.py
文件 1668 2017-01-04 16:45 start.py
相关资源
- 神经网络用于分类
- 基于python的三层神经网络模型搭建
- 中国城市经纬度爬虫.ipynb
- 012345手势识别神经网络代码
- numpy实现BP神经网络
- 卷积神经网络在医学图像分割中的研
- 神经网络gcn代码
- 神经网络拟合曲线
- 神经网络预测控制
- 中山大学-自然语言处理-中文分词项目
- 利用CNN网络实现mnist图像分类,手动实
- 网络爬虫(pachong_anjuke.py)
- python网络爬虫获取景点信息源码
- 西电python网络处理上机题答案
- Python网络编程 3版 高清扫描版 完整中
- Python数据爬虫及可视化分析
- 卷积神经网络图像识别python代码pdf
- Python网络爬虫实战.epub
- 贝叶斯网络程序
- 卷积神经网络python
- python网络爬虫爬取整个网页
- Python-在特征金字塔网络FPN的Pytorch实现
- Python-PyTorch对卷积CRF的参考实现
- Python-Keras实现Inceptionv4InceptionResnetv1和
- Python-FastSCNN的PyTorch实现快速语义分割
- Python-subpixel利用Tensorflow的一个子像素
-
Python-汉字的神经风格转移Neuralst
y - Python-神经网络模型能够从音频演讲中
- OCR:一个有趣的网页版手写数字识别
- NeMo_脉冲神经网络工具_spiking neural n
评论
共有 条评论