Complete rework of the language.

Added keywords 'def', 'group' 'output' and 'repeat'.
Added more tests and architectures of existing networks.
parent eb7ab1af
......@@ -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.
*
* 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;
import java.util.HashMap;
public class Layer {
private Dimension inputDimension;
private Dimension outputDimension;
private HashMap<String, Value> argumentMap;
public Dimension getInputDimension() {
return inputDimension;
}
public void setInputDimension(Dimension inputDimension) {
this.inputDimension = inputDimension;
}
public Dimension getOutputDimension() {
return outputDimension;
}
public void setOutputDimension(Dimension outputDimension) {
this.outputDimension = outputDimension;
}
public HashMap<String, Value> getArgumentMap() {
return argumentMap;
}
public void setArgumentMap(HashMap<String, Value> argumentMap) {
this.argumentMap = argumentMap;
}
}
/**
*
* ******************************************************************************
* 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 Pooling {
}
/**
*
* ******************************************************************************
* 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 Value {
}
......@@ -42,13 +42,15 @@ public class ParserTest {
public static final boolean ENABLE_FAIL_QUICK = false;
private static List<String> expectedParseErrorModels = Arrays.asList(
// incorrect argument name for a layer
"src/test/resources/WrongArgument.cnna",
"src/test/resources/invalid_tests/WrongArgument.cnna",
"src/test/resources/MissingOutputLayer.cnna",
"src/test/resources/invalid_tests/InvalidRepeatInput.cnna",
"src/test/resources/WrongOutputLayerPosition.cnna",
"src/test/resources/invalid_tests/MissingInput.cnna",
"src/test/resources/WrongActivationType.cnna")
"src/test/resources/invalid_tests/WrongInputPosition.cnna",
"src/test/resources/invalid_tests/WrongActivationType.cnna")
.stream().map(s -> Paths.get(s).toString())
.collect(Collectors.toList());
......
......@@ -35,12 +35,12 @@ public class SymtabTest extends AbstractSymtabTest {
@Test
public void testParsing() throws Exception {
CNNArchParser parser = new CNNArchParser();
assertTrue(parser.parse("src/test/resources/SimpleNetwork2.cnna").isPresent());
assertTrue(parser.parse("src/test/resources/valid_tests/SimpleNetworkSoftmax.cnna").isPresent());
}
@Test
public void testAlexnet(){
Scope symTab = createSymTab("src/test/resources");
Scope symTab = createSymTab("src/test/resources/architectures");
CNNArchCompilationUnitSymbol a = symTab.<CNNArchCompilationUnitSymbol>resolve(
"Alexnet",
CNNArchCompilationUnitSymbol.KIND).orElse(null);
......@@ -48,4 +48,24 @@ public class SymtabTest extends AbstractSymtabTest {
}
@Test
public void testMultiInput(){
Scope symTab = createSymTab("src/test/resources/architectures");
CNNArchCompilationUnitSymbol a = symTab.<CNNArchCompilationUnitSymbol>resolve(
"ThreeInputCNN_M14",
CNNArchCompilationUnitSymbol.KIND).orElse(null);
assertNotNull(a);
}
@Test
public void testMultiInputArray(){
Scope symTab = createSymTab("src/test/resources/architectures");
CNNArchCompilationUnitSymbol a = symTab.<CNNArchCompilationUnitSymbol>resolve(
"ThreeInputCNN_M14_alternative",
CNNArchCompilationUnitSymbol.KIND).orElse(null);
assertNotNull(a);
}
}
......@@ -20,10 +20,14 @@
*/
package de.monticore.lang.monticar.cnnarch.cocos;
import de.monticore.lang.monticar.cnnarch.ParserTest;
import de.monticore.lang.monticar.cnnarch._cocos.CNNArchCocos;
import de.monticore.lang.monticar.cnnarch._symboltable.CNNArchLanguage;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import static org.junit.Assert.assertTrue;
......@@ -31,9 +35,23 @@ public class AllCoCoTest extends AbstractCoCoTest {
String baseDir="src/test/resources";
@Test
public void testCoCosSimulator() throws IOException {
testModel("SimpleNetwork");
testModel("SimpleNetwork2");
testModel("Alexnet");
checkValid("architectures", "Alexnet");
checkValid("architectures", "Resnet34");
checkValid("architectures", "ResNeXt50");
checkValid("architectures", "SequentialAlexnet");
checkValid("architectures", "ThreeInputCNN_M14");
checkValid("architectures", "ThreeInputCNN_M14_alternative");
checkValid("architectures", "VGG16");
checkValid("valid_tests", "SimpleNetworkSoftmax");
checkValid("valid_tests", "SimpleNetworkSigmoid");
checkValid("valid_tests", "SimpleNetworkLinear");
checkValid("valid_tests", "SimpleNetworkRelu");
checkValid("valid_tests", "SimpleNetworkTanh");
checkValid("valid_tests", "VGG16_alternative");
checkValid("valid_tests", "DirectPerception");
checkValid("valid_tests", "SafetyNetwork");
/*testInvalidModel("DuplicateArgument",1,"x03011");
testInvalidModel("IntegerArgumentTypeTest",9,"x03012");
......
Architecture Alexnet {
Convolution(num_filter=96, kernel=(11,11), stride=(4,4))
Activation(type=relu)
LRN(alpha=0.0001, beta=0.75, knorm=2, nsize=5)
Pooling(type=max, kernel=(3, 3), stride=(2,2))
Convolution(num_filter=256, kernel=(5,5), pad=(2,2))
Activation(type=relu)
LRN(alpha=0.0001, beta=0.75, knorm=2, nsize=5)
Pooling(type=max, kernel=(3, 3), stride=(2,2))
Convolution(num_filter=384, kernel=(3,3), pad=(1,1))
Activation(type=relu)
Convolution(num_filter=384, kernel=(3,3), pad=(1,1))
Activation(type=relu)
Convolution(num_filter=256, kernel=(3,3), pad=(1,1))
Activation(type=relu)
FullyConnected(units=4096)
Activation(type=relu)
Dropout(p=0.5)
FullyConnected(units=4096)
Activation(type=relu)
Dropout(p=0.5)
Output(type=softmax)
}
\ No newline at end of file
Architecture DuplicateArgument{
FullyConnected(units=64, units=64)
Output(type=softmax)
}
\ No newline at end of file
Architecture IntegerArgumentTypeTest {
Convolution(num_filter=3.4, kernel=(2,2.5), stride=(2.3,3), pad=(3/3,3/3))
LRN(nsize=2.5)
Pooling(type=max, kernel=(2,2.5), stride=(2.3,3), pad=(3.2,3.1))
FullyConnected(units=3/2)
Output(type=softmax)
}
\ No newline at end of file
Architecture InvalidActivationBeforeOutput1 {
FullyConnected(units=64)
Activation(type=relu)
Output(type=linear)
}
\ No newline at end of file
Architecture InvalidLayerDimension{
FullyConnected(units=128)
Convolution(num_filter=4, kernel=(2,2))
Output(type=softmax)
}
\ No newline at end of file
Architecture MissingConvolutionArgument1{
Convolution(kernel=(12,12), no_bias=true)
Output(type=softmax)
}
\ No newline at end of file
Architecture MissingConvolutionArgument2{
Convolution(num_filter=64, no_bias=true)
Output(type=softmax)
}
\ No newline at end of file
Architecture MissingFullyConnectedArgument{
FullyConnected(no_bias=true)
Output(type=softmax)