GithubHelp home page GithubHelp logo

use autoslim for yolof about mmrazor HOT 7 CLOSED

open-mmlab avatar open-mmlab commented on July 24, 2024
use autoslim for yolof

from mmrazor.

Comments (7)

HIT-cwh avatar HIT-cwh commented on July 24, 2024

Sorry for taking so long to get back to you.
We will solve the related issues you raised as soon as possible.

from mmrazor.

HIT-cwh avatar HIT-cwh commented on July 24, 2024

AutoSlim can be used in Yolof in pr[#126 ]. Pls make sure the following codes works fine first:

# model settings
model_cfg = dict(
    type='mmdet.YOLOF',
    backbone=dict(
        type='ResNet',
        depth=50,
        num_stages=4,
        out_indices=(3, ),
        frozen_stages=1,
        norm_cfg=dict(type='BN', requires_grad=False),
        norm_eval=True,
        style='caffe',
        init_cfg=dict(
            type='Pretrained',
            checkpoint='open-mmlab://detectron/resnet50_caffe')),
    neck=dict(
        type='DilatedEncoder',
        in_channels=2048,
        out_channels=512,
        block_mid_channels=128,
        num_residual_blocks=4),
    bbox_head=dict(
        type='YOLOFHead',
        num_classes=80,
        in_channels=512,
        reg_decoded_bbox=True,
        anchor_generator=dict(
            type='AnchorGenerator',
            ratios=[1.0],
            scales=[1, 2, 4, 8, 16],
            strides=[32]),
        bbox_coder=dict(
            type='DeltaXYWHBBoxCoder',
            target_means=[.0, .0, .0, .0],
            target_stds=[1., 1., 1., 1.],
            add_ctr_clamp=True,
            ctr_clamp=32),
        loss_cls=dict(
            type='FocalLoss',
            use_sigmoid=True,
            gamma=2.0,
            alpha=0.25,
            loss_weight=1.0),
        loss_bbox=dict(type='GIoULoss', loss_weight=1.0)),
    # training and testing settings
    train_cfg=dict(
        assigner=dict(
            type='UniformAssigner', pos_ignore_thr=0.15, neg_ignore_thr=0.7),
        allowed_border=-1,
        pos_weight=-1,
        debug=False),
    test_cfg=dict(
        nms_pre=1000,
        min_bbox_size=0,
        score_thr=0.05,
        nms=dict(type='nms', iou_threshold=0.6),
        max_per_img=100))
algorithm_cfg = ConfigDict(
    type='AutoSlim',
    architecture=dict(type='MMDetArchitecture', model=model_cfg),
    pruner=dict(
        type='RatioPruner',
        ratios=(2 / 12, 3 / 12, 4 / 12, 5 / 12, 6 / 12, 7 / 12, 8 / 12, 9 / 12,
                10 / 12, 11 / 12, 1.0)),
    retraining=False,
    bn_training_mode=True,
    input_shape=None)

algorithm = build_algorithm(algorithm_cfg)
subnet_dict = algorithm.pruner.sample_subnet()
assert isinstance(subnet_dict, dict)
algorithm.pruner.set_subnet(subnet_dict)
subnet_dict = algorithm.pruner.export_subnet()
assert isinstance(subnet_dict, dict)
algorithm.pruner.deploy_subnet(algorithm.architecture, subnet_dict)
imgs = torch.randn(16, 3, 224, 224)
losses = algorithm.architecture.forward_dummy(imgs)

By the way, AutoSlim can also be used to prune models with shared modules such as detection head in RetinaNet in this pr.

from mmrazor.

NickYangMin avatar NickYangMin commented on July 24, 2024

ok, I will try it, thx!

from mmrazor.

NickYangMin avatar NickYangMin commented on July 24, 2024

I try it with branch 'dev_v0.3.0',but it still doesn't work

from mmrazor.

HIT-cwh avatar HIT-cwh commented on July 24, 2024

I try it with branch 'dev_v0.3.0',but it still doesn't work

Pls try it with #126 , this pr is based on branch 'dev_v0.3.0' and hasn't been merged yet.

from mmrazor.

NickYangMin avatar NickYangMin commented on July 24, 2024

ok

from mmrazor.

NickYangMin avatar NickYangMin commented on July 24, 2024

it works, thx! @HIT-cwh

from mmrazor.

Related Issues (20)

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.