资源简介
使用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
相关资源
- BP算法Python代码
- 卷积神经网络人脸识别.txt
- 最详细神经网络python描写附注释
- 基于Python的计算机网络实验设计
- 最新Python3.6网络爬虫实战案例5章(基
- 回声状态网络源码实现
- Python实现一个简单的3层BP神经网络
- python3网络爬虫开发实战 无密码
- Hopfield Neural Network——神经网络pytho
- 自己编写的简单网络协议编辑器,用
- CNN网络识别Mnist的源码,有详细注释,
- zw_基于python的网络爬虫设计.zip
- 5层神经网络带L2正则化的损失函数计
- python3.4爬取网络图片
- BP神经网络_Python实习_包含鸢尾花分类
- 卷积神经网络轴承数故障分类
- GA-BP算法的python实现
- python编写的类似QQ的聊天工具
- 《Python3网络爬虫开发实战》中文PDF
- WebLogic WLS远程执行漏洞(CVE-2017-1027
- 基于LSTM的RNN网络人体骨骼关节点检测
- 时间长短序列网络LSTM
- 利用selenium编写的python网络爬虫-淘宝
- Python3网络爬虫实战思维导图
- 卷积神经网络回归模型
- SRNN python代码实现
- Python 强大的图论和网络研究工具 ne
- python实现网络爬虫 爬取北上广深的天
- Python-Keras实现实时语义分割的深层神
- Python-手势识别使用在TensorFlow中卷积神
评论
共有 条评论