当前位置:   article > 正文

解读Depth Map Prediction from a Single Image using a Multi-Scale Deep Network (4)_peeking behind objects: layered depth prediction f

peeking behind objects: layered depth prediction from a single image

解读Depth Map Prediction from a Single Image using a Multi-Scale Deep Network (4)


上次把CNN卷积网络的结构作了介绍,这次仍然分析这篇博文,点击打开链接

来学习卷积神经网络的训练


训练原理:利用链式求导,计算损失函数对每一个权重的偏导数,然后根据梯度下降公式更新权重,依然是反向

                       传播算法


反向传播算法三个步骤:

1,前向计算每个神经元的输出值

2,反向计算每个神经元的误差项(也叫误差传递),即网络损失函数对该神经元加权输入的偏导数

3,计算每个神经元连接权重的梯度


卷积网络的训练:

1,卷积层训练:

       用反向传播的原理计算filter每个权值的梯度

       步长为2的情况,通过补零,转化为步长为1的情况

       输入深度为D的误差传递

       filter数量为N的误差传递

       filter权重梯度的计算

2,Pooling层的训练:

       Pooling层没有需要学习的参数,它需要做的仅仅是讲误差项传递到上一层,而没有梯度计算


写到这里,我不得不感谢这篇博客,教会我CNN的基础架构和反向传播算法


理论上大体明白了CNN网络,可以看一下CNN网络的Python实现

卷积层的初始化:

  1. class ConvLayer(object):
  2. def __init__(self, input_width, input_height,
  3. channel_number, filter_width,
  4. filter_height, filter_number,
  5. zero_padding, stride, activator,
  6. learning_rate):
  7. self.input_width = input_width
  8. self.input_height = input_height
  9. self.channel_number = channel_number
  10. self.filter_width = filter_width
  11. self.filter_height = filter_height
  12. self.filter_number = filter_number
  13. self.zero_padding = zero_padding
  14. self.stride = stride
  15. self.output_width = \
  16. ConvLayer.calculate_output_size(
  17. self.input_width, filter_width, zero_padding,
  18. stride)
  19. self.output_height = \
  20. ConvLayer.calculate_output_size(
  21. self.input_height, filter_height, zero_padding,
  22. stride)
  23. self.output_array = np.zeros((self.filter_number,
  24. self.output_height, self.output_width))
  25. self.filters = []
  26. for i in range(filter_number):
  27. self.filters.append(Filter(filter_width,
  28. filter_height, self.channel_number))
  29. self.activator = activator
  30. self.learning_rate = learning_rate

这段代码可以了解到:

1,参数input,channel,filter,zero_padding,stride,output的设置

2,设置filter的activator以及learning_rate

来看一下calculate_output_size()函数,

  1. @staticmethod
  2. def calculate_output_size(input_size,
  3. filter_size, zero_padding, stride):
  4. return (input_size - filter_size +
  5. 2 * zero_padding) / stride + 1

其实就是按照计算公式实现的

来看一下Filter类,

  1. class Filter(object):
  2. def __init__(self, width, height, depth):
  3. self.weights = np.random.uniform(-1e-4, 1e-4,
  4. (depth, height, width))
  5. self.bias = 0
  6. self.weights_grad = np.zeros(
  7. self.weights.shape)
  8. self.bias_grad = 0
  9. def __repr__(self):
  10. return 'filter weights:\n%s\nbias:\n%s' % (
  11. repr(self.weights), repr(self.bias))
  12. def get_weights(self):
  13. return self.weights
  14. def get_bias(self):
  15. return self.bias
  16. def update(self, learning_rate):
  17. self.weights -= learning_rate * self.weights_grad
  18. self.bias -= learning_rate * self.bias_grad

从Filter类代码可以了解到:

1,filter的基本参数

2,用梯度下降法更新filter权重


明日接着分析CNN的Python代码










声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/974516
推荐阅读
相关标签
  

闽ICP备14008679号