mask_rcnn keras源码跟读3)配置文件

机器·深度学习 专栏收录该内容
37 篇文章 2 订阅

config.py文件,参数配置一个一个地看

# NUMBER OF GPUs to use. For CPU training, use 1
GPU_COUNT = 1
# Number of images to train with on each GPU. A 12GB GPU can typically
# handle 2 images of 1024x1024px.
# Adjust based on your GPU memory and image sizes. Use the highest
# number that your GPU can handle for best performance.
IMAGES_PER_GPU = 2

GPU_COUNT:你机器有几个GPU,
IMAGES_PER_GP :每个GPU训练多少张图片()


# Number of training steps per epoch
# This doesn't need to match the size of the training set. Tensorboard
# updates are saved at the end of each epoch, so setting this to a
# smaller number means getting more frequent TensorBoard updates.
# Validation stats are also calculated at each epoch end and they
# might take a while, so don't set this too small to avoid spending
# a lot of time on validation stats.
STEPS_PER_EPOCH = 1000

# Number of validation steps to run at the end of every training epoch.
# A bigger number improves accuracy of validation stats, but slows
# down the training.
VALIDATION_STEPS = 50

STEPS_PER_EPOCH :多少个step为1个epoch(每个step都会取1个batch的数据)
VALIDATION_STEPS :多少个step的batch数据作为训练集

# Backbone network architecture
# Supported values are: resnet50, resnet101
BACKBONE = "resnet101"

BACKBONE :特征提取主架构,一般用resnet101


# The strides of each layer of the FPN Pyramid. These values
# are based on a Resnet101 backbone.
BACKBONE_STRIDES = [4, 8, 16, 32, 64]

BACKBONE_STRIDES :特征图相对于原图缩小的倍数,如在resnet101中,C2的大小是原图的1/4,C3是原图的1/8,C4是的原图1/16,C5是原图的1/32,其和FPN输出的P2-P5是对应的,P6在P5的基础上进行了一个下采样,因此P6是原图的1/64


# Number of classification classes (including background)
NUM_CLASSES = 1  # Override in sub-classes

NUM_CLASSES :目标检测的类别,1表示只有1类(编号从0开始,0为默认为背景)


# Length of square anchor side in pixels
RPN_ANCHOR_SCALES = (32, 64, 128, 256, 512)

RPN_ANCHOR_SCALES :P2-P5默认anchor的大小,如P2的anchor大小为32*32


# Ratios of anchors at each cell (width/height)
# A value of 1 represents a square anchor, and 0.5 is a wide anchor
RPN_ANCHOR_RATIOS = [0.5, 1, 2]

RPN_ANCHOR_RATIOS :anchor的横纵比,比如P2的默认anchor为32*32,若anchor的横纵比为0.5,则anchor的size:(64*1/3)*(64*2/3)


# Anchor stride
# If 1 then anchors are created for each cell in the backbone feature map.
# If 2, then anchors are created for every other cell, and so on.
RPN_ANCHOR_STRIDE = 1

# Non-max suppression threshold to filter RPN proposals.
# You can increase this during training to generate more propsals.
RPN_NMS_THRESHOLD = 0.7

# How many anchors per image to use for RPN training
RPN_TRAIN_ANCHORS_PER_IMAGE = 256

RPN_ANCHOR_STRIDE :对FPN网络的输出P2-P5,首先会使用3*3核对其卷积获得share输出,share用于后续的BG/FG和坐标的回归。anchor_stride

# Shared convolutional base of the RPN
shared = KL.Conv2D(512, (3, 3), padding='same', activation='relu',
                   strides=anchor_stride, #RPN_ANCHOR_STRIDE
                   name='rpn_conv_shared')(feature_map)

RPN_NMS_THRESHOLD :在ProposalLayer使用到的极大值抑制算法,首先选择一个最佳的best_anchor,left_anchor和best_anchor的IOU若大于0.7则舍弃。

RPN_TRAIN_ANCHORS_PER_IMAGE :对于一张图片,使用多少anchor用于RPN网络的训练。

# RPN bounding boxes: [max anchors per image, (dy, dx, log(dh), log(dw))]
rpn_bbox = np.zeros((config.RPN_TRAIN_ANCHORS_PER_IMAGE, 4))
 # ROIs kept after non-maximum supression (training and inference)
 POST_NMS_ROIS_TRAINING = 2000
 POST_NMS_ROIS_INFERENCE = 1000

这2个参数基本不用管,在不使用RPN网络的时候用到


# If enabled, resizes instance masks to a smaller size to reduce
# memory load. Recommended when using high-resolution images.
USE_MINI_MASK = True
MINI_MASK_SHAPE = (56, 56)  # (height, width) of the mini-mask

