Faster RCNN設定ファイルの詳細解説:MMDetectionフレームワーク

MMDetectionフレームワークにおけるFaster R-CNNモデルの設定ファイルは、mmdetection/configs/faster_rcnn/ディレクトリ下のsample_config.pyに存在します。以下がその主要部分です:

_base_ = [
    '../base/models/sample_model.py',
    '../base/datasets/sample_dataset.py',
    '../base/schedules/sample_schedule.py', '../base/default_runtime.py'
]

上記コードでは、最初の設定ファイルが使用するモデルを指定し、2番目のファイルは学習データセットを定義しています。3番目のファイルには学習パラメータ(例: 学習率やエポック数)が含まれ、4番目のファイルは実行時の環境設定を担当します。

次に、モデル設定ファイルであるsample_model.pyの内容とその解説を行います:

model_cfg = dict(
    # モデルタイプ
    model_type='SampleRCNN',
    # 事前学習済みモデル
    pre_trained='torchvision://resnet50_variant',
    # バックボーンネットワーク
    backbone=dict(
        # バックボーンアーキテクチャ
        architecture='ResNetVariant',
        # 層の深さ
        depth=50,
        # FPNの段階数
        stages=4,
        # 出力されるFPN層のインデックス
        output_indices=(0, 1, 2, 3),
        # 固定するステージ数
        frozen_stages=1,
        norm_config=dict(type='BatchNorm', requires_grad=True),
        eval_norm=True,
        # ネットワークスタイル
        style='pytorch_custom'),
    # 中間特徴抽出部
    neck_layer=dict(
        # ネックタイプ
        layer_type='CustomFPN',
        # 各ステージの入力チャンネル数
        in_channels=[256, 512, 1024, 2048],
        # 出力チャンネル数
        out_channels=256,
        # 特徴マップ出力数
        num_out_maps=5),
    # RPNヘッド設定
    rpn_head=dict(
        # RPNヘッドタイプ
        head_type='CustomRPNHead',
        # 入力チャンネル数
        input_channels=256,
        # 特徴チャンネル数
        feature_channels=256,
        # アンカー生成器
        anchor_gen=dict(
            type='AnchorGenCustom',
            scales=[8],
            ratios=[0.5, 1.0, 2.0],
            strides=[4, 8, 16, 32, 64]),
        bbox_encoder=dict(
            # BBoxエンコーダー
            type='DeltaXYWHBBoxEncoder',
            target_means=[0., 0., 0., 0.],
            target_stds=[1., 1., 1., 1.]),
        # 分類損失関数
        loss_classifier=dict(
            type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0),
        # BBox損失関数
        loss_bbox=dict(type='L1Loss', loss_weight=1.0)),
    # ROIヘッド設定
    roi_head=dict(
        # ROIヘッドタイプ
        head_type='StandardRoIHeadCustom',
        # ROI特徴抽出器
        roi_extractor=dict(
            type='SingleROIExtractorCustom',
            roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=0),
            out_channels=256,
            featmap_strides=[4, 8, 16, 32]),
        # ROI BBoxヘッド
        bbox_head=dict(
            # 全結合層タイプ
            fc_type='SharedFCBBoxHeadCustom',
            # 入力チャンネル数
            input_channels=256,
            # 出力チャンネル数
            fc_output_channels=1024,
            # ROI特徴サイズ
            roi_feat_size=7,
            # クラス数
            num_classes=80,
            # BBoxエンコーダー
            bbox_encoder=dict(
                type='DeltaXYWHBBoxEncoder',
                target_means=[0., 0., 0., 0.],
                target_stds=[0.1, 0.1, 0.2, 0.2]),
            class_agnostic=False,
            # 分類損失関数
            loss_classifier=dict(
                type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0),
            # BBox損失関数
            loss_bbox=dict(type='L1Loss', loss_weight=1.0))))
# モデルの学習およびテスト設定
train_setup = dict(
    # RPN学習設定
    rpn=dict(
        assigner=dict(
            type='MaxIoUAssignerCustom',
            pos_iou_thr=0.7,
            neg_iou_thr=0.3,
            min_pos_iou=0.3,
            match_low_quality=True,
            ignore_iof_thr=-1),
        sampler=dict(
            type='RandomSamplerCustom',
            num_samples=256,
            pos_fraction=0.5,
            neg_pos_ub=-1,
            add_gt_as_proposals=False),
        allowed_border=-1,
        pos_weight=-1,
        debug_mode=False),
    # RPNプロポーザル設定
    rpn_proposal=dict(
        nms_across_levels=False,
        nms_pre=2000,
        nms_post=1000,
        max_num=1000,
        nms_thr=0.7,
        min_bbox_size=0),
    # ROI学習設定
    rcnn=dict(
        assigner=dict(
            type='MaxIoUAssignerCustom',
            pos_iou_thr=0.5,
            neg_iou_thr=0.5,
            min_pos_iou=0.5,
            match_low_quality=False,
            ignore_iof_thr=-1),
        sampler=dict(
            type='RandomSamplerCustom',
            num_samples=512,
            pos_fraction=0.25,
            neg_pos_ub=-1,
            add_gt_as_proposals=True),
        pos_weight=-1,
        debug_mode=False))
# テスト設定
test_setup = dict(
    # RPN設定
    rpn=dict(
        nms_across_levels=False,
        nms_pre=1000,
        nms_post=1000,
        max_num=1000,
        nms_thr=0.7,
        min_bbox_size=0),
    # ROI設定
    rcnn=dict(
        score_threshold=0.05,
        # NMSタイプとIOU閾値
        nms=dict(type='nms_custom', iou_threshold=0.5),
        max_per_img=100)
)

タグ: MMDetection FasterRCNN Python DeepLearning ObjectDetection

6月3日 17:37 投稿