Resnet学习笔记(一)--resnet.py

最近集中学习了一下Resnet的实现代码,在这将每一个文件都进行一个详细的分解。
首先分解的是Resnet的网络实现代码resnet.py。

import skimage.io  # bug. need to import this before tensorflow
import skimage.transform  # bug. need to import this before tensorflow
import tensorflow as tf
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.training import moving_averages

from config import Config

import datetime
import numpy as np
import os
import time

MOVING_AVERAGE_DECAY = 0.9997 #滑动平均模型衰减率
BN_DECAY = MOVING_AVERAGE_DECAY #BN层衰减率
BN_EPSILON = 0.001
CONV_WEIGHT_DECAY = 0.00004 #卷积层权重衰减率
CONV_WEIGHT_STDDEV = 0.1 #卷积层权重标准差 
FC_WEIGHT_DECAY = 0.00004 #全连接层权重衰减率
FC_WEIGHT_STDDEV = 0.01
RESNET_VARIABLES = 'resnet_variables'
UPDATE_OPS_COLLECTION = 'resnet_update_ops'  # must be grouped with training op
IMAGENET_MEAN_BGR = [103.062623801, 115.902882574, 123.151630838, ] #图像的平均BGR

tf.app.flags.DEFINE_integer('input_size', 224, "input image size") #输入图像的尺寸


activation = tf.nn.relu

#定义整个网络结构的函数
def inference(x, is_training,
              num_classes=6,
              num_blocks=[3, 4, 6, 3],  # defaults to 50-layer network
              use_bias=False, # defaults to using batch norm
              bottleneck=True):
    c = Config()
    c['bottleneck'] = bottleneck #残差学习单元常量
    c['is_training'] = tf.convert_to_tensor(is_training,
                                            dtype='bool',
                                            name='is_training')
    c['ksize'] = 3 #缺省ksize值
    c['stride'] = 1 #缺省stride值
    c['use_bias'] = use_bias
    c['fc_units_out'] = num_classes #全连接层输出
    c['num_blocks'] = num_blocks #每一层的block数
    c['stack_stride'] = 2

    with tf.variable_scope('scale1'):
        c['conv_filters_out'] = 64
        c['ksize'] = 7
        c['stride'] = 2
        x = conv(x, c)
        x = bn(x, c)
        x = activation(x)

    with tf.variable_scope('scale2'): #第一个残差单元输入64通道输出256通道
        x = _max_pool(x, ksize=3, stride=2)
        c['num_blocks'] = num_blocks[0]
        c['stack_stride'] 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值