把mask的部分扣出来进行缩放,具体可以参考minimize_mask()


# Input image resizing
# Generally, use the "square" resizing mode for training and inferencing
# and it should work well in most cases. In this mode, images are scaled
# up such that the small side is = IMAGE_MIN_DIM, but ensuring that the
# scaling doesn't make the long side > IMAGE_MAX_DIM. Then the image is
# padded with zeros to make it a square so multiple images can be put
# in one batch.
# Available resizing modes:
# none:   No resizing or padding. Return the image unchanged.
# square: Resize and pad with zeros to get a square image
#         of size [max_dim, max_dim].
# pad64:  Pads width and height with zeros to make them multiples of 64.
#         If IMAGE_MIN_DIM or IMAGE_MIN_SCALE are not None, then it scales
#         up before padding. IMAGE_MAX_DIM is ignored in this mode.
#         The multiple of 64 is needed to ensure smooth scaling of feature
#         maps up and down the 6 levels of the FPN pyramid (2**6=64).
# crop:   Picks random crops from the image. First, scales the image based
#         on IMAGE_MIN_DIM and IMAGE_MIN_SCALE, then picks a random crop of
#         size IMAGE_MIN_DIM x IMAGE_MIN_DIM. Can be used in training only.
#         IMAGE_MAX_DIM is not used in this mode.
IMAGE_RESIZE_MODE = "square"
IMAGE_MIN_DIM = 800
IMAGE_MAX_DIM = 1024
# Minimum scaling ratio. Checked after MIN_IMAGE_DIM and can force further
# up scaling. For example, if set to 2 then images are scaled up to double
# the width and height, or more, even if MIN_IMAGE_DIM doesn't require it.
# Howver, in 'square' mode, it can be overruled by IMAGE_MAX_DIM.
IMAGE_MIN_SCALE = 0

对输入图片的预处理,具体可以参考load_image_gt


    # Image mean (RGB)
    MEAN_PIXEL = np.array([123.7, 116.8, 103.9])

MEAN_PIXEL :用于图片的归一化处理


# Number of ROIs per image to feed to classifier/mask heads
# The Mask RCNN paper uses 512 but often the RPN doesn't generate
# enough positive proposals to fill this and keep a positive:negative
# ratio of 1:3. You can increase the number of proposals by adjusting
# the RPN NMS threshold.
TRAIN_ROIS_PER_IMAGE = 200

# Percent of positive ROIs used to train classifier/mask heads
ROI_POSITIVE_RATIO = 0.33

TRAIN_ROIS_PER_IMAGE :经过ProposalLayer生成了许多roi,根据roi和gt_box的iou把其划为候选正负样本(iou>0.5?),最终在候选正样本中选择200*0.33个作为最终的正样本。

# Subsample ROIs. Aim for 33% positive
# Positive ROIs
positive_count = int(config.TRAIN_ROIS_PER_IMAGE *config.ROI_POSITIVE_RATIO)

# Pooled ROIs
POOL_SIZE = 7
MASK_POOL_SIZE = 14

# Shape of output mask
# To change this you also need to change the neural network mask branch
MASK_SHAPE = [28, 28]

这里是ROI_POOLING部分,具体可以参考build_fpn_mask_graph


剩下的参数比较简单,看注释即可

    # Maximum number of ground truth instances to use in one image
    MAX_GT_INSTANCES = 100

    # Bounding box refinement standard deviation for RPN and final detections.
    RPN_BBOX_STD_DEV = np.array([0.1, 0.1, 0.2, 0.2])
    BBOX_STD_DEV = np.array([0.1, 0.1, 0.2, 0.2])

    # Max number of final detections
    DETECTION_MAX_INSTANCES = 100

    # Minimum probability value to accept a detected instance
    # ROIs below this threshold are skipped
    DETECTION_MIN_CONFIDENCE = 0.7

    # Non-maximum suppression threshold for detection
    #降低该参数,可让最终的mask不会都堆叠在一起
    DETECTION_NMS_THRESHOLD = 0.3

    # Learning rate and momentum
    # The Mask RCNN paper uses lr=0.02, but on TensorFlow it causes
    # weights to explode. Likely due to differences in optimzer
    # implementation.
    LEARNING_RATE = 0.001
    LEARNING_MOMENTUM = 0.9

    # Weight decay regularization
    WEIGHT_DECAY = 0.0001

    # Use RPN ROIs or externally generated ROIs for training
    # Keep this True for most situations. Set to False if you want to train
    # the head branches on ROI generated by code rather than the ROIs from
    # the RPN. For example, to debug the classifier head without having to
    # train the RPN.
    USE_RPN_ROIS = True
  • 1
    点赞
  • 23
    评论
  • 14
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值