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.66 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

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

20
    ArgumentRhs = stringVal:String
21 22 23 24 25
                | number:Number
                | tuple:Tuple
                | booleanVal:Boolean;
    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 28 29 30 31 32 33 34



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



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

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

    ActivationMethod implements MainLayerMethod = name:"Activation" "(" arguments:(ActivationArgumentAssignment || ",")* ")";
48
    ActivationArgumentAssignment implements ArgumentAssignment = lhs:ActivationArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
49 50 51
    enum ActivationArgument = ACTTYPE:"act_type";            //required

    PoolingMethod implements MainLayerMethod = name:"Pooling" "(" arguments:(PoolingArgumentAssignment || ",")* ")";
52
    PoolingArgumentAssignment implements ArgumentAssignment = lhs:PoolingArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
53 54 55 56 57 58 59
    enum PoolingArgument = KERNEL:"kernel"                   //required
                         | POOLTYPE:"pool_type"              //required
                         | POOLINGCONVENTION:"pooling_convention"
                         | STRIDE:"stride"
                         | PAD:"pad";

    DropoutMethod implements MainLayerMethod = name:"Dropout" "(" arguments:(DropoutArgumentAssignment || ",")* ")";
60
    DropoutArgumentAssignment implements ArgumentAssignment = lhs:DropoutArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
61 62 63 64
    enum DropoutArgument = P:"p"
                         | MODE:"mode";

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

    FlattenMethod implements MainLayerMethod = name:"Flatten" "(" ")";




    StandardOutputLayerMethod implements OutputLayerMethod = (optName:"SoftmaxOutput"
                                                           | optName:"MAERegressionOutput"
                                                           | optName:"LinearRegressionOutput"
                                                           | optName:"LogisticRegressionOutput") "("
                                                             arguments:(StandardOutputArgumentAssignment || ",")* ")";
    ast StandardOutputLayerMethod = method public String getName(){
                                          return optName.get();
                                      };
84
    StandardOutputArgumentAssignment implements ArgumentAssignment = lhs:StandardOutputArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
85 86 87 88 89
    enum StandardOutputArgument = GRADSCALE:"grad_scale";


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