intial commit

parents
This diff is collapsed.
This diff is collapsed.
******************************************************************************
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.montiarc;
grammar CNNArch extends de.monticore.common.Common {
Architecture = "architecture"
name:Name "("
inputPort:Name& ")" "{"
(MainLayer)+
outputPort:Name& "="
OutputLayer
"}";
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(){}
method public ASTRhs getRhs(){};
Rhs = stringVal:String
| intVal:Num_Int
| doubleVal:Num_Double
| intTuple:IntTuple
| refOrBool:Name;
IntTuple = "(" values:Num_Int "," values:(Num_Int || ",")+ ")";
MainLayer implements Layer = method:MainLayerMethod;
OutputLayer implements Layer = method:OutputLayerMethod;
ConvolutionMethod implements MainLayerMethod = name:"Convolution" "(" arguments:(ConvolutionArgumentAssignment || ",")* ")";
ConvolutionArgumentAssignment implements ArgumentAssignment = lhs:ConvolutionArgument "=" rhs:Rhs;
enum ConvolutionArgument = KERNEL:"kernel" //required
| NUMFILTER:"num_filter" //required
| STRIDE:"stride"
| PAD:"pad"
| NOBIAS:"no_bias";
FullyConnectedMethod implements MainLayerMethod = name:"FullyConnected" "(" arguments:(FullyConnectedArgumentAssignment || ",")* ")";
FullyConnectedArgumentAssignment implements ArgumentAssignment = lhs:FullyConnectedArgument "=" rhs:Rhs;
enum FullyConnectedArgument = NUMHIDDEN:"num_hidden" //required
| NOBIAS:"no_bias";
ActivationMethod implements MainLayerMethod = name:"Activation" "(" arguments:(ActivationArgumentAssignment || ",")* ")";
ActivationArgumentAssignment implements ArgumentAssignment = lhs:ActivationArgument "=" rhs:Rhs;
enum ActivationArgument = ACTTYPE:"act_type"; //required
PoolingMethod implements MainLayerMethod = name:"Pooling" "(" arguments:(PoolingArgumentAssignment || ",")* ")";
PoolingArgumentAssignment implements ArgumentAssignment = lhs:PoolingArgument "=" rhs:Rhs;
enum PoolingArgument = KERNEL:"kernel" //required
| POOLTYPE:"pool_type" //required
| POOLINGCONVENTION:"pooling_convention"
| STRIDE:"stride"
| PAD:"pad";
DropoutMethod implements MainLayerMethod = name:"Dropout" "(" arguments:(DropoutArgumentAssignment || ",")* ")";
DropoutArgumentAssignment implements ArgumentAssignment = lhs:DropoutArgument "=" rhs:Rhs;
enum DropoutArgument = P:"p"
| MODE:"mode";
LRNMethod implements MainLayerMethod = name:"LRN" "(" arguments:(LRNArgumentAssignment || ",")* ")";
LRNArgumentAssignment implements ArgumentAssignment = lhs:LRNArgument "=" rhs:Rhs;
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();
};
StandardOutputArgumentAssignment implements ArgumentAssignment = lhs:StandardOutputArgument "=" rhs:Rhs;
enum StandardOutputArgument = GRADSCALE:"grad_scale";
SVMOutputLayerMethod implements OutputLayerMethod = name:"SVMOutput" "("
arguments:(SVMOutputArgumentAssignment || ",")* ")";
SVMOutputArgumentAssignment implements ArgumentAssignment = lhs:SVMOutputArgument "=" rhs:Rhs;
enum SVMOutputArgument = MARGIN:"margin"
| REGULARIZATIONCOEFFICIENT:"regularization_coefficient"
| USELINEAR:"use_linear";
}
\ No newline at end of file
/**
*
* ******************************************************************************
* 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.montiarc.cnnarch._ast;
import java.util.LinkedList;
import java.util.List;
public interface ASTMethod extends ASTMethodTOP {
String getName();
default List<? extends ASTArgumentAssignment> getAssignments() {
return new LinkedList<>();
}
default ASTRhs get(String lhsName) {
ASTRhs rhs = null;
lhsName = lhsName.replace("_", "");
for (ASTArgumentAssignment assignment : getAssignments()) {
String assignmentLhs = assignment.getLhs().name();
if (assignmentLhs.equalsIgnoreCase(lhsName)) {
rhs = assignment.getRhs();
}
}
return rhs;
}
}
/**
*
* ******************************************************************************
* 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.montiarc.cnnarch._ast;
import java.util.Optional;
public class ASTRhs extends ASTRhsTOP{
private boolean containsBoolean;
public ASTRhs() {
}
public ASTRhs(String stringVal, String intVal, String doubleVal, ASTIntTuple intTuple, String refOrBool) {
super(stringVal, intVal, doubleVal, intTuple, refOrBool);
}
@Override
public void setRefOrBool(String refOrBool) {
if (refOrBool.equalsIgnoreCase("true")
|| refOrBool.equalsIgnoreCase("false")){
containsBoolean = true;
super.setRefOrBool(refOrBool.toLowerCase());
}
else {
containsBoolean = false;
super.setRefOrBool(refOrBool);
}
}
public Optional<String> getRef(){
if (containsBoolean) {
return Optional.empty();
}
else {
return getRefOrBool();
}
}
public Optional<String> getBooleanVal(){
if (containsBoolean) {
return getRefOrBool();
}
else {
return Optional.empty();
}
}
}
\ No newline at end of file
/**
*
* ******************************************************************************
* 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.montiarc.cnnarch._cocos;
import de.monticore.lang.montiarc.cnnarch._ast.*;
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());
}
//set position for each layer and insert flatten layer if necessary
private void completeArchitecture(List<ASTMainLayer> layers) {
int pos = 0;
boolean isConvNet = false;
int flattenPos = -1;
for(ASTMainLayer layer : layers) {
if (layer.getMethod() instanceof ASTConvolutionMethod) {
isConvNet = true;
}
if (layer.getMethod() instanceof ASTFullyConnectedMethod && flattenPos == -1) {
flattenPos = pos;
pos++;
}
//layer.setPosition(pos);
pos++;
}
if (isConvNet) {
ASTMainLayer flattenLayer = (new ASTMainLayer.Builder()).method(flattenMethodBuilder.build()).build();
layers.add(flattenPos, flattenLayer);
//flattenLayer.setPosition(flattenPos);
}
}
}
\ No newline at end of file
/**
*
* ******************************************************************************
* 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.montiarc.cnnarch._cocos;
import de.monticore.lang.montiarc.cnnarch._ast.ASTArgumentAssignment;
import de.se_rwth.commons.logging.Log;
import java.util.HashSet;
import java.util.Set;
public class ArgumentCheck implements CNNArchASTArgumentAssignmentCoCo {
@Override
public void check(ASTArgumentAssignment node) {
}
}
\ No newline at end of file
/**
*
* ******************************************************************************
* 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.montiarc.cnnarch._cocos;
public class CNNArchCocos {
public static CNNArchCoCoChecker createChecker() {
return new CNNArchCoCoChecker()
.addCoCo(new ArgumentCheck())
.addCoCo(new ArchitectureCheck());
}
}
\ No newline at end of file
/**
*
* ******************************************************************************
* 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.montiarc.cnnarch._symboltable;
import de.monticore.symboltable.MutableScope;
import de.monticore.symboltable.ResolvingConfiguration;
import de.monticore.symboltable.SymbolTableCreator;
import de.monticore.symboltable.resolving.CommonResolvingFilter;
import java.util.Optional;
public class CNNArchLanguage extends CNNArchLanguageTOP {
public static final String FILE_ENDING = "cnna";
public CNNArchLanguage() {
super("CNNArch Language", FILE_ENDING);
}
@Override
protected CNNArchModelLoader provideModelLoader() {
return new CNNArchModelLoader(this);
}
@Override
protected void initResolvingFilters() {
super.initResolvingFilters();
}
@Override
public Optional<? extends SymbolTableCreator> getSymbolTableCreator(ResolvingConfiguration resolvingConfiguration, MutableScope mutableScope) {
return null;
}
}
<configuration>
<timestamp key="bySecond" datePattern="yyyy-MM-dd-HHmmss"/>
<!-- this is a console appender -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%date{yyyy-MM-dd HH:mm:ss} %-7([%level]) %logger{26} %message%n
</pattern>
</encoder>
</appender>
<root level="TRACE">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment