Aufgrund von Umarbeiten des s3 Storage wird es in GitLab, in nächster Zeit, mögliche Performance-Einbußen geben. Näheres dazu unter: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/43/show_ticket/6670

CNNArch.mc4 4.94 KB
Newer Older
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
1
package de.monticore.lang.monticar;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
2

3
grammar CNNArch extends de.monticore.lang.math.Math {
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
4

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
5
    symbol scope CNNArchCompilationUnit = "Architecture" Name& "{" Architecture "}";
6

7
    Architecture = (MainLayer)+ OutputLayer;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
8

9

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
10 11 12 13 14 15 16 17
    interface Layer;
    ast Layer = method ASTMethod getMethod(){};
    interface Method;
    interface MainLayerMethod extends Method;
    interface OutputLayerMethod extends Method;

    interface ArgumentAssignment;
    ast ArgumentAssignment = method public Enum getLhs(){}
18
                             method public ASTArgumentRhs getRhs(){};
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
19

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
20
    ArgumentRhs = number:Number
21
                | tuple:Tuple
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
22 23
                | booleanVal:Boolean
                | type:ArgumentKeyword;
24 25
    Tuple = "(" values:Number "," values:(Number || ",")+ ")";
    enum Boolean = TRUE:"true" | FALSE:"false" | TRUE:"True" | FALSE:"False";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
26 27
    interface ArgumentKeyword;
    ast ArgumentKeyword = method Optional<String> getName(){};
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
28 29 30 31 32 33 34 35 36



    MainLayer implements Layer = method:MainLayerMethod;
    OutputLayer implements Layer = method:OutputLayerMethod;



    ConvolutionMethod implements MainLayerMethod = name:"Convolution" "(" arguments:(ConvolutionArgumentAssignment || ",")* ")";
37
    ConvolutionArgumentAssignment implements ArgumentAssignment = lhs:ConvolutionArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
38 39 40 41 42 43 44
    enum ConvolutionArgument = KERNEL:"kernel"               //required
                             | NUMFILTER:"num_filter"        //required
                             | STRIDE:"stride"
                             | PAD:"pad"
                             | NOBIAS:"no_bias";

    FullyConnectedMethod implements MainLayerMethod = name:"FullyConnected" "(" arguments:(FullyConnectedArgumentAssignment || ",")* ")";
45
    FullyConnectedArgumentAssignment implements ArgumentAssignment = lhs:FullyConnectedArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
46
    enum FullyConnectedArgument = NUMHIDDEN:"units"     //required
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
47 48 49
                                | NOBIAS:"no_bias";

    ActivationMethod implements MainLayerMethod = name:"Activation" "(" arguments:(ActivationArgumentAssignment || ",")* ")";
50
    ActivationArgumentAssignment implements ArgumentAssignment = lhs:ActivationArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
51 52 53 54 55
    enum ActivationArgument = ACTTYPE:"type";            //required
    ActivationType implements ArgumentKeyword = name:"relu"
                                              | name:"sigmoid"
                                              | name:"tanh"
                                              | name:"softmax";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
56 57

    PoolingMethod implements MainLayerMethod = name:"Pooling" "(" arguments:(PoolingArgumentAssignment || ",")* ")";
58
    PoolingArgumentAssignment implements ArgumentAssignment = lhs:PoolingArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
59
    enum PoolingArgument = KERNEL:"kernel"                   //required
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
60
                         | POOLTYPE:"type"                   //required
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
61 62 63
                         | POOLINGCONVENTION:"pooling_convention"
                         | STRIDE:"stride"
                         | PAD:"pad";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
64 65 66 67 68
    PoolingType implements ArgumentKeyword = name:"max"
                                           | name:"avg"
                                           | name:"sum";
    PoolingConvention implements ArgumentKeyword = name:"full"
                                                 | name:"valid";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
69 70

    DropoutMethod implements MainLayerMethod = name:"Dropout" "(" arguments:(DropoutArgumentAssignment || ",")* ")";
71
    DropoutArgumentAssignment implements ArgumentAssignment = lhs:DropoutArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
72
    enum DropoutArgument = P:"p";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
73 74

    LRNMethod implements MainLayerMethod = name:"LRN" "(" arguments:(LRNArgumentAssignment || ",")* ")";
75
    LRNArgumentAssignment implements ArgumentAssignment = lhs:LRNArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
76 77 78 79 80 81 82
    enum LRNArgument = ALPHA:"alpha"
                     | BETA:"beta"
                     | KNORM:"knorm"
                     | NSIZE:"nsize";                         //required



Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
83
    StandardOutputLayerMethod implements OutputLayerMethod = name:"Output" "(" arguments:(StandardOutputArgumentAssignment || ",")* ")";
84
    StandardOutputArgumentAssignment implements ArgumentAssignment = lhs:StandardOutputArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98
    enum StandardOutputArgument = GRADSCALE:"grad_scale"
                                | TYPE:"type";
    OutputType implements ArgumentKeyword = name:"softmax"
                                          | name:"linear"
                                          | name:"logistic"
                                          | name:"mae";


    //SVMOutputLayerMethod implements OutputLayerMethod = name:"SVMOutput" "("
    //                                                        arguments:(SVMOutputArgumentAssignment || ",")* ")";
    //SVMOutputArgumentAssignment implements ArgumentAssignment = lhs:SVMOutputArgument "=" rhs:ArgumentRhs;
    //enum SVMOutputArgument = MARGIN:"margin"
    //                       | REGULARIZATIONCOEFFICIENT:"regularization_coefficient"
    //                       | USELINEAR:"use_linear";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
99
}