maskrcnn_benchmark理解记录——modeling\rpn\anchor_generator.py

     For a set of image sizes and feature maps, computes a set
    of anchors对于一组图像大小和feature maps,计算一组锚点
    传入的是
    anchor_sizes = config.MODEL.RPN.ANCHOR_SIZES            #(32, 64, 128, 256, 512)
    aspect_ratios = config.MODEL.RPN.ASPECT_RATIOS          #(0.5, 1.0, 2.0)
    anchor_stride = config.MODEL.RPN.ANCHOR_STRIDE          #(4, 8, 16, 32, 64)     也就是P2~P6
    straddle_thresh = config.MODEL.RPN.STRADDLE_THRESH      # 0

# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import math

import numpy as np
import torch
from torch import nn

from maskrcnn_benchmark.structures.bounding_box import BoxList


class BufferList(nn.Module):
    """
    Similar to nn.ParameterList, but for buffers
    """

    def __init__(self, buffers=None):
        super(BufferList, self).__init__()
        if buffers is not None:
            self.extend(buffers)

    def extend(self, buffers):
        offset = len(self)
        for i, buffer in enumerate(buffers):
            self.register_buffer(str(offset + i), buffer)
        return self

    def __len__(self):
        return len(self._buffers)

    def __iter__(self):
        return iter(self._buffers.values())


class AnchorGenerator(nn.Module):
    """
    For a set of image sizes and feature maps, computes a set
    of anchors对于一组图像大小和feature maps,计算一组锚点
    传入的是
    anchor_sizes = config.MODEL.RPN.ANCHOR_SIZES            #(32, 64, 128, 256, 512)
    aspect_ratios = config.MODEL.RPN.ASPECT_RATIOS          #(0.5, 1.0, 2.0)
    anchor_stride = config.MODEL.RPN.ANCHOR_STRIDE          #(4, 8, 16, 32, 64)     也就是P2~P6
    straddle_thresh = config.MODEL.RPN.STRADDLE_THRESH      # 0
    """

    def __init__(
            self,
            sizes=(128, 256, 512),
            aspect_ratios=(0.5, 1.0, 2.0),
            anchor_strides=(8, 16, 32),
            straddle_thresh=0,
    ):
        super(AnchorGenerator, self).__init__()

        if len(anchor_strides) == 1:
            anchor_stride = anchor_strides[0]
            cell_anchors = [
                generate_anchors(anchor_stride, sizes, aspect_ratios).float()
            ]
        else:
            if len(anchor_strides) != len(sizes):
                raise RuntimeError("FPN should have #anchor_strides == #sizes")

            # TODO 会运行到这里 以(x1&#x
在服务器中安装maskrcnn_benchmark通常遵循以下步骤: 1. **系统环境检查**: 确保服务器操作系统为Linux,maskrcnn_benchmark通常在Linux环境下开发和运行。 2. **安装依赖库**: maskrcnn_benchmark依赖于多个库,包括但不限于Python 3, PyTorch, torchvision, CMake等。可以通过以下命令安装: ```bash sudo apt-get update sudo apt-get install -y python3 python3-pip pip3 install torch torchvision sudo apt-get install -y libturbojpeg sudo apt-get install -y cmake ``` 3. **编译**: maskrcnn_benchmark可能需要编译某些依赖库(如Caffe2),根据其官方文档中的指南进行编译。 4. **安装maskrcnn_benchmark**: 你可以使用Python包管理工具pip来安装,或者直接从GitHub下载源代码后安装。 - 使用pip安装(如果可用): ```bash pip3 install maskrcnn_benchmark ``` - 从源代码安装: ```bash git clone https://github.com/facebookresearch/maskrcnn-benchmark.git cd maskrcnn-benchmark python setup.py build develop ``` 5. **配置环境变量**: 根据maskrcnn_benchmark的安装说明,可能还需要设置环境变量,比如设置`PYTHONPATH`环境变量指向maskrcnn_benchmark的安装路径。 ```bash export PYTHONPATH=/path/to/maskrcnn_benchmark:$PYTHONPATH ``` 6. **验证安装**: 安装完成后,可以通过运行maskrcnn_benchmark中的测试用例来验证安装是否成功。 ```bash python -m maskrcnn_benchmark.configs.vg_attr_config --test-only ``` 请注意,maskrcnn_benchmark可能依赖于一些特定版本的依赖库,因此在安装时需要严格按照其官方文档的指示操作,以确保所有依赖都是兼容的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值