ResNeXt50.emadl 1.92 KB
Newer Older
1
2
component ResNeXt50{
    ports in Z(0:255)^{3, 224, 224} image,
3
         out Q(0:1)^{1000,1,1} predictions;
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

    implementation CNN {

        def conv(filter, channels, stride=1, act=true){
            Convolution(kernel=filter, channels=channels, stride=(stride,stride)) ->
            BatchNorm() ->
            Relu(?=act)
        }
        def resGroup(innerChannels, outChannels, stride=1){
            conv(filter=(1,1), channels=innerChannels) ->
            conv(filter=(3,3), channels=innerChannels, stride=stride) ->
            conv(filter=(1,1), channels=outChannels, act=false)
        }
        def skip(outChannels, stride){
            Convolution(kernel=(1,1), channels=outChannels, stride=(stride,stride)) ->
            BatchNorm()
        }
        def resLayer(innerChannels, outChannels, stride=1, changedChannels=false){
            (
                resGroup(innerChannels=innerChannels,
                         outChannels=outChannels,
                         stride=stride,
                         | = 32) ->
                Add()
            |
                skip(outChannels=outChannels, stride=stride, ? = stride!=1 || changedChannels)
            ) ->
            Add() ->
            Relu()
        }

        image ->
        conv(filter=(7,7), channels=64, stride=2) ->
        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() ->
        predictions
    }
}