hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
import cv2
from rknn.api import RKNN
 
if __name__ == '__main__':
 
    # Create RKNN object
    rknn = RKNN(verbose=True)
    
    # Pre-process config
    print('--> Config model')
    rknn.config(mean_values=[127.5, 127.5, 127.5], std_values=[127.5, 127.5, 127.5])
    print('done')
 
    # Load model
    print('--> Loading model')
    ret = rknn.load_tensorflow(tf_pb='./ssd_mobilenet_v2.pb',
                               inputs=['FeatureExtractor/MobilenetV2/MobilenetV2/input'],
                               outputs=['concat_1', 'concat'],
                               input_size_list=[[1,300,300,3]])
    if ret != 0:
        print('Load model failed!')
        exit(ret)
    print('done')
 
    # Build model
    print('--> hybrid_quantization_step1')
    ret = rknn.hybrid_quantization_step1(dataset='./dataset.txt', proposal=False)
    if ret != 0:
        print('hybrid_quantization_step1 failed!')
        exit(ret)
    print('done')
 
    # Tips
    print('Please modify ssd_mobilenet_v2.quantization.cfg!')
    print('==================================================================================================')
    print('Modify Method: Fill the customized_quantize_layers with the output name & dtype of the custom layer.')
    print('')
    print('For example:')
    print('    custom_quantize_layers:')
    print('        Conv__344:0: float16')
    print('        FeatureExtractor/MobilenetV2/expanded_conv/depthwise/Relu6:0: float16')
    print('Or:')
    print('    custom_quantize_layers: {')
    print('        Conv__344:0: float16,')
    print('        FeatureExtractor/MobilenetV2/expanded_conv/depthwise/Relu6:0: float16,')
    print('    }')
    print('==================================================================================================')
 
    rknn.release()