GithubHelp home page GithubHelp logo

thundernet_pytorch's Introduction

Thundernet_Pytorch

项目已经更新:thundernet_mmdetection

20191222 update

  • add data augmentation
  • add Multi-scale training
  • add onnx (doing)

pretrained model

Requirements

  • pytorch 1.2.0
  • torchvision 0.4

Lib Prepare

git clone https://github.com/ouyanghuiyu/Thundernet_Pytorch.git

Build

cd lib && python setup.py  build_ext --inplace
cd psroialign/PSROIAlign && sh build.sh 

Data Prepare

Download VOC0712 datasets ln -s "YOUR PATH" data

Train

cd script
sh  train_49.sh
sh  train_146.sh
sh  train_535.sh

demo

cd script
sh  pre.sh

TODO LIST

  • add coco train and test
  • add NCNN inference

Citation

Please cite the paper in your publications if it helps your research:

@article{zheng2019thundernet,
  title={ThunderNet: Towards Real-time Generic Object Detection},
  author={Zheng Qin, Zeming Li,Zhaoning Zhang,Yiping Bao,Gang Yu, Yuxing Peng, Jian Sun},
  journal={arXiv preprint arXiv:1903.11752},
  year={2019}
}

VOC TEST EXAMPLE

test

thundernet_pytorch's People

Contributors

daybreak-u avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

thundernet_pytorch's Issues

thundernet_epoch_2.pth

Hi,
我想问下,是不是需要预训练文件的放入?
当我运行sh. train_146.sh 的时候
作者有没有训练好的预训练模型,方便分享一下

snet146/snet_146/pascal_voc7012/thundernet_epoch_2.pth

Official Implementation

Hi @ouyanghuiyu

Is there any official implementation of this paper where we can reproduce the reported results in the paper?

Thanks

about dataset

If I train my own data, but it is different from the number of categories in the coco data set, where should I modify it? Thank you

关于训练另外一个数据集

你好,请问出现这个问题要怎么办?
训练VOC数据集正常可以训练,测试,但是
训练自己的数据,代码可以跑起来,loss不下降,AP为0

image

VOC2007

voctest_1

AP和Results都很低,只有38多点

您好,我尝试使用您的代码。
我在第一次运行的时候遇到了#22 issue同样的问题。
weights/ 提供的sn146的预训练模型好像损坏了,无法解压提取。
所以我在跑的时候,去掉了参数--r。
但是跑VOC,AP和Results都很低,只有38多点
预测的结果
2008_000038.jpg
2008_000175.jpg
请问您出现过这种情况吗?为什么会这样?谢谢!

关于训练自己的模型

您好,程序卡在data = next(data_iter),loss等都是nan,请问是python版本问题吗,我用的是3.5

很低的AP和检测结果

您好,我尝试使用您的代码跑VOC,但是得到了很低的结果(AP,AP50等,接近于0),检测结果也不是很好,请问您出现过这种情况吗?谢谢!

thundernet 部署

你好,请问你有试过,将thundernet部署到x86平台嘛? 有试过将thundernet转onnx之后的模型部署嘛

Train Error.

Hi, i met the error when i train my own data and the error like this:
Traceback (most recent call last):
File "trainval_net.py", line 484, in
rois_label = _RCNN(im_data, im_info, gt_boxes, num_boxes,
File "/home/mario/.conda/envs/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in call
result = self.forward(*input, **kwargs)
File "/home/mario/Projects/Obj_det/faster-rcnn.pytorch-pytorch-1.0/lib/model/faster_rcnn/faster_rcnn.py", line 51, in forward
base_feat = self.RCNN_base(im_data)
File "/home/mario/.conda/envs/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in call
result = self.forward(*input, **kwargs)
File "/home/mario/Projects/Obj_det/Thundernet_Pytorch/lib/model/faster_rcnn/Snet.py", line 147, in forward
return cem_out
UnboundLocalError: local variable 'cem_out' referenced before assignment
could you please tell me how to fix it. thanks:)

cpu

I ran the test in the CPU with the following error:

