ResNeXt50.emadl 1.77 KB
Newer Older
1
2
component ResNeXt50{
    ports in Z(0:255)^{3, 224, 224} image,
3
         out Q(0:1)^{1000} predictions;
4
5

    implementation CNN {
6
7
        def conv(kernel, channels, stride=1, act=true){
            Convolution(kernel=(kernel,kernel), channels=channels, stride=(stride,stride)) ->
8
9
10
11
            BatchNorm() ->
            Relu(?=act)
        }
        def resGroup(innerChannels, outChannels, stride=1){
12
13
14
            conv(kernel=1, channels=innerChannels) ->
            conv(kernel=3, channels=innerChannels, stride=stride) ->
            conv(kernel=1, channels=outChannels, act=false)
15
16
17
18
19
20
21
22
23
        }
        def resLayer(innerChannels, outChannels, stride=1, changedChannels=false){
            (
                resGroup(innerChannels=innerChannels,
                         outChannels=outChannels,
                         stride=stride,
                         | = 32) ->
                Add()
            |
24
                conv(kernel=1, channels=outChannels, stride=stride, act=false, ? = stride!=1 || changedChannels)
25
26
27
28
29
30
            ) ->
            Add() ->
            Relu()
        }

        image ->
31
        conv(kernel=7, channels=64, stride=2) ->
32
33
34
35
36
37
38
39
40
41
42
        Pooling(pool_type="max", kernel=(3,3), stride=(2,2)) ->
        resLayer(innerChannels=4, outChannels=256, changedChannels=true, -> = 3) ->
        resLayer(innerChannels=8, outChannels=512, stride=2) ->
        resLayer(innerChannels=8, outChannels=512, -> = 3) ->
        resLayer(innerChannels=16, outChannels=1024, stride=2) ->
        resLayer(innerChannels=16, outChannels=1024, -> = 5) ->
        resLayer(innerChannels=32, outChannels=2048, stride=2) ->
        resLayer(innerChannels=32, outChannels=2048, -> = 2) ->
        GlobalPooling(pool_type="avg") ->
        FullyConnected(units=1000) ->
        Softmax() ->
43
        predictions;
44
45
    }
}