| 56 | } |
| 57 | |
| 58 | VARP resNetExpr(ResNetType resNetType, int numClass) { |
| 59 | std::vector<int> numbers; |
| 60 | { |
| 61 | auto numbersMap = std::map<ResNetType, std::vector<int>>({ |
| 62 | {ResNet18, {2, 2, 2, 2}}, |
| 63 | {ResNet34, {3, 4, 6, 3}}, |
| 64 | {ResNet50, {3, 4, 6, 3}}, |
| 65 | {ResNet101, {3, 4, 23, 3}}, |
| 66 | {ResNet152, {3, 8, 36, 3}} |
| 67 | }); |
| 68 | if (numbersMap.find(resNetType) == numbersMap.end()) { |
| 69 | MNN_ERROR("resNetType (%d) not support, only support [ResNet18, ResNet34, ResNet50, ResNet101, ResNet152]\n", resNetType); |
| 70 | return VARP(nullptr); |
| 71 | } |
| 72 | numbers = numbersMap[resNetType]; |
| 73 | } |
| 74 | std::vector<int> channels({64, 64, 128, 256, 512}); |
| 75 | { |
| 76 | if (resNetType != ResNet18 && resNetType != ResNet34) { |
| 77 | channels[0] = 16; |
| 78 | } |
| 79 | } |
| 80 | std::vector<int> strides({1, 2, 2, 2}); |
| 81 | int finalChannel = channels[4] * 4; |
| 82 | auto x = _Input({1, 3, 224, 224}, NC4HW4); |
| 83 | x = _Conv(0.0f, 0.0f, x, {3, 64}, {7, 7}, SAME, {2, 2}, {1, 1}, 1); |
| 84 | x = _MaxPool(x, {3, 3}, {2, 2}, SAME); |
| 85 | for (int i = 0; i < 4; ++i) { |
| 86 | if (resNetType == ResNet18 || resNetType == ResNet34) { |
| 87 | x = residualBlock(x, {channels[i], channels[i+1]}, strides[i], numbers[i]); |
| 88 | } else { |
| 89 | x = bottleNeckBlock(x, {channels[i] * 4, channels[i+1], channels[i+1] * 4}, strides[i], numbers[i]); |
| 90 | } |
| 91 | } |
| 92 | x = _AvePool(x, {7, 7}, {1, 1}, VALID); |
| 93 | x = _Conv(0.0f, 0.0f, x, {x->getInfo()->dim[1], numClass}, {1, 1}, VALID, {1, 1}, {1, 1}, 1); // reshape FC with Conv1x1 |
| 94 | x = _Softmax(x, -1); |
| 95 | return x; |
| 96 | } |
no test coverage detected