Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_47816946
simple-faster-rcnn-pytorch
提交
fd3d2931
S
simple-faster-rcnn-pytorch
项目概览
weixin_47816946
/
simple-faster-rcnn-pytorch
与 Fork 源项目一致
从无法访问的项目Fork
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
simple-faster-rcnn-pytorch
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fd3d2931
编写于
12月 29, 2017
作者:
C
chenyuntc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove chainer dependencies
上级
2a949675
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
22 addition
and
80 deletion
+22
-80
data/util.py
data/util.py
+1
-1
data/voc_dataset.py
data/voc_dataset.py
+1
-21
model/faster_rcnn.py
model/faster_rcnn.py
+9
-5
model/faster_rcnn_vgg16.py
model/faster_rcnn_vgg16.py
+3
-46
model/region_proposal_network.py
model/region_proposal_network.py
+4
-4
model/utils/creator_tool.py
model/utils/creator_tool.py
+4
-3
未找到文件。
data/util.py
浏览文件 @
fd3d2931
...
...
@@ -121,7 +121,7 @@ def crop_bbox(
This method is mainly used together with image cropping.
This method translates the coordinates of bounding boxes like
:func:`
~chainercv.transforms
.translate_bbox`. In addition,
:func:`
data.util
.translate_bbox`. In addition,
this function truncates the bounding boxes to fit within the cropped area.
If a bounding box does not overlap with the cropped area,
this bounding box will be removed.
...
...
data/voc_dataset.py
浏览文件 @
fd3d2931
# Mofidied work:
# Original works by:
# --------------------------------------------------------
# Faster R-CNN implementation In ChainerCV
# Copyright (c) 2017 Preferred Networks, Inc.
# Licensed under The MIT License [see LICENSE for details]
# https://github.com/chainer/chainercv
# --------------------------------------------------------
# Faster R-CNN implementation by Chainer
# Copyright (c) 2016 Shunta Saito
# Licensed under The MIT License [see LICENSE for details]
# https://github.com/mitmul/chainer-faster-rcnn
# --------------------------------------------------------
# Faster R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick and Sean Bell
# https://github.com/rbgirshick/py-faster-rcnn
# ----------------------------------------------------
import
os
import
xml.etree.ElementTree
as
ET
...
...
@@ -51,7 +31,7 @@ class VOCBboxDataset:
The labels are packed into a one dimensional tensor of shape :math:`(R,)`.
:math:`R` is the number of bounding boxes in the image.
The class name of the label :math:`l` is :math:`l` th element of
:obj:`
chainercv.datasets.voc_bbox_label_names
`.
:obj:`
VOC_BBOX_LABEL_NAMES
`.
The array :obj:`difficult` is a one dimensional boolean array of shape
:math:`(R,)`. :math:`R` is the number of bounding boxes in the image.
...
...
model/faster_rcnn.py
浏览文件 @
fd3d2931
...
...
@@ -27,7 +27,7 @@ class FasterRCNN(nn.Module):
in the RoIs and improve localizations.
Each stage is carried out by one of the callable
:class:`
chainer.Chain
` objects :obj:`feature`, :obj:`rpn` and :obj:`head`.
:class:`
torch.nn.Module
` objects :obj:`feature`, :obj:`rpn` and :obj:`head`.
There are two functions :meth:`predict` and :meth:`__call__` to conduct
object detection.
...
...
@@ -49,10 +49,10 @@ class FasterRCNN(nn.Module):
extractor (nn.Module): A module that takes a BCHW image
array and returns feature maps.
rpn (nn.Module): A module that has the same interface as
:class:`
~chainercv.links.model.faster_rcnn
.RegionProposalNetwork`.
:class:`
model.region_proposal_network
.RegionProposalNetwork`.
Please refer to the documentation found there.
head (nn.Module): A
callab
le that takes
a BCHW
array
, RoIs and batch indices for RoIs. This returns class
head (nn.Module): A
modu
le that takes
a BCHW
variable
, RoIs and batch indices for RoIs. This returns class
dependent localization paramters and class scores.
loc_normalize_mean (tuple of four floats): Mean values of
localization estimates.
...
...
@@ -99,7 +99,7 @@ class FasterRCNN(nn.Module):
the :math:`L` th class.
Args:
x (
~chainer
.Variable): 4D image variable.
x (
autograd
.Variable): 4D image variable.
scale (float): Amount of scaling applied to the raw image
during preprocessing.
...
...
@@ -261,6 +261,10 @@ class FasterRCNN(nn.Module):
return
bboxes
,
labels
,
scores
def
get_optimizer
(
self
):
"""
return optimizer, It could be overwriten if you want to specify
special optimizer
"""
lr
=
opt
.
lr
params
=
[]
for
key
,
value
in
dict
(
self
.
named_parameters
()).
items
():
...
...
model/faster_rcnn_vgg16.py
浏览文件 @
fd3d2931
...
...
@@ -37,58 +37,17 @@ def decom_vgg16():
class
FasterRCNNVGG16
(
FasterRCNN
):
"""Faster R-CNN based on VGG-16.
When you specify the path of a pre-trained chainer model serialized as
a :obj:`.npz` file in the constructor, this chain model automatically
initializes all the parameters with it.
When a string in prespecified set is provided, a pretrained model is
loaded from weights distributed on the Internet.
The list of pretrained models supported are as follows:
* :obj:`voc07`: Loads weights trained with the trainval split of
\
PASCAL VOC2007 Detection Dataset.
* :obj:`imagenet`: Loads weights trained with ImageNet Classfication
\
task for the feature extractor and the head modules.
\
Weights that do not have a corresponding layer in VGG-16
\
will be randomly initialized.
For descriptions on the interface of this model, please refer to
:class:`~chainercv.links.model.faster_rcnn.FasterRCNN`.
:class:`~chainercv.links.model.faster_rcnn.FasterRCNNVGG16`
supports finer control on random initializations of weights by arguments
:obj:`vgg_initialW`, :obj:`rpn_initialW`, :obj:`loc_initialW` and
:obj:`score_initialW`.
It accepts a callable that takes an array and edits its values.
If :obj:`None` is passed as an initializer, the default initializer is
used.
:class:`model.faster_rcnn.FasterRCNN`.
Args:
n_fg_class (int): The number of classes excluding the background.
pretrained_model (str): The destination of the pre-trained
chainer model serialized as a :obj:`.npz` file.
If this is one of the strings described
above, it automatically loads weights stored under a directory
:obj:`$CHAINER_DATASET_ROOT/pfnet/chainercv/models/`,
where :obj:`$CHAINER_DATASET_ROOT` is set as
:obj:`$HOME/.chainer/dataset` unless you specify another value
by modifying the environment variable.
min_size (int): A preprocessing paramter for :meth:`prepare`.
max_size (int): A preprocessing paramter for :meth:`prepare`.
ratios (list of floats): This is ratios of width to height of
the anchors.
anchor_scales (list of numbers): This is areas of anchors.
Those areas will be the product of the square of an element in
:obj:`anchor_scales` and the original area of the reference
window.
vgg_initialW (callable): Initializer for the layers corresponding to
the VGG-16 layers.
rpn_initialW (callable): Initializer for Region Proposal Network
layers.
loc_initialW (callable): Initializer for the localization head.
score_initialW (callable): Initializer for the score head.
proposal_creator_params (dict): Key valued paramters for
:class:`~chainercv.links.model.faster_rcnn.ProposalCreator`.
"""
...
...
@@ -128,14 +87,12 @@ class VGG16RoIHead(nn.Module):
This class is used as a head for Faster R-CNN.
This outputs class-wise localizations and classification based on feature
maps in the given RoIs.
Args:
n_class (int): The number of classes possibly including the background.
roi_size (int): Height and width of the feature maps after RoI-pooling.
spatial_scale (float): Scale of the roi is resized.
vgg_initialW (callable): Initializer for the layers corresponding to
the VGG-16 layers.
loc_initialW (callable): Initializer for the localization head.
score_initialW (callable): Initializer for the score head.
classifier (nn.Module): Two layer Linear ported from vgg16
"""
...
...
model/region_proposal_network.py
浏览文件 @
fd3d2931
...
...
@@ -34,10 +34,10 @@ class RegionProposalNetwork(nn.Module):
initialize weight.
May also be a callable that takes an array and edits its values.
proposal_creator_params (dict): Key valued paramters for
:class:`
~chainercv.links.model.faster_rcnn
.ProposalCreator`.
:class:`
model.utils.creator_tools
.ProposalCreator`.
.. seealso::
:class:`~
chainercv.links.model.faster_rcnn
.ProposalCreator`
:class:`~
model.utils.creator_tools
.ProposalCreator`
"""
...
...
@@ -70,7 +70,7 @@ class RegionProposalNetwork(nn.Module):
* :math:`A` is number of anchors assigned to each pixel.
Args:
x (~
chainer
.Variable): The Features extracted from images.
x (~
torch.autograd
.Variable): The Features extracted from images.
Its shape is :math:`(N, C, H, W)`.
img_size (tuple of ints): A tuple :obj:`height, width`,
which contains image size after scaling.
...
...
@@ -78,7 +78,7 @@ class RegionProposalNetwork(nn.Module):
reading them from files.
Returns:
(~
chainer.Variable, ~chainer
.Variable, array, array, array):
(~
torch.autograd.Variable, ~torch.autograd
.Variable, array, array, array):
This is a tuple of five following values.
...
...
model/utils/creator_tool.py
浏览文件 @
fd3d2931
import
numpy
as
np
from
chainer
import
cuda
import
cupy
from
model.utils.bbox_tools
import
bbox2loc
,
bbox_iou
,
loc2bbox
from
model.utils.nms
import
non_maximum_suppression
...
...
@@ -419,9 +419,10 @@ class ProposalCreator:
# Apply nms (e.g. threshold = 0.7).
# Take after_nms_topN (e.g. 300).
# NOTE: somthing is wrong here!
# unNOTE: somthing is wrong here!
# TODO: remove cuda.to_gpu
keep
=
non_maximum_suppression
(
c
uda
.
to_gpu
(
roi
),
c
p
.
ascontiguousarray
(
cp
.
asarray
(
a
)
),
thresh
=
self
.
nms_thresh
)
if
n_post_nms
>
0
:
keep
=
keep
[:
n_post_nms
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录