tusen-ai / simpledet

A Simple and Versatile Framework for Object Detection and Instance Recognition
Apache License 2.0
3.08k stars 488 forks source link

support quantize training #243

Closed XiaotaoChen closed 5 years ago

XiaotaoChen commented 5 years ago

the file for mxnet

cp operator_cxx/contrib/quantization_int* /path/to/mxnet_home/src/operator/contrib/
cp py_for_mxnet/initializer.py /path/to/mxnet_home/python/mxnet/

the quantize op

operator_cxx/contrib/quantization_int8-inl.h
operator_cxx/contrib/quantization_int8.cc
operator_cxx/contrib/quantization_int8.cu

the initializer for aux params in quantization int8

py_for_mxnet/initializer.py

how to run int8 training

python detection_train.py --config config/faster_r50v1c4_c5_512roi_1x.py

quantization config

# for quantize int8 training
        quantize_flag = True
        '''
        delya_quant: after delay_quant iters, the quantization working actually.
        ema_decay:  the hyperparameter for activation threshold update.
        grad_mode:  the mode for gradients pass. there are two mode: ste or clip. 
                    ste mean straightforward pass the out gradients to data,
                    clip mean only pass the gradients whose value of data in the range of [-threshold, threshold],
                              the gradients of outer is settting to 0.
        workspace:  the temporary space used in grad_mode=clip
        '''
        base_quant_attrs = {
            "delay_quant": "0", 
            "ema_decay": "0.99",
            "grad_mode": "ste",
            "workspace": "1024"
        }
        # quantized_op = ["Convolution", "FullyConnected", "Deconvolution","Concat", "Pooling", "add_n", "elemwise_add"]  # the operators of "Concat", "Pooling", "add_n", "elemwise_add"  haven't verify the final accuracy match to the fp32 accuracy. but those opeartors can be quantized.
        quantized_op = ["Convolution", "FullyConnected", "Deconvolution"] 
XiaotaoChen commented 5 years ago

I modified the code with your advices. @RogerChern @xchani please help review again. Thanks.

RogerChern commented 5 years ago

pending for the wheel files