ResNet152.emadl 1.45 KB
Newer Older
Bernhard Rumpe's avatar
BR-sy  
Bernhard Rumpe committed
1
/* (c) https://github.com/MontiCore/monticore */
2 3 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
component ResNet152{
    ports in Z(0:255)^{3, 224, 224} image,
         out Q(0:1)^{1000} predictions;

    implementation CNN {
        def conv(kernel, channels, stride=1, act=true){
            Convolution(kernel=(kernel,kernel), channels=channels, stride=(stride,stride)) ->
            BatchNorm() ->
            Relu(?=act)
        }
        def resLayer(channels, stride=1, addSkipConv=false){
            (
                conv(kernel=1, channels=channels, stride=stride) ->
                conv(kernel=3, channels=channels) ->
                conv(kernel=1, channels=4*channels, act=false)
            |
                conv(kernel=1, channels=4*channels, stride=stride, act=false, ? = addSkipConv)
            ) ->
            Add() ->
            Relu()
        }

        image ->
        conv(kernel=7, channels=64, stride=2) ->
        Pooling(pool_type="max", kernel=(3,3), stride=(2,2)) ->
        resLayer(channels=64, addSkipConv=true) ->
        resLayer(channels=64, ->=2) ->
        resLayer(channels=128, stride=2, addSkipConv=true) ->
        resLayer(channels=128, ->=7) ->
        resLayer(channels=256, stride=2, addSkipConv=true) ->
        resLayer(channels=256, ->=35) ->
        resLayer(channels=512, stride=2, addSkipConv=true) ->
        resLayer(channels=512, ->=2) ->
        GlobalPooling(pool_type="avg") ->
        FullyConnected(units=1000) ->
        Softmax() ->
38
        predictions;
39
    }
Bernhard Rumpe's avatar
BR-sy  
Bernhard Rumpe committed
40
}