| 25 | } |
| 26 | |
| 27 | VARP 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 | |
| 84 | static VARP bottleNeck(VARP x, INTS channels, int stride, int expansionRatio) { |