Aufgrund einer Wartung wird GitLab am 18.05. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 18.05. between 8:00 and 9:00 am.

Commit 7eaf3aa1 authored by Thomas Michael Timmermanns's avatar Thomas Michael Timmermanns
Browse files

Complete rework of the language.

Added keywords 'def', 'group' 'output' and 'repeat'.
Added more tests and architectures of existing networks.
parent eb7ab1af
package de.monticore.lang.monticar;
grammar CNNArch extends de.monticore.lang.math.Math {
grammar CNNArch extends de.monticore.lang.monticar.Common2 {
symbol scope CNNArchCompilationUnit = "Architecture" Name& "{" Architecture "}";
symbol scope CNNArchCompilationUnit = "architecture" Name& "{" Architecture "}";
Architecture = (MainLayer)+ OutputLayer;
Architecture = defs:VarDef* inputStructure:InputStructure elements:ArchitectureElement*;
interface VarDef;
symbol InputDef implements VarDef = "def" "input" Name& (ArrayDeclaration)?;
symbol OutputDef implements VarDef = "def" "output" Name& (ArrayDeclaration)?;
interface Layer;
ast Layer = method ASTMethod getMethod(){};
interface ArchitectureElement extends GroupElement;
interface GroupElement;
interface Method;
interface MainLayerMethod extends Method;
interface OutputLayerMethod extends Method;
interface GroupMethod extends Method,GroupElement;
interface MergeMethod extends Method;
interface LayerMethod extends Method,ArchitectureElement;
interface InputStructure;
interface InputElement;
interface ArgumentListing;
interface ArgumentAssignment;
ast ArgumentAssignment = method public Enum getLhs(){}
method public ASTArgumentRhs getRhs(){};
interface GroupStructure;
interface Group;
SingleInput implements InputStructure,InputElement = input:Name@InputDef "->";
ArrayInput implements InputElement = input:Name@InputDef "[" (index:UnitNumberResolution)? "]" "->";
InputGroupStructure implements GroupStructure,InputStructure = groups:InputGroup+
MergeStructure;
OutputStructure implements ArchitectureElement = "output" (GroupOrdinalRange)? "{"
elements:ArchitectureElement* "}" "->"
output:Name@OutputDef;
RepeatStructure implements ArchitectureElement = "repeat"
intLiteral:UnitNumberResolution "{"
ArchitectureElement* "}";
StandardGroupStructure implements ArchitectureElement,GroupStructure = groups:StandardGroup+
MergeStructure;
MergeStructure = "merge" method:MergeMethod;
StandardGroup implements Group = declaration:GroupDeclaration "{"
body:GroupBody "}";
InputGroup implements Group = declaration:GroupDeclaration "{"
input:InputElement
body:GroupBody "}";
GroupDeclaration = "group" (GroupOrdinalRange|GroupOrdinal);
GroupOrdinal = intLiteral:UnitNumberResolution;
GroupOrdinalRange = startInt:UnitNumberResolution".."endInt:UnitNumberResolution;
GroupBody = elements:GroupElement*;
ArgumentRhs = number:Number
| tuple:Tuple
| booleanVal:Boolean
| type:ArgumentKeyword;
| booleanVal:BooleanLiteral;
//| type:ArgumentKeyword;
Tuple = "(" values:Number "," values:(Number || ",")+ ")";
enum Boolean = TRUE:"true" | FALSE:"false" | TRUE:"True" | FALSE:"False";
interface ArgumentKeyword;
ast ArgumentKeyword = method Optional<String> getName(){};
//interface ArgumentKeyword;
//ast ArgumentKeyword = method Optional<String> getName(){};
ast Method = method ASTArgumentListing getArgumentListing(){}
method Enum getType(){};
ast ArgumentAssignment = method Enum getLhs(){}
method ASTArgumentRhs getRhs(){};
//ast ArgumentListing = method java.util.List<? extends ASTArgumentAssignment> getArguments(){};
ast InputElement = method String getInput(){}
method Optional<de.monticore.lang.monticar.cnnarch._symboltable.InputDefSymbol> getInputSymbol(){};
ast Group = method ASTGroupDeclaration getDeclaration(){}
method ASTGroupBody getBody(){};
MainLayer implements Layer = method:MainLayerMethod;
OutputLayer implements Layer = method:OutputLayerMethod;
ConcatenateMethod implements MergeMethod = type:ConcatenateType "(" argumentListing:ConcatenateArgumentListing ")";
ConcatenateArgumentListing implements ArgumentListing = arguments:(ConcatenateArgumentAssignment || ",")*;
ConcatenateArgumentAssignment implements ArgumentAssignment = lhs:ConcatenateArgument "=" rhs:ArgumentRhs;
enum ConcatenateArgument = "placeholder";
enum ConcatenateType = "concatenate";
ConvolutionMethod implements MainLayerMethod = name:"Convolution" "(" arguments:(ConvolutionArgumentAssignment || ",")* ")";
AddMethod implements MergeMethod = type:AddType "(" argumentListing:AddArgumentListing ")";
AddArgumentListing implements ArgumentListing = arguments:(AddArgumentAssignment|| ",")*;
AddArgumentAssignment implements ArgumentAssignment = lhs:AddArgument "=" rhs:ArgumentRhs;
enum AddArgument = "placeholder";
enum AddType = "add";
SplitMethod implements GroupMethod = type:SplitType "(" argumentListing:SplitArgumentListing ")";
SplitArgumentListing implements ArgumentListing = arguments:(SplitArgumentAssignment || ",")*;
SplitArgumentAssignment implements ArgumentAssignment = lhs:SplitArgument "=" rhs:ArgumentRhs;
enum SplitArgument = "placeholder";
enum SplitType = "split";
ConvolutionMethod implements LayerMethod = type:ConvolutionType "(" argumentListing:ConvolutionArgumentListing ")";
ConvolutionArgumentListing implements ArgumentListing = arguments:(ConvolutionArgumentAssignment || ",")*;
ConvolutionArgumentAssignment implements ArgumentAssignment = lhs:ConvolutionArgument "=" rhs:ArgumentRhs;
enum ConvolutionArgument = KERNEL:"kernel" //required
| NUMFILTER:"num_filter" //required
| FILTERS:"filters" //required
| STRIDE:"stride"
| PAD:"pad"
| NOBIAS:"no_bias";
enum ConvolutionType = "convolution";
FullyConnectedMethod implements MainLayerMethod = name:"FullyConnected" "(" arguments:(FullyConnectedArgumentAssignment || ",")* ")";
FullyConnectedMethod implements LayerMethod = type:FullyConnectedType "(" argumentListing:FullyConnectedArgumentListing ")";
FullyConnectedArgumentListing implements ArgumentListing = arguments:(FullyConnectedArgumentAssignment || ",")*;
FullyConnectedArgumentAssignment implements ArgumentAssignment = lhs:FullyConnectedArgument "=" rhs:ArgumentRhs;
enum FullyConnectedArgument = NUMHIDDEN:"units" //required
enum FullyConnectedArgument = UNITS:"units" //required
| NOBIAS:"no_bias";
enum FullyConnectedType = "fullyConnected";
ActivationMethod implements MainLayerMethod = name:"Activation" "(" arguments:(ActivationArgumentAssignment || ",")* ")";
ActivationMethod implements LayerMethod = "activation."type:ActivationType "(" argumentListing:ActivationArgumentListing ")";
ActivationArgumentListing implements ArgumentListing = arguments:(ActivationArgumentAssignment || ",")*;
ActivationArgumentAssignment implements ArgumentAssignment = lhs:ActivationArgument "=" rhs:ArgumentRhs;
enum ActivationArgument = ACTTYPE:"type"; //required
ActivationType implements ArgumentKeyword = name:"relu"
| name:"sigmoid"
| name:"tanh"
| name:"softmax";
enum ActivationArgument = "placeholder";
enum ActivationType = "relu"
| "sigmoid"
| "tanh"
| "softmax";
PoolingMethod implements MainLayerMethod = name:"Pooling" "(" arguments:(PoolingArgumentAssignment || ",")* ")";
PoolingMethod implements LayerMethod = "pooling."type:PoolingType "(" argumentListing:PoolingArgumentListing ")";
PoolingArgumentListing implements ArgumentListing = arguments:(PoolingArgumentAssignment || ",")*;
PoolingArgumentAssignment implements ArgumentAssignment = lhs:PoolingArgument "=" rhs:ArgumentRhs;
enum PoolingArgument = KERNEL:"kernel" //required
| POOLTYPE:"type" //required
| POOLINGCONVENTION:"pooling_convention"
| STRIDE:"stride"
| PAD:"pad";
PoolingType implements ArgumentKeyword = name:"max"
| name:"avg"
| name:"sum";
PoolingConvention implements ArgumentKeyword = name:"full"
| name:"valid";
DropoutMethod implements MainLayerMethod = name:"Dropout" "(" arguments:(DropoutArgumentAssignment || ",")* ")";
DropoutArgumentAssignment implements ArgumentAssignment = lhs:DropoutArgument "=" rhs:ArgumentRhs;
enum DropoutArgument = P:"p";
| Global:"global";
enum PoolingType = "max"
| "avg";
LRNMethod implements MainLayerMethod = name:"LRN" "(" arguments:(LRNArgumentAssignment || ",")* ")";
LRNArgumentAssignment implements ArgumentAssignment = lhs:LRNArgument "=" rhs:ArgumentRhs;
enum LRNArgument = ALPHA:"alpha"
| BETA:"beta"
| KNORM:"knorm"
| NSIZE:"nsize"; //required
DropoutMethod implements LayerMethod = type:DropoutType "(" argumentListing:DropoutArgumentListing ")";
DropoutArgumentListing implements ArgumentListing = arguments:(DropoutArgumentAssignment || ",")*;
DropoutArgumentAssignment implements ArgumentAssignment = lhs:DropoutArgument "=" rhs:ArgumentRhs;
enum DropoutArgument = P:"p";
enum DropoutType = "dropout";
StandardOutputLayerMethod implements OutputLayerMethod = name:"Output" "(" arguments:(StandardOutputArgumentAssignment || ",")* ")";
StandardOutputArgumentAssignment implements ArgumentAssignment = lhs:StandardOutputArgument "=" rhs:ArgumentRhs;
enum StandardOutputArgument = GRADSCALE:"grad_scale"
| TYPE:"type";
OutputType implements ArgumentKeyword = name:"softmax"
| name:"linear"
| name:"logistic"
| name:"mae";
BatchNormMethod implements LayerMethod = type:BatchNormType "(" argumentListing:BatchNormArgumentListing ")";
BatchNormArgumentListing implements ArgumentListing = arguments:(BatchNormArgumentAssignment || ",")*;
BatchNormArgumentAssignment implements ArgumentAssignment = lhs:BatchNormArgument "=" rhs:ArgumentRhs;
enum BatchNormArgument = "placeholder";
enum BatchNormType = "batchNorm";
LrnMethod implements LayerMethod = type:LrnType "(" argumentListing:LrnArgumentListing ")";
LrnArgumentListing implements ArgumentListing = arguments:(LrnArgumentAssignment || ",")*;
LrnArgumentAssignment implements ArgumentAssignment = lhs:LrnArgument "=" rhs:ArgumentRhs;
enum LrnArgument = NSIZE:"nsize" //required
| ALPHA:"alpha"
| BETA:"beta"
| KNORM:"knorm";
enum LrnType = "lrn";
//SVMOutputLayerMethod implements OutputLayerMethod = name:"SVMOutput" "("
// arguments:(SVMOutputArgumentAssignment || ",")* ")";
//SVMOutputArgumentAssignment implements ArgumentAssignment = lhs:SVMOutputArgument "=" rhs:ArgumentRhs;
//enum SVMOutputArgument = MARGIN:"margin"
// | REGULARIZATIONCOEFFICIENT:"regularization_coefficient"
// | USELINEAR:"use_linear";
}
\ No newline at end of file
......@@ -20,27 +20,12 @@
*/
package de.monticore.lang.monticar.cnnarch._ast;
import de.monticore.lang.monticar.cnnarch._ast.ASTArgumentAssignment;
import java.util.LinkedList;
import java.util.List;
public interface ASTMethod extends ASTMethodTOP {
public interface ASTArgumentListing extends ASTArgumentListingTOP {
String getName();
List<? extends ASTArgumentAssignment> getArguments();
default List<? extends ASTArgumentAssignment> getArguments() {
return new LinkedList<ASTArgumentAssignment>();
}
default ASTArgumentRhs get(String lhsName) {
ASTArgumentRhs rhs = null;
lhsName = lhsName.replace("_", "");
for (ASTArgumentAssignment assignment : getArguments()) {
String assignmentLhs = assignment.getLhs().name();
if (assignmentLhs.equalsIgnoreCase(lhsName)) {
rhs = assignment.getRhs();
}
}
return rhs;
}
}
......@@ -20,21 +20,20 @@
*/
package de.monticore.lang.monticar.cnnarch._cocos;
import de.monticore.lang.monticar.cnnarch._ast.*;
import de.monticore.lang.monticar.cnnarch._ast.ASTArchitecture;
import de.monticore.lang.monticar.cnnarch._ast.ASTArchitectureElement;
import java.util.List;
public class ArchitectureCheck implements CNNArchASTArchitectureCoCo {
//private static final ASTFlattenMethod.Builder flattenMethodBuilder = new ASTFlattenMethod.Builder().name("Flatten");
@Override
public void check(ASTArchitecture node) {
completeArchitecture(node.getMainLayers());
completeArchitecture(node.getElements());
}
//set position for each layer and insert flatten layer if necessary
private void completeArchitecture(List<ASTMainLayer> layers) {
private void completeArchitecture(List<ASTArchitectureElement> layers) {
/*int pos = 0;
boolean isConvNet = false;
int flattenPos = -1;
......
......@@ -20,6 +20,7 @@
*/
package de.monticore.lang.monticar.cnnarch._cocos;
public class CNNArchCocos {
public static CNNArchCoCoChecker createChecker() {
......
......@@ -20,6 +20,7 @@
*/
package de.monticore.lang.monticar.cnnarch._cocos;
import de.monticore.lang.monticar.cnnarch._ast.ASTArgumentAssignment;
import de.monticore.lang.monticar.cnnarch._ast.ASTMethod;
import de.se_rwth.commons.logging.Log;
......@@ -32,7 +33,7 @@ public class DuplicateArgumentCheck implements CNNArchASTMethodCoCo {
@Override
public void check(ASTMethod node) {
Set<Enum> set = new HashSet<>();
for (ASTArgumentAssignment assignment : node.getArguments()) {
for (ASTArgumentAssignment assignment : node.getArgumentListing().getArguments()) {
if (set.contains(assignment.getLhs())) {
Log.error("0x03011 Multiple assignments of the same argument are not allowed",
assignment.get_SourcePositionStart());
......
......@@ -20,11 +20,6 @@
*/
package de.monticore.lang.monticar.cnnarch._symboltable;
import de.monticore.symboltable.MutableScope;
import de.monticore.symboltable.ResolvingConfiguration;
import de.monticore.symboltable.SymbolTableCreator;
import java.util.Optional;
public class CNNArchLanguage extends CNNArchLanguageTOP {
......
......@@ -20,6 +20,7 @@
*/
package de.monticore.lang.monticar.cnnarch._symboltable;
import de.monticore.lang.monticar.cnnarch._ast.ASTArchitecture;
import de.monticore.lang.monticar.cnnarch._ast.ASTCNNArchCompilationUnit;
import de.monticore.symboltable.ArtifactScope;
......@@ -28,7 +29,10 @@ import de.monticore.symboltable.MutableScope;
import de.monticore.symboltable.ResolvingConfiguration;
import de.se_rwth.commons.logging.Log;
import java.util.*;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Optional;
public class CNNArchSymbolTableCreator extends CNNArchSymbolTableCreatorTOP {
......
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch.datamodel;
public class Activation {
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch.datamodel;
public class Architecture {
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch.datamodel;
public class BatchNorm {
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch.datamodel;
public class Convolution {
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch.datamodel;
public class DataModel {
public void resolveDimensions(){
}
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch.datamodel;
public class Dimension {
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch.datamodel;
public class FullyConnected {
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.