美文网首页
手写 fully_connected全连接层

手写 fully_connected全连接层

作者: 猴子喜 | 来源:发表于2020-03-24 00:18 被阅读0次

fully_connected用于生成全连接层,总体思路就是

用_variable_with_weight_decay生成w×x+b中的w,并加上偏置biases。

最后通过参数提供batch_norm和activation等功能

def fully_connected(inputs,
                    num_outputs,
                    scope,
                    use_xavier=True,
                    stddev=1e-3,
                    weight_decay=0.0,
                    activation_fn=tf.nn.relu,
                    bn=False,
                    bn_decay=None,
                    is_training=None):
  """ Fully connected layer with non-linear operation.

  Args:
    inputs: 2-D tensor BxN
    num_outputs: int

  Returns:
    Variable tensor of size B x num_outputs.
  """
  with tf.variable_scope(scope) as sc:

    num_input_units = inputs.get_shape()[-1].value
    weights = _variable_with_weight_decay('weights',
                                          shape=[num_input_units, num_outputs],
                                          use_xavier=use_xavier,
                                          stddev=stddev,
                                          wd=weight_decay)
    outputs = tf.matmul(inputs, weights)
    biases = _variable_on_cpu('biases', [num_outputs],
                             tf.constant_initializer(0.0))
    outputs = tf.nn.bias_add(outputs, biases)


    if bn:
      outputs = batch_norm_for_fc(outputs, is_training, bn_decay, 'bn')

    if activation_fn is not None:
      outputs = activation_fn(outputs)

    return outputs

相关文章

  • 手写 fully_connected全连接层

    fully_connected用于生成全连接层,总体思路就是 用_variable_with_weight_dec...

  • CNN

    利用CNN识别MNIST手写字,很普通的一个例程。输入数据经过卷积层,池化层,卷积层,池化层,全连接层,Softm...

  • 18- OpenCV+TensorFlow 入门人工智能图像处理

    cnn卷积神经网络实现手写数字识别 卷积层 & 池化层实现 padding参数决定卷积核是否可以停留边缘。 全连接...

  • tensorflow全连接层手写数字识别

    import tensorflow as tf from tensorflow.examples.tutorial...

  • 基于mnist的Hello World 体验

    有两个隐层的神经网络,使用minist手写训练集。代码如下: 全连接和cnn都跑了两轮,结果如下:全连接网络: l...

  • Lenet 和 Lenet5 结构简单粗暴详解(附完整代码)

    LeNet LeNet 早期用来识别手写体数字的图像的卷积神经网络 组成部分: 卷积层块全连接层块 直接上代码--...

  • 全连接层

    前言 就是把前面实现的BP神经网络封装成层 代码

  • 20201019-Keras-2

    Keras 笔记 手写字体识别。 不使用CNN,直接两个全连接层的小示例。 简简单单,展示! 参考:https:/...

  • 全连接层与 softmax

    全连接层 一维 一般常见的是这种一维的全连接层,下面这种图就很常见。全连接层,通俗的说就是前面一层的每个单元都与后...

  • 全连接层&卷积层

    1.全连接层可以视作一种特殊的卷积 考虑下面两种情况: 特征图和全连接层相连:AlexNet经过五次池化后得到77...

网友评论

      本文标题:手写 fully_connected全连接层

      本文链接:https://www.haomeiwen.com/subject/bwlnyhtx.html