load checkpoint weights/snet_146/pascal_voc_0712/thundernet_epoch_6.pth
load model successfully!
load checkpoint weights/snet_146/pascal_voc_0712/thundernet_epoch_6.pth
Loaded Photo: 0 images.
/home/silence/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/nn/functional.py:1351: UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.
warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.")
Traceback (most recent call last):
File "demo.py", line 328, in
rois_label = _RCNN(im_data, im_info, gt_boxes, num_boxes)
File "/home/silence/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in call
result = self.forward(*input, **kwargs)
File "/home/silence/cvdata/Thundernet_Pytorch-master/lib/model/faster_rcnn/faster_rcnn.py", line 126, in forward
pooled_feat = self._roi_align_layer(base_feat, rois.view(-1, 5))
File "/home/silence/cvdata/Thundernet_Pytorch-master/lib/model/faster_rcnn/faster_rcnn.py", line 68, in _roi_align_layer
return self.psroiAlign.forward(bottom, rois)
File "/home/silence/cvdata/Thundernet_Pytorch-master/lib/psroialign/psroialign.py", line 19, in forward
pooled_feat = self.psroialign(feat, rois)
File "/home/silence/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in call
result = self.forward(*input, **kwargs)
File "/home/silence/cvdata/Thundernet_Pytorch-master/lib/psroialign/PSROIAlign/model/roi_layers/ps_roi_align.py", line 77, in forward
self.pooled_dim # 10
File "/home/silence/cvdata/Thundernet_Pytorch-master/lib/psroialign/PSROIAlign/model/roi_layers/ps_roi_align.py", line 33, in forward
raise NotImplementedError
NotImplementedError

PSROI Align 模块

你好,非常感谢你的工作,我在build psroialign模块之后跑不通,提示cudaCheckError() failed : invalid device function,在setup.py中新增了"nvcc":['-arch=sm_61'],但还是没有解决,请问你有遇到这样的情况吗?

训练速度慢

楼主好,我在训练过程中,发现迭代的速度比较慢,大约30多秒迭代一步,正常吗?

WARNING:root:NaN or Inf found in input tensor.

如题,训练的时候一直都报这个警告。loss一直未nan。请问各位大佬怎么解决?
[epoch 3][iter 0/ 110] loss: nan, lr: 1.00e-10, rpn_cls: nan, rpn_box: nan, rcnn_cls: 2.2976, rcnn_box 0.0000 size:(240,240)
WARNING:root:NaN or Inf found in input tensor.
WARNING:root:NaN or Inf found in input tensor.
WARNING:root:NaN or Inf found in input tensor.

How to train the SNet from scratch?

Hi, could you provide me the training SNet code from scratch? I think a good SNet backbone model is very important for further thundernet performance. I want to train the Snet from scratch. Thx.

CPU测试问题

GPU上预测结果一切正常,将代码拷贝到另外一台CPU服务器上,CPU可以运行,但没有预测框。请问作者试过在CPU上运行代码吗?结果是正确的吗?

多Batch输入

请问一下,测试网络时支持多batchsize输入还是只能单batchsize?

训练时出现loss=Nan

您好!我训练自己的数据,格式和VOC一致,类别也改过,也调过lr,但是一训练就出现loss=nan;数据是kitti数据集,以前训练过其它网络,数据应该没问题;请问我有漏改了什么吗?

训练完自己的模型后怎么去检测视频?

使用自己的voc格式的数据集进行了训练和验证,MAP不是很高,但是可以检测出我们所需要的类别,只是为什么模型输出的是分割颜色区别,为什么不是检测框? 另外如何使用该模型去进行视频测试? 麻烦楼主解答一下,谢谢您了。

Other Pytorch version of PSROIAlign

I want to use PSROIAlign in my project which is based on pytorch0.4, could you please tell me where I can find the matched Pytorch version of PSROIAlign?

求楼主~多GPU训练时报错TypeError: zip argument #1 must support iteration

