MCPcopy Create free account
hub / github.com/alibaba/MNN / mobileNetV1Expr

Function mobileNetV1Expr

benchmark/exprModels/MobileNetExpr.cpp:27–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27VARP mobileNetV1Expr(MobileNetWidthType alpha, MobileNetResolutionType beta, int numClass) {
28 int inputSize, poolSize; // MobileNet_224, MobileNet_192, MobileNet_160, MobileNet_128
29 {
30 auto inputSizeMap = std::map<MobileNetResolutionType, int>({
31 {MobileNet_224, 224},
32 {MobileNet_192, 192},
33 {MobileNet_160, 160},
34 {MobileNet_128, 128}
35 });
36 if (inputSizeMap.find(beta) == inputSizeMap.end()) {
37 MNN_ERROR("MobileNetResolutionType (%d) not support, only support [MobileNet_224, MobileNet_192, MobileNet_160, MobileNet_128]\n", beta);
38 return VARP(nullptr);
39 }
40 inputSize = inputSizeMap[beta];
41 poolSize = inputSize / 32;
42 }
43
44 int channels[6]; // MobileNet_100, MobileNet_075, MobileNet_050, MobileNet_025
45 {
46 auto channelsMap = std::map<MobileNetWidthType, int>({
47 {MobileNet_100, 32},
48 {MobileNet_075, 24},
49 {MobileNet_050, 16},
50 {MobileNet_025, 8}
51 });
52 if (channelsMap.find(alpha) == channelsMap.end()) {
53 MNN_ERROR("MobileNetWidthType (%d) not support, only support [MobileNet_100, MobileNet_075, MobileNet_050, MobileNet_025]\n", alpha);
54 return VARP(nullptr);
55 }
56 channels[0] = channelsMap[alpha];
57 }
58
59 for (int i = 1; i < 6; ++i) {
60 channels[i] = channels[0] * (1 << i);
61 }
62
63 auto x = _Input({1, 3, inputSize, inputSize}, NC4HW4);
64 x = _Conv(0.0f, 0.0f, x, {3, channels[0]}, {3, 3}, SAME, {2, 2}, {1, 1}, 1);
65 x = convBlock(x, {channels[0], channels[1]}, 1);
66 x = convBlock(x, {channels[1], channels[2]}, 2);
67 x = convBlock(x, {channels[2], channels[2]}, 1);
68 x = convBlock(x, {channels[2], channels[3]}, 2);
69 x = convBlock(x, {channels[3], channels[3]}, 1);
70 x = convBlock(x, {channels[3], channels[4]}, 2);
71 x = convBlock(x, {channels[4], channels[4]}, 1);
72 x = convBlock(x, {channels[4], channels[4]}, 1);
73 x = convBlock(x, {channels[4], channels[4]}, 1);
74 x = convBlock(x, {channels[4], channels[4]}, 1);
75 x = convBlock(x, {channels[4], channels[4]}, 1);
76 x = convBlock(x, {channels[4], channels[5]}, 2);
77 x = convBlock(x, {channels[5], channels[5]}, 1);
78 x = _AvePool(x, {poolSize, poolSize}, {1, 1}, VALID);
79 x = _Conv(0.0f, 0.0f, x, {channels[5], numClass}, {1, 1}, VALID, {1, 1}, {1, 1}, 1); // reshape FC with Conv1x1
80 x = _Softmax(x, -1);
81 return x;
82}
83
84static VARP bottleNeck(VARP x, INTS channels, int stride, int expansionRatio) {

Callers 1

mainFunction · 0.85

Calls 8

_InputFunction · 0.85
_AvePoolFunction · 0.85
_SoftmaxFunction · 0.85
convBlockFunction · 0.70
VARPFunction · 0.50
_ConvFunction · 0.50
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected