ResNeXt50.emadl 1.82 KB
Newer Older
Bernhard Rumpe's avatar
BR-sy    
Bernhard Rumpe committed
1
/* (c) https://github.com/MontiCore/monticore */
2
3
component ResNeXt50{
    ports in Z(0:255)^{3, 224, 224} image,
4
         out Q(0:1)^{1000} predictions;
5
6

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

        image ->
32
        conv(kernel=7, channels=64, stride=2) ->
33
34
35
36
37
38
39
40
41
42
43
        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() ->
44
        predictions;
45
    }
Bernhard Rumpe's avatar
BR-sy    
Bernhard Rumpe committed
46
}