可爱的楼主您好~我单卡训练没问题,多卡训练报错
Traceback (most recent call last):
File "trainval_net.py", line 479, in
rois_label = _RCNN(im_data, im_info, gt_boxes, num_boxes,
File "/home/xinjianli/anaconda3/envs/torch12/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in call
result = self.forward(*input, **kwargs)
File "/home/xinjianli/anaconda3/envs/torch12/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 153, in forward
return self.gather(outputs, self.output_device)
File "/home/xinjianli/anaconda3/envs/torch12/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 165, in gather
return gather(outputs, output_device, dim=self.dim)
File "/home/xinjianli/anaconda3/envs/torch12/lib/python3.6/site-packages/torch/nn/parallel/scatter_gather.py", line 68, in gather
res = gather_map(outputs)
File "/home/xinjianli/anaconda3/envs/torch12/lib/python3.6/site-packages/torch/nn/parallel/scatter_gather.py", line 63, in gather_map
return type(out)(map(gather_map, zip(*outputs)))
File "/home/xinjianli/anaconda3/envs/torch12/lib/python3.6/site-packages/torch/nn/parallel/scatter_gather.py", line 63, in gather_map
return type(out)(map(gather_map, zip(*outputs)))
File "/home/xinjianli/anaconda3/envs/torch12/lib/python3.6/site-packages/torch/nn/parallel/scatter_gather.py", line 63, in gather_map
return type(out)(map(gather_map, zip(*outputs)))
TypeError: zip argument #1 must support iteration

#!/bin/bash
set -e
cd ..

CUDA_VISIBLE_DEVICES=18,19,20,21 python trainval_net.py --dataset pascal_voc_0712 --net snet_146 --bs 256 --nw 16
--lr 1e-2 --epochs 150 --cuda --lr_decay_step 25,50,75 --use_tfboard True
--save_dir snet146 --eval_interval 2 --logdir snet146_log --pre ./weights/snet_146.tar
--checkepoch 2 --mgpus

编译问题

您好,请问我在执行:python setup.py build_ext --inplace的时候出现下列错误:
error C1189: #error: pybind11 requires MSVC 2015 update 3 or newer
error: command 'D:\VS2015\VC\BIN\x86_amd64\cl.exe' failed with exit status 2

请问我该怎么解决呢,我是目标检测小白

模型性能

您好,请问该代码和原论文结果相比,精度怎样?

Got error when testing without "--cuda"

Hi Ouyang,

Great work! Now I've finished the training on Pascal VOC and begin to do the testing job. I got some questions here that 1) the snet_146 model can only run 90FPS+ on RTX2060; 2) when I test without "--cuda", errors pop up...

Any help is appreciated!

Shun

你好,方便提供一下预训练模型吗?

感谢分享,项目中的psroialign模块好像有点问题,build之后跑不通,我将你项目中的psroialign模块替换为https://github.com/McDo/PSROIAlign-Multi-Batch-PyTorch.git 项目,稍作修改后跑通了。然而,训练了两百多个epoch后使用testing.py进行测试,模型没有检测出任何一个框。整个训练过程中loss是下降的,我想用你的预训练模型测试一下,请问方便吗?我使用的训练数据为voc

检测框跳动

[Hi,我用这个代码来进行测试,当我输入视频流的时候,检测框会疯狂的上下跳动,我不知道这是什么情况,谢谢

5a7b139c43494be8ce89bc033039034

pretrained model accuracy

I tested the classificaiton accuracy of the pretrained model and get Top1 0.082 and Top5 0.444. This is weired. Why is it so low? Anyone who tests it as well?

视频导入

Hi
请问支持视频的实时识别吗,如果我要更改其中的code,能否告知其中哪个函数,多谢

模型性能

感谢大佬的复现!请问大佬能否将复现的结果放在readme里面,我比较好奇320分辨率下sn49,sn146,sn535的flops以及在voc07上的map

CEM模块是否需要BN和RELU

大神,我看你的代码中CEM模块只有卷积层,没有BN层和RELU层。请问是否需要添加BN和RELU层呢?yolo v3上采用前的1*1模块有BN和LEAKRELU。如下:
`[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky

[upsample]
stride=2`

Data prepare and Train procedure

Could you provide the train procedure and data preparation( such as data file catalogue ,where should i put the VOC data ?) in detail?

psroialign onnx support

As far as I know, there is no onnx support for psroialign yet. Does anybody know there is any support for this?

Cannot extract the pretrained weights file.

Hi,

I cannot seem to be able to extract the pretrained weights file in the ./weights directory titled "snet146.tar" . It seems corrupted. Can you please re-upload it?

Thanks

shufflenet block的实现疑问

作者大大您好:

谢谢开源可以学习!!
看到您实现的shufflenet的block实现,好像和论文里面的不一样啊,这个会有影响吗?
def forward(self, old_x):
if self.stride==1:
x_proj, x = self.channel_shuffle(old_x)
return torch.cat((x_proj, self.branch_main(x)), 1)
elif self.stride==2:
x_proj = old_x
x = old_x
return torch.cat((self.branch_proj(x_proj), self.branch_main(x)), 1)

v2-eee995e9167bde760a6aab6c4b30c794_hd

下面是我之前不知道从哪个repo搞过来的,貌似和论文是一致的 :-)

`import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from collections import OrderedDict
from torch.nn import init
import math

def conv_bn(inp, oup, stride):
return nn.Sequential(
nn.Conv2d(inp, oup, 3, stride, 1, bias=False),
nn.BatchNorm2d(oup),
nn.ReLU(inplace=True)
)

def conv_1x1_bn(inp, oup):
return nn.Sequential(
nn.Conv2d(inp, oup, 1, 1, 0, bias=False),
nn.BatchNorm2d(oup),
nn.ReLU(inplace=True)
)

def channel_shuffle(x, groups):
batchsize, num_channels, height, width = x.data.size()

channels_per_group = num_channels // groups

# reshape
x = x.view(batchsize, groups, 
    channels_per_group, height, width)

x = torch.transpose(x, 1, 2).contiguous()

# flatten
x = x.view(batchsize, -1, height, width)

return x

class InvertedResidual(nn.Module):
def init(self, inp, oup, stride, benchmodel):
super(InvertedResidual, self).init()
self.benchmodel = benchmodel
self.stride = stride
assert stride in [1, 2]

    oup_inc = oup//2
    
    if self.benchmodel == 1:
        #assert inp == oup_inc
    	self.banch2 = nn.Sequential(
            # pw
            nn.Conv2d(oup_inc, oup_inc, 1, 1, 0, bias=False),
            nn.BatchNorm2d(oup_inc),
            nn.ReLU(inplace=True),
            # dw
            nn.Conv2d(oup_inc, oup_inc, 3, stride, 1, groups=oup_inc, bias=False),
            nn.BatchNorm2d(oup_inc),
            # pw-linear
            nn.Conv2d(oup_inc, oup_inc, 1, 1, 0, bias=False),
            nn.BatchNorm2d(oup_inc),
            nn.ReLU(inplace=True),
        )                
    else:                  
        self.banch1 = nn.Sequential(
            # dw
            nn.Conv2d(inp, inp, 3, stride, 1, groups=inp, bias=False),
            nn.BatchNorm2d(inp),
            # pw-linear
            nn.Conv2d(inp, oup_inc, 1, 1, 0, bias=False),
            nn.BatchNorm2d(oup_inc),
            nn.ReLU(inplace=True),
        )        

        self.banch2 = nn.Sequential(
            # pw
            nn.Conv2d(inp, oup_inc, 1, 1, 0, bias=False),
            nn.BatchNorm2d(oup_inc),
            nn.ReLU(inplace=True),
            # dw
            nn.Conv2d(oup_inc, oup_inc, 3, stride, 1, groups=oup_inc, bias=False),
            nn.BatchNorm2d(oup_inc),
            # pw-linear
            nn.Conv2d(oup_inc, oup_inc, 1, 1, 0, bias=False),
            nn.BatchNorm2d(oup_inc),
            nn.ReLU(inplace=True),
        )
      
@staticmethod
def _concat(x, out):
    # concatenate along channel axis
    return torch.cat((x, out), 1)        

def forward(self, x):
    if 1==self.benchmodel:
        x1 = x[:, :(x.shape[1]//2), :, :]
        x2 = x[:, (x.shape[1]//2):, :, :]
        out = self._concat(x1, self.banch2(x2))
    elif 2==self.benchmodel:
        out = self._concat(self.banch1(x), self.banch2(x))

    return channel_shuffle(out, 2)

class ShuffleNetV2(nn.Module):
def init(self, n_class=1000, input_size=224, width_mult=1., back_flag = False):
super(ShuffleNetV2, self).init()

    assert input_size % 32 == 0
    
    self.stage_repeats = [4, 8, 4]
    self.back_flag = back_flag
    # index 0 is invalid and should never be called.
    # only used for indexing convenience.
    if width_mult == 0.5:
        self.stage_out_channels = [-1, 24,  48,  96, 192, 1024]
    elif width_mult == 1.0:
        self.stage_out_channels = [-1, 24, 116, 232, 464, 1024]
    elif width_mult == 1.5:
        self.stage_out_channels = [-1, 24, 176, 352, 704, 1024]
    elif width_mult == 2.0:
        self.stage_out_channels = [-1, 24, 224, 488, 976, 2048]
    else:
        raise ValueError(
            """{} groups is not supported for
                   1x1 Grouped Convolutions""".format(num_groups))

    # building first layer
    input_channel = self.stage_out_channels[1]
    self.conv1 = conv_bn(3, input_channel, 2)    
    self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)

    self.stage2 = []
    self.stage3 = []
    self.stage4 = []
    for idxstage in range(len(self.stage_repeats)):
      output_channel = self.stage_out_channels[idxstage+2]
      numrepeat = self.stage_repeats[idxstage]
      stage = []
      for i in range(numrepeat):
        if i == 0:
          stage.append(InvertedResidual(input_channel, output_channel, 2, 2))
        else:
          stage.append(InvertedResidual(input_channel, output_channel, 1, 1))
        input_channel = output_channel
      if idxstage == 0:
        self.stage2 = stage
      elif idxstage == 1:
        self.stage3 = stage
      elif idxstage == 2:
        self.stage4 = stage
      else:
        print("error")
    # self.stages = nn.Sequential(*self.stages)
    self.stage2 = nn.Sequential(*self.stage2) # 58 * 58 * 116
    self.stage3 = nn.Sequential(*self.stage3) # 26 * 26 * 232
    self.stage4 = nn.Sequential(*self.stage4)
    
    self.features = []
    # building inverted residual blocks
    for idxstage in range(len(self.stage_repeats)):
        numrepeat = self.stage_repeats[idxstage]
        output_channel = self.stage_out_channels[idxstage+2]
        for i in range(numrepeat):
            if i == 0:
            #inp, oup, stride, benchmodel):
                self.features.append(InvertedResidual(input_channel, output_channel, 2, 2))
            else:
                self.features.append(InvertedResidual(input_channel, output_channel, 1, 1))
            input_channel = output_channel
            
    # make it nn.Sequential
    self.features = nn.Sequential(*self.features)

    # building last several layers
    self.conv_last      = conv_1x1_bn(input_channel, self.stage_out_channels[-1])
    self.globalpool = nn.Sequential(nn.AvgPool2d(int(input_size/32)))              

# building classifier
    self.classifier = nn.Sequential(nn.Linear(self.stage_out_channels[-1], n_class))

def forward(self, x):
    y = []
    conv1 = self.conv1(x)
    maxpool = self.maxpool(conv1)
    y.append(maxpool)
    out3 = self.stage2(maxpool)
    y.append(out3)
    out4 = self.stage3(out3)
    y.append(out4)
    out5 = self.stage4(out4)
    y.append(out5)
    if self.back_flag:
      return y
    #x = self.features(x)
    x = self.conv_last(out5)
    x = self.globalpool(x)
    x = x.view(-1, self.stage_out_channels[-1])
    x = self.classifier(x)
    return x

def shufflenetv2(width_mult=1.):
model = ShuffleNetV2(width_mult=width_mult)
return model

if name == "main":
"""Testing
"""
model = ShuffleNetV2()
print(model)
`

something about result

hi,Thanks for your contributing!I train the model on KITTI dataset,only one class=‘car’;but the AP and AR are low,are 0.23 and 0.4 respectively;The FPS i test on 1050Ti are 50,is it any problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.