使用UP框架基于最新mqbench对yolox进行QAT训练,选择backbend=tengine_u8
时报错:AttributeError: 'dict' object has no attribute 'detach'
以下是使用的QAT配置文件:
num_classes: &num_classes 13
runtime:
aligned: true
# async_norm: True
special_bn_init: true
task_names: quant_det
runner:
type: quant
quant:
quant_type: qat
deploy_backend: Tengine_u8
cali_batch_size: 900
prepare_args:
extra_qconfig_dict:
w_observer: MinMaxObserver
a_observer: EMAMinMaxObserver
w_fakequantize: FixedFakeQuantize
a_fakequantize: FixedFakeQuantize
leaf_module: [Space2Depth, FrozenBatchNorm2d]
extra_quantizer_dict:
additional_module_type: [ConvFreezebn2d, ConvFreezebnReLU2d]
mixup:
type: yolox_mixup_cv2
kwargs:
extra_input: true
input_size: [640, 640]
mixup_scale: [0.8, 1.6]
fill_color: 0
mosaic:
type: mosaic
kwargs:
extra_input: true
tar_size: 640
fill_color: 0
random_perspective:
type: random_perspective_yolox
kwargs:
degrees: 10.0 # 0.0
translate: 0.1
scale: [0.1, 2.0] # 0.5
shear: 2.0 # 0.0
perspective: 0.0
fill_color: 0 # 0
border: [-320, -320]
augment_hsv:
type: augment_hsv
kwargs:
hgain: 0.015
sgain: 0.7
vgain: 0.4
color_mode: BGR
flip:
type: flip
kwargs:
flip_p: 0.5
to_tensor: &to_tensor
type: custom_to_tensor
train_resize: &train_resize
type: keep_ar_resize_max
kwargs:
max_size: 640
random_size: [15, 25]
scale_step: 32
padding_type: left_top
padding_val: 0
test_resize: &test_resize
type: keep_ar_resize_max
kwargs:
max_size: 640
padding_type: left_top
padding_val: 0
dataset:
train:
dataset:
type: coco
kwargs:
meta_file: train.json
image_reader:
type: fs_opencv
kwargs:
image_dir: &img_root /images/
color_mode: BGR
transformer: [*train_resize, *to_tensor]
batch_sampler:
type: base
kwargs:
sampler:
type: dist
kwargs: {}
batch_size: 4
test:
dataset:
type: coco
kwargs:
meta_file: >_file val.json
image_reader:
type: fs_opencv
kwargs:
image_dir: *img_root
color_mode: BGR
transformer: [*test_resize, *to_tensor]
evaluator:
type: COCO
kwargs:
gt_file: *gt_file
iou_types: [bbox]
batch_sampler:
type: base
kwargs:
sampler:
type: dist
kwargs: {}
batch_size: 4
dataloader:
type: base
kwargs:
num_workers: 4
alignment: 32
worker_init: true
pad_type: batch_pad
trainer: # Required.
max_epoch: &max_epoch 6 # total epochs for the training
save_freq: 1
test_freq: 1
only_save_latest: false
optimizer: # optimizer = SGD(params,lr=0.01,momentum=0.937,weight_decay=0.0005)
register_type: yolov5
type: SGD
kwargs:
lr: 0.0000003125
momentum: 0.9
nesterov: true
weight_decay: 0.0 # weight_decay = 0.0005 * batch_szie / 64
lr_scheduler: # lr_scheduler = MultStepLR(optimizer, milestones=[9,14],gamma=0.1)
warmup_epochs: 0 # set to be 0 to disable warmup. When warmup, target_lr = init_lr * total_batch_size
warmup_type: linear
warmup_ratio: 0.001
type: MultiStepLR
kwargs:
milestones: [2, 4] # epochs to decay lr
gamma: 0.1 # decay rate
saver:
save_dir: checkpoints/yolox_s_ret_a1_comloc_quant_tengine
results_dir: results_dir/yolox_s_ret_a1_comloc_quant_tengine
resume_model: /United-Perception/train_config/pretrain/300_65_ckpt_best.pth
auto_resume: True
ema:
enable: false
ema_type: exp
kwargs:
decay: 0.9998
net:
- name: backbone
type: yolox_s
kwargs:
out_layers: [2, 3, 4]
out_strides: [8, 16, 32]
normalize: {type: mqbench_freeze_bn}
act_fn: {type: Silu}
- name: neck
prev: backbone
type: YoloxPAFPN
kwargs:
depth: 0.33
out_strides: [8, 16, 32]
normalize: {type: mqbench_freeze_bn}
act_fn: {type: Silu}
- name: roi_head
prev: neck
type: YoloXHead
kwargs:
num_classes: *num_classes
width: 0.5
num_point: &dense_points 1
normalize: {type: mqbench_freeze_bn}
act_fn: {type: Silu}
- name: post_process
prev: roi_head
type: retina_post_iou
kwargs:
num_classes: *num_classes
# number of classes including backgroudn. for rpn, it's 2; for RetinaNet, it's 81
cfg:
cls_loss:
type: quality_focal_loss
kwargs:
gamma: 2.0
iou_branch_loss:
type: sigmoid_cross_entropy
loc_loss:
type: compose_loc_loss
kwargs:
loss_cfg:
- type: iou_loss
kwargs:
loss_type: giou
loss_weight: 1.0
- type: l1_loss
kwargs:
loss_weight: 1.0
anchor_generator:
type: hand_craft
kwargs:
anchor_ratios: [1] # anchor strides are provided as feature strides by feature extractor
anchor_scales: [4] # scale of anchors relative to feature map
roi_supervisor:
type: atss
kwargs:
top_n: 9
use_iou: true
roi_predictor:
type: base
kwargs:
pre_nms_score_thresh: 0.05 # to reduce computation
pre_nms_top_n: 1000
post_nms_top_n: 1000
roi_min_size: 0 # minimum scale of a valid roi
merger:
type: retina
kwargs:
top_n: 100
nms:
type: naive
nms_iou_thresh: 0.65
以下是报错信息:
[MQBENCH] INFO: Enable observer and Disable quantize for act_fake_quant
[MQBENCH] INFO: Enable observer and Disable quantize for act_fake_quant
[MQBENCH] INFO: Enable observer and Disable quantize for act_fake_quant
Traceback (most recent call last):
File "/opt/conda/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/opt/conda/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/data/lsc/United-Perception/up/__main__.py", line 27, in <module>
main()
File "/data/lsc/United-Perception/up/__main__.py", line 21, in main
args.run(args)
File "/data/lsc/United-Perception/up/commands/train.py", line 144, in _main
launch(main, args.num_gpus_per_machine, args.num_machines, args=args, start_method=args.fork_method)
File "/data/lsc/United-Perception/up/utils/env/launch.py", line 52, in launch
mp.start_processes(
File "/opt/conda/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 188, in start_processes
while not context.join():
File "/opt/conda/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 150, in join
raise ProcessRaisedException(msg, error_index, failed_process.pid)
torch.multiprocessing.spawn.ProcessRaisedException:
-- Process 3 terminated with the following error:
Traceback (most recent call last):
File "/opt/conda/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 59, in _wrap
fn(i, *args)
File "/data/lsc/United-Perception/up/utils/env/launch.py", line 117, in _distributed_worker
main_func(args)
File "/data/lsc/United-Perception/up/commands/train.py", line 134, in main
runner = RUNNER_REGISTRY.get(runner_cfg['type'])(cfg, **runner_cfg['kwargs'])
File "/data/lsc/United-Perception/up/tasks/quant/runner/quant_runner.py", line 17, in __init__
super(QuantRunner, self).__init__(config, work_dir, training)
File "/data/lsc/United-Perception/up/runner/base_runner.py", line 59, in __init__
self.build()
File "/data/lsc/United-Perception/up/tasks/quant/runner/quant_runner.py", line 34, in build
self.calibrate()
File "/data/lsc/United-Perception/up/tasks/quant/runner/quant_runner.py", line 182, in calibrate
self.model(batch)
File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/data/lsc/United-Perception/up/tasks/quant/models/model_helper.py", line 76, in forward
output = submodule(input)
File "/opt/conda/lib/python3.8/site-packages/torch/fx/graph_module.py", line 308, in wrapped_call
return cls_call(self, *args, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/torch/fx/graph_module.py", line 308, in wrapped_call
return cls_call(self, *args, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "<eval_with_key_2>", line 4, in forward
input_1_post_act_fake_quantizer = self.input_1_post_act_fake_quantizer(input_1); input_1 = None
File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/data/lsc/United-Perception/MQBench/mqbench/fake_quantize/fixed.py", line 20, in forward
self.activation_post_process(X.detach())
AttributeError: 'dict' object has no attribute 'detach'
辛苦帮忙看下是什么问题?是mqbench还没有支持tengine么