-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yolox improve with REPConv/ASFF/TOOD #154
Changes from 43 commits
1167efd
9988716
4f55bda
1f4b054
18db2c5
42472ff
a1e5bc1
d0c1297
19388ed
a88c747
a837d97
425d6c2
2e87257
7b08d4f
f0f7ffc
d9bb9af
5bc6e00
e812089
6a9241e
bc2b238
e9e0dfc
bb16a3f
bbdfb9f
2f5c6c4
71c6ea2
6fcb293
5ecb695
2346aaf
4066723
b1d7b6c
437342c
166fe9b
48975bb
58e3f0c
95028f4
33e0740
1d21505
ab87f09
ce4e7b5
502a9dc
6379b27
47f7e2e
81a2051
cac888a
8dbe360
feb0eeb
b8b2646
7e07113
e1e9e8a
2f7534f
a364d60
10f549e
1eb0a4b
08bbba8
a8ba8fd
7844e64
77973f1
67140ae
e8b6607
525f7c0
cfde0cd
4ffd599
600e2c2
68454fd
a6236d3
47c4581
eeb269a
53183ec
1fefb7e
93c0254
c22bf98
887e2be
b865306
b0fa9e6
a7a914c
3ff49fe
55c3c46
3490d45
991d2ce
99e0d4c
3eb7cd2
1b063fc
26b458f
e08509e
59a3916
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
_base_ = './yolox_s_8xb16_300e_coco.py' | ||
_base_ = 'configs/detection/yolox/yolox_s_8xb16_300e_coco.py' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imitate configs/detection/fcos,reconstruct config There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
# model settings | ||
model = dict(model_type='l') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
from easycv.file import io | ||
from easycv.models import (DINO, MOCO, SWAV, YOLOX, Classification, MoBY, | ||
build_model) | ||
from easycv.models.backbones.repvgg_yolox_backbone import RepVGGBlock | ||
from easycv.utils.bbox_util import scale_coords | ||
from easycv.utils.checkpoint import load_checkpoint | ||
|
||
|
@@ -21,6 +22,24 @@ | |
] | ||
|
||
|
||
def reparameterize_models(model): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems not common, move to model.forward_export There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, thanks |
||
""" reparameterize model for inference, especially for | ||
1. rep conv block : merge 3x3 weight 1x1 weights | ||
call module switch_to_deploy recursively | ||
Args: | ||
model: nn.Module | ||
""" | ||
reparameterize_count = 0 | ||
for layer in model.modules(): | ||
reparameterize_count += 1 | ||
if isinstance(layer, RepVGGBlock): | ||
layer.switch_to_deploy() | ||
logging.info( | ||
'export : PAI-export reparameterize_count(RepVGGBlock, ) switch to deploy with {} blocks' | ||
.format(reparameterize_count)) | ||
return model | ||
|
||
|
||
def export(cfg, ckpt_path, filename): | ||
""" export model for inference | ||
|
||
|
@@ -34,6 +53,7 @@ def export(cfg, ckpt_path, filename): | |
load_checkpoint(model, ckpt_path, map_location='cpu') | ||
else: | ||
cfg.model.backbone.pretrained = False | ||
model = reparameterize_models(model) | ||
|
||
if isinstance(model, MOCO) or isinstance(model, DINO): | ||
_export_moco(model, cfg, filename) | ||
|
@@ -171,6 +191,7 @@ def _export_yolox(model, cfg, filename): | |
raise ValueError('`end2end` only support torch1.7.0 and later!') | ||
|
||
batch_size = cfg.export.get('batch_size', 1) | ||
static_opt = cfg.export.get('static_opt', True) | ||
img_scale = cfg.get('img_scale', (640, 640)) | ||
assert ( | ||
len(img_scale) == 2 | ||
|
@@ -194,7 +215,6 @@ def _export_yolox(model, cfg, filename): | |
# use trace is a litter bit faster than script. But it is not supported in an end2end model. | ||
if end2end: | ||
yolox_trace = torch.jit.script(model_export) | ||
|
||
else: | ||
yolox_trace = torch.jit.trace(model_export, input.to(device)) | ||
|
||
|
@@ -207,13 +227,17 @@ def _export_yolox(model, cfg, filename): | |
assert blade_env_assert() | ||
|
||
if end2end: | ||
input = 255 * torch.rand(img_scale + (3, )) | ||
if batch_size == 1: | ||
input = 255 * torch.rand(img_scale + (3, )) | ||
else: | ||
input = 255 * torch.rand(img_scale + (3, batch_size)) | ||
|
||
yolox_blade = blade_optimize( | ||
script_model=model, | ||
model=yolox_trace, | ||
inputs=(input.to(device), ), | ||
blade_config=blade_config) | ||
blade_config=blade_config, | ||
static_opt=static_opt) | ||
|
||
with io.open(filename + '.blade', 'wb') as ofile: | ||
torch.jit.save(yolox_blade, ofile) | ||
|
@@ -644,7 +668,15 @@ def __init__(self, | |
|
||
self.example_inputs = example_inputs | ||
self.preprocess_fn = preprocess_fn | ||
self.postprocess_fn = postprocess_fn | ||
self.ignore_postprocess = getattr(self.model, 'ignore_postprocess', | ||
False) | ||
if not self.ignore_postprocess: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why add ignore_postprocess? postprocess_fn=None is already supported. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, but this is some confused design ,we will try to fix it. |
||
self.postprocess_fn = postprocess_fn | ||
else: | ||
self.postprocess_fn = None | ||
logging.warning( | ||
'Model {} ignore_postprocess set to be {} during export !'.format( | ||
type(model), self.ignore_postprocess)) | ||
self.trace_model = trace_model | ||
if self.trace_model: | ||
self.trace_module() | ||
|
@@ -669,7 +701,6 @@ def forward(self, image): | |
image = output | ||
|
||
model_output = self.model.forward_export(image) | ||
|
||
if self.postprocess_fn is not None: | ||
model_output = self.postprocess_fn(model_output, | ||
*preprocess_outputs) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,9 @@ def visualize(self, results, vis_num=10, score_thr=0.3, **kwargs): | |
dict of image meta info, containing filename, img_shape, | ||
origin_img_shape, scale_factor and so on. | ||
""" | ||
import copy | ||
results = copy.deepcopy(results) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why add deepcopy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to fix the map=0 problem when evaluation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is already fixed, please refer to: #67 remove deepcopy |
||
|
||
class_names = None | ||
if hasattr(self.data_source, 'CLASSES'): | ||
class_names = self.data_source.CLASSES | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,6 @@ def before_train_epoch(self, runner): | |
train_loader.dataset.update_skip_type_keys(self.skip_type_keys) | ||
runner.logger.info('Add additional L1 loss now!') | ||
model.head.use_l1 = True | ||
|
||
if hasattr(runner.model.module, 'epoch_counter'): | ||
runner.model.module.epoch_counter = epoch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's epoch_counter for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use to change the label assigner before but cannot get a better result. remove it now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why modify base path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change as the base path done