基本信息
源码名称:深度学习之一:卷积神经网络(CNN)详解与代码实现
源码大小:2.19M
文件格式:.rar
开发语言:Python
更新时间:2019-08-09
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

目录

1.应用场景

2.卷积神经网络结构

 2.1 卷积(convelution)

 2.2 Relu激活函数

 2.3 池化(pool)

 2.4 全连接(full connection)

 2.5 损失函数(softmax_loss)

 2.6 前向传播(forward propagation)

 2.7 反向传播(backford propagation)

 2.8 随机梯度下降(sgd_momentum)

3.代码实现流程图以及介绍

4.代码实现(python3.6)

5.运行结果以及分析

6.参考文献




# -*- coding: utf-8 -*-

try:

  from . import layers

except Exception:

  import layers

 

 

 

 

def affine_relu_forward(x, w, b):

  """

  Convenience layer that perorms an affine transform followed by a ReLU

 

  Inputs:

  - x: Input to the affine layer

  - w, b: Weights for the affine layer

 

  Returns a tuple of:

  - out: Output from the ReLU

  - cache: Object to give to the backward pass

  """

  a, fc_cache = layers.affine_forward(x, w, b)

  out, relu_cache = layers.relu_forward(a)

  cache = (fc_cache, relu_cache)

  return out, cache

 

 

def affine_relu_backward(dout, cache):

  """

  Backward pass for the affine-relu convenience layer

  """

  fc_cache, relu_cache = cache

  da = layers.relu_backward(dout, relu_cache)

  dx, dw, db = layers.affine_backward(da, fc_cache)

  return dx, dw, db

 

 

pass

 

 

def conv_relu_forward(x, w, b, conv_param):

  """

  A convenience layer that performs a convolution followed by a ReLU.

 

  Inputs:

  - x: Input to the convolutional layer

  - w, b, conv_param: Weights and parameters for the convolutional layer

 

  Returns a tuple of:

  - out: Output from the ReLU

  - cache: Object to give to the backward pass

  """

  a, conv_cache = layers.conv_forward_fast(x, w, b, conv_param)

  out, relu_cache = layers.relu_forward(a)

  cache = (conv_cache, relu_cache)

  return out, cache

 

 

def conv_relu_backward(dout, cache):

  """

  Backward pass for the conv-relu convenience layer.

  """

  conv_cache, relu_cache = cache

  da = layers.relu_backward(dout, relu_cache)

  dx, dw, db = layers.conv_backward_fast(da, conv_cache)

  return dx, dw, db

 

 

def conv_relu_pool_forward(x, w, b, conv_param, pool_param):

  """

  Convenience layer that performs a convolution, a ReLU, and a pool.

 

  Inputs:

  - x: Input to the convolutional layer

  - w, b, conv_param: Weights and parameters for the convolutional layer

  - pool_param: Parameters for the pooling layer

 

  Returns a tuple of:

  - out: Output from the pooling layer

  - cache: Object to give to the backward pass

  """

  a, conv_cache = layers.conv_forward_naive(x, w, b, conv_param)

  s, relu_cache = layers.relu_forward(a)

  out, pool_cache = layers.max_pool_forward_naive(s, pool_param)

  cache = (conv_cache, relu_cache, pool_cache)

  return out, cache

 

 

def conv_relu_pool_backward(dout, cache):

  """

  Backward pass for the conv-relu-pool convenience layer

  """

  conv_cache, relu_cache, pool_cache = cache

  ds = layers.max_pool_backward_naive(dout, pool_cache)

  da = layers.relu_backward(ds, relu_cache)

  dx, dw, db = layers.conv_backward_naive(da, conv_cache)

  return dx, dw, db

 

layers.py

import numpy as np

 

'''