Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
languages
CNNTrainLang
Commits
2b2f2468
Commit
2b2f2468
authored
Aug 20, 2018
by
Svetlana Pavlitskaya
Browse files
Version 0.2.4-SNAPSHOT: deleted generation-related code, addded badges in readme, minor bug fixed
parent
a3e64578
Pipeline
#69331
passed with stages
Changes
11
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
2b2f2468
...
...
@@ -28,6 +28,9 @@ masterJobLinux:
image
:
maven:3-jdk-8
script
:
-
mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean deploy --settings settings.xml
-
cat target/site/jacoco/index.html
-
mvn package sonar:sonar -s settings.xml
only
:
-
master
...
...
@@ -43,6 +46,7 @@ BranchJobLinux:
image
:
maven:3-jdk-8
script
:
-
mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
-
cat target/site/jacoco/index.html
except
:
-
master
README.md
View file @
2b2f2468
[

](https://codeclimate.com/github/EmbeddedMontiArc/CNNTrainLang/maintainability)
[

](https://travis-ci.org/EmbeddedMontiArc/CNNTrainLang)
[

](https://circleci.com/gh/EmbeddedMontiArc/CNNTrainLang/tree/updated_cnntrain)
[

](https://coveralls.io/github/EmbeddedMontiArc/CNNTrainLang?branch=updated_cnntrain)


# CNNTrain
...
...
pom.xml
View file @
2b2f2468
...
...
@@ -30,7 +30,7 @@
<groupId>
de.monticore.lang.monticar
</groupId>
<artifactId>
cnn-train
</artifactId>
<version>
0.2.
3
-SNAPSHOT
</version>
<version>
0.2.
4
-SNAPSHOT
</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
...
...
@@ -55,6 +55,7 @@
<compiler.plugin>
3.3
</compiler.plugin>
<source.plugin>
2.4
</source.plugin>
<shade.plugin>
2.4.3
</shade.plugin>
<jacoco.plugin>
0.8.1
</jacoco.plugin>
<!-- Classifiers -->
<grammars.classifier>
grammars
</grammars.classifier>
...
...
@@ -214,6 +215,28 @@
</executions>
</plugin>
<!-- Test coverage -->
<plugin>
<groupId>
org.jacoco
</groupId>
<artifactId>
jacoco-maven-plugin
</artifactId>
<version>
${jacoco.plugin}
</version>
<executions>
<execution>
<id>
pre-unit-test
</id>
<goals>
<goal>
prepare-agent
</goal>
</goals>
</execution>
<execution>
<id>
post-unit-test
</id>
<phase>
test
</phase>
<goals>
<goal>
report
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Other Configuration -->
<plugin>
<artifactId>
maven-compiler-plugin
</artifactId>
...
...
settings.xml
View file @
2b2f2468
...
...
@@ -27,8 +27,8 @@
xsi:schemaLocation=
"http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"
>
<pluginGroups>
<pluginGroup>
org.mortbay.jetty
</pluginGroup>
<pluginGroup>
de.topobyte
</pluginGroup>
<pluginGroup>
org.mortbay.jetty
</pluginGroup>
<pluginGroup>
de.topobyte
</pluginGroup>
</pluginGroups>
<proxies>
...
...
@@ -39,9 +39,9 @@
<id>
se-nexus
</id>
<username>
cibuild
</username>
<password>
${env.cibuild}
</password>
</server>
</server>
<server>
<server>
<id>
github
</id>
<username>
travisbuilduser
</username>
<password>
${env.travisbuilduserpassword}
</password>
...
...
@@ -53,10 +53,28 @@
<id>
se-nexus
</id>
<mirrorOf>
external:*
</mirrorOf>
<url>
https://nexus.se.rwth-aachen.de/content/groups/public
</url>
</mirror>
</mirror>
</mirrors>
<profiles>
<profile>
<id>
sonar
</id>
<activation>
<activeByDefault>
true
</activeByDefault>
</activation>
<properties>
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<sonar.host.url>
https://metric.se.rwth-aachen.de
</sonar.host.url>
<sonar.login>
jenkins
</sonar.login>
<sonar.password>
${env.sonar}
</sonar.password>
</properties>
</profile>
<profile>
<id>
se-nexus
</id>
...
...
@@ -81,5 +99,5 @@
<activeProfiles>
<activeProfile>
se-nexus
</activeProfile>
</activeProfiles>
</activeProfiles>
</settings>
\ No newline at end of file
src/main/java/de/monticore/lang/monticar/cnntrain/_symboltable/CNNTrainSymbolTableCreator.java
View file @
2b2f2468
...
...
@@ -66,8 +66,8 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
@Override
public
void
endVisit
(
ASTCNNTrainCompilationUnit
ast
)
{
CNNTrainCompilationUnitSymbol
compilationUnitSymbol
=
(
CNNTrainCompilationUnitSymbol
)
ast
.
getSymbol
().
get
();
compilationUnitSymbol
.
setConfiguration
((
ConfigurationSymbol
)
ast
.
getConfiguration
().
getSymbol
().
get
());
CNNTrainCompilationUnitSymbol
compilationUnitSymbol
=
(
CNNTrainCompilationUnitSymbol
)
ast
.
getSymbol
Opt
().
get
();
compilationUnitSymbol
.
setConfiguration
((
ConfigurationSymbol
)
ast
.
getConfiguration
().
getSymbol
Opt
().
get
());
setEnclosingScopeOfNodes
(
ast
);
}
...
...
@@ -94,7 +94,7 @@ public class CNNTrainSymbolTableCreator extends CNNTrainSymbolTableCreatorTOP {
public
void
endVisit
(
ASTOptimizerEntry
node
)
{
for
(
ASTEntry
nodeParam
:
node
.
getValue
().
getParamsList
())
{
OptimizerParamSymbol
param
=
new
OptimizerParamSymbol
();
OptimizerParamValueSymbol
valueSymbol
=
(
OptimizerParamValueSymbol
)
nodeParam
.
getValue
().
getSymbol
().
get
();
OptimizerParamValueSymbol
valueSymbol
=
(
OptimizerParamValueSymbol
)
nodeParam
.
getValue
().
getSymbol
Opt
().
get
();
param
.
setValue
(
valueSymbol
);
configuration
.
getOptimizer
().
getOptimizerParamMap
().
put
(
nodeParam
.
getName
(),
param
);;
}
...
...
src/main/java/de/monticore/lang/monticar/cnntrain/generator/CNNTrainGenerator.java
deleted
100644 → 0
View file @
a3e64578
/**
*
* ******************************************************************************
* 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.cnntrain.generator
;
import
de.monticore.io.paths.ModelPath
;
import
de.monticore.lang.monticar.cnntrain._cocos.CNNTrainCocos
;
import
de.monticore.lang.monticar.cnntrain._symboltable.ConfigurationSymbol
;
import
de.monticore.lang.monticar.cnntrain._symboltable.CNNTrainCompilationUnitSymbol
;
import
de.monticore.lang.monticar.cnntrain._symboltable.CNNTrainLanguage
;
import
de.monticore.symboltable.GlobalScope
;
import
de.monticore.symboltable.Scope
;
import
de.se_rwth.commons.logging.Log
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.nio.file.Path
;
import
java.util.Map
;
import
java.util.Optional
;
public
class
CNNTrainGenerator
{
private
String
generationTargetPath
;
public
CNNTrainGenerator
()
{
setGenerationTargetPath
(
"./target/generated-sources-cnntrain/"
);
}
public
String
getGenerationTargetPath
()
{
if
(
generationTargetPath
.
charAt
(
generationTargetPath
.
length
()
-
1
)
!=
'/'
)
{
this
.
generationTargetPath
=
generationTargetPath
+
"/"
;
}
return
generationTargetPath
;
}
public
void
setGenerationTargetPath
(
String
generationTargetPath
)
{
this
.
generationTargetPath
=
generationTargetPath
;
}
public
void
generate
(
Path
modelsDirPath
,
String
rootModelName
){
final
ModelPath
mp
=
new
ModelPath
(
modelsDirPath
);
GlobalScope
scope
=
new
GlobalScope
(
mp
,
new
CNNTrainLanguage
());
Map
.
Entry
<
String
,
String
>
fileContent
=
generateFileContent
(
scope
,
rootModelName
);
try
{
generateConfigFile
(
fileContent
);
}
catch
(
IOException
e
){
Log
.
error
(
e
.
toString
());
}
}
public
Map
.
Entry
<
String
,
String
>
generateFileContent
(
Scope
scope
,
String
rootModelName
){
Optional
<
CNNTrainCompilationUnitSymbol
>
compilationUnit
=
scope
.
resolve
(
rootModelName
,
CNNTrainCompilationUnitSymbol
.
KIND
);
if
(!
compilationUnit
.
isPresent
()){
Log
.
error
(
"CNNTrainCompilationUnitSymbol is empty. Could not resolve configuration "
+
rootModelName
);
System
.
exit
(
1
);
}
CNNTrainCocos
.
checkAll
(
compilationUnit
.
get
());
ConfigurationSymbol
configuration
=
compilationUnit
.
get
().
getConfiguration
();
CNNTrainTemplateController
cnnTrainTemplateController
=
new
CNNTrainTemplateController
(
configuration
);
Map
.
Entry
<
String
,
String
>
fileContent1
;
fileContent1
=
cnnTrainTemplateController
.
process
(
"Config"
,
Target
.
PYTHON
);
Map
.
Entry
<
String
,
String
>
fileContent
=
fileContent1
;
return
fileContent
;
}
public
void
generateConfigFile
(
Map
.
Entry
<
String
,
String
>
fileContent
)
throws
IOException
{
Log
.
info
(
"Start generating config file..."
,
"Generation Test"
);
File
f
=
new
File
(
getGenerationTargetPath
()
+
fileContent
.
getKey
());
Log
.
info
(
f
.
getName
(),
"FileCreation:"
);
if
(!
f
.
exists
())
{
f
.
getParentFile
().
mkdirs
();
if
(!
f
.
createNewFile
())
{
Log
.
error
(
"File could not be created"
);
}
}
FileWriter
writer
=
new
FileWriter
(
f
);
writer
.
write
(
fileContent
.
getValue
());
writer
.
close
();
}
}
src/main/java/de/monticore/lang/monticar/cnntrain/generator/CNNTrainTemplateController.java
deleted
100644 → 0
View file @
a3e64578
/**
*
* ******************************************************************************
* 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.cnntrain.generator
;
import
de.monticore.lang.monticar.cnntrain._symboltable.*
;
import
de.monticore.lang.monticar.cnntrain._symboltable.ConfigurationSymbol
;
import
de.se_rwth.commons.logging.Log
;
import
freemarker.template.Configuration
;
import
freemarker.template.Template
;
import
freemarker.template.TemplateException
;
import
java.io.IOException
;
import
java.io.StringWriter
;
import
java.io.Writer
;
import
java.util.*
;
public
class
CNNTrainTemplateController
{
public
static
final
String
FTL_FILE_ENDING
=
".ftl"
;
public
static
final
String
TEMPLATE_CONTROLLER_KEY
=
"tc"
;
private
Configuration
freemarkerConfig
=
TemplateConfiguration
.
get
();
private
ConfigurationSymbol
configuration
;
private
Writer
writer
;
private
String
mainTemplateNameWithoutEnding
;
private
Target
targetLanguage
;
public
CNNTrainTemplateController
(
ConfigurationSymbol
configuration
)
{
setConfiguration
(
configuration
);
}
public
String
getFileNameWithoutEnding
()
{
return
mainTemplateNameWithoutEnding
+
"_"
+
getFullConfigurationName
();
}
public
Target
getTargetLanguage
()
{
return
targetLanguage
;
}
public
void
setTargetLanguage
(
Target
targetLanguage
)
{
this
.
targetLanguage
=
targetLanguage
;
}
public
ConfigurationSymbol
getConfiguration
()
{
return
configuration
;
}
public
void
setConfiguration
(
ConfigurationSymbol
configuration
)
{
this
.
configuration
=
configuration
;
}
public
String
getConfigurationName
()
{
return
getConfiguration
().
getEnclosingScope
().
getSpanningSymbol
().
get
().
getName
().
replaceAll
(
"\\."
,
"_"
);
}
public
String
getFullConfigurationName
()
{
return
getConfiguration
().
getEnclosingScope
().
getSpanningSymbol
().
get
().
getFullName
().
replaceAll
(
"\\."
,
"_"
);
}
public
String
getNumEpoch
()
{
if
(!
getConfiguration
().
getEntryMap
().
containsKey
(
"num_epoch"
))
{
return
null
;
}
return
String
.
valueOf
(
getConfiguration
().
getEntry
(
"num_epoch"
).
getValue
());
}
public
String
getBatchSize
()
{
if
(!
getConfiguration
().
getEntryMap
().
containsKey
(
"batch_size"
))
{
return
null
;
}
return
String
.
valueOf
(
getConfiguration
().
getEntry
(
"batch_size"
)
.
getValue
());
}
public
Boolean
getLoadCheckpoint
()
{
if
(!
getConfiguration
().
getEntryMap
().
containsKey
(
"load_checkpoint"
))
{
return
null
;
}
return
(
Boolean
)
getConfiguration
().
getEntry
(
"load_checkpoint"
).
getValue
().
getValue
();
}
public
Boolean
getNormalize
()
{
if
(!
getConfiguration
().
getEntryMap
().
containsKey
(
"normalize"
))
{
return
null
;
}
return
(
Boolean
)
getConfiguration
().
getEntry
(
"normalize"
).
getValue
().
getValue
();
}
public
String
getContext
()
{
if
(!
getConfiguration
().
getEntryMap
().
containsKey
(
"context"
))
{
return
null
;
}
return
getConfiguration
().
getEntry
(
"context"
).
getValue
().
toString
();
}
public
String
getEvalMetric
()
{
if
(!
getConfiguration
().
getEntryMap
().
containsKey
(
"eval_metric"
))
{
return
null
;
}
return
getConfiguration
().
getEntry
(
"eval_metric"
).
getValue
().
toString
();
}
public
String
getOptimizerName
()
{
if
(
getConfiguration
().
getOptimizer
()
==
null
)
{
return
null
;
}
return
getConfiguration
().
getOptimizer
().
getName
();
}
public
Map
<
String
,
String
>
getOptimizerParams
()
{
// get classes for single enum values
List
<
Class
>
lrPolicyClasses
=
new
ArrayList
<>();
for
(
LRPolicy
enum_value:
LRPolicy
.
values
())
{
lrPolicyClasses
.
add
(
enum_value
.
getClass
());
}
Map
<
String
,
String
>
mapToStrings
=
new
HashMap
<>();
Map
<
String
,
OptimizerParamSymbol
>
optimizerParams
=
getConfiguration
().
getOptimizer
().
getOptimizerParamMap
();
for
(
Map
.
Entry
<
String
,
OptimizerParamSymbol
>
entry
:
optimizerParams
.
entrySet
())
{
String
paramName
=
entry
.
getKey
();
String
valueAsString
=
entry
.
getValue
().
toString
();
Class
realClass
=
entry
.
getValue
().
getValue
().
getValue
().
getClass
();
if
(
realClass
==
Boolean
.
class
)
{
valueAsString
=
(
Boolean
)
entry
.
getValue
().
getValue
().
getValue
()
?
"True"
:
"False"
;
}
else
if
(
lrPolicyClasses
.
contains
(
realClass
))
{
valueAsString
=
"'"
+
valueAsString
+
"'"
;
}
mapToStrings
.
put
(
paramName
,
valueAsString
);
}
return
mapToStrings
;
}
public
void
include
(
String
relativePath
,
String
templateWithoutFileEnding
,
Writer
writer
){
String
templatePath
=
relativePath
+
templateWithoutFileEnding
+
FTL_FILE_ENDING
;
try
{
Template
template
=
freemarkerConfig
.
getTemplate
(
templatePath
);
Map
<
String
,
Object
>
ftlContext
=
Collections
.
singletonMap
(
TEMPLATE_CONTROLLER_KEY
,
this
);
this
.
writer
=
writer
;
template
.
process
(
ftlContext
,
writer
);
this
.
writer
=
null
;
}
catch
(
IOException
e
)
{
Log
.
error
(
"Freemarker could not find template "
+
templatePath
+
" :\n"
+
e
.
getMessage
());
System
.
exit
(
1
);
}
catch
(
TemplateException
e
){
Log
.
error
(
"An exception occured in template "
+
templatePath
+
" :\n"
+
e
.
getMessage
());
System
.
exit
(
1
);
}
}
public
Map
.
Entry
<
String
,
String
>
process
(
String
templateNameWithoutEnding
,
Target
targetLanguage
){
StringWriter
writer
=
new
StringWriter
();
this
.
mainTemplateNameWithoutEnding
=
templateNameWithoutEnding
;
this
.
targetLanguage
=
targetLanguage
;
include
(
""
,
templateNameWithoutEnding
,
writer
);
String
fileEnding
=
targetLanguage
.
toString
();
if
(
targetLanguage
==
Target
.
CPP
){
fileEnding
=
".h"
;
}
String
fileName
=
getFileNameWithoutEnding
()
+
fileEnding
;
Map
.
Entry
<
String
,
String
>
fileContent
=
new
AbstractMap
.
SimpleEntry
<>(
fileName
,
writer
.
toString
());
this
.
mainTemplateNameWithoutEnding
=
null
;
this
.
targetLanguage
=
null
;
return
fileContent
;
}
}
src/main/java/de/monticore/lang/monticar/cnntrain/generator/Target.java
deleted
100644 → 0
View file @
a3e64578
/**
*
* ******************************************************************************
* 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.cnntrain.generator
;
public
enum
Target
{
PYTHON
{
@Override
public
String
toString
()
{
return
".py"
;
}
},
CPP
{
@Override
public
String
toString
()
{
return
".cpp"
;
}
};
public
static
Target
fromString
(
String
target
){
switch
(
target
.
toLowerCase
()){
case
"python"
:
return
PYTHON
;
case
"py"
:
return
PYTHON
;
case
"cpp"
:
return
CPP
;
case
"c++"
:
return
CPP
;
default
:
throw
new
IllegalArgumentException
();
}
}
}
src/main/java/de/monticore/lang/monticar/cnntrain/generator/TemplateConfiguration.java
deleted
100644 → 0
View file @
a3e64578
/**
*
* ******************************************************************************
* 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.cnntrain.generator
;
import
freemarker.template.Configuration
;
import
freemarker.template.TemplateExceptionHandler
;
public
class
TemplateConfiguration
{
private
static
TemplateConfiguration
instance
;
private
Configuration
configuration
;
private
TemplateConfiguration
()
{
configuration
=
new
Configuration
(
Configuration
.
VERSION_2_3_23
);
configuration
.
setClassForTemplateLoading
(
TemplateConfiguration
.
class
,
"/templates/"
);
configuration
.
setDefaultEncoding
(
"UTF-8"
);
configuration
.
setTemplateExceptionHandler
(
TemplateExceptionHandler
.
RETHROW_HANDLER
);
}
public
Configuration
getConfiguration
()
{
return
configuration
;
}
public
static
Configuration
get
(){
if
(
instance
==
null
){
instance
=
new
TemplateConfiguration
();
}
return
instance
.
getConfiguration
();
}
}
src/main/resources/templates/Config.ftl
deleted
100644 → 0
View file @
a3e64578
<#
if
(tc.batchSize)??>
batch_size
=
$
{
tc
.batchSize
}
,
</#
if
>
<#
if
(tc.numEpoch)??>
num_epoch
=
$
{
tc
.numEpoch
}
,
</#
if
>
<#
if
(tc.loadCheckpoint)??>
load_checkpoint
=
$
{
tc
.loadCheckpoint
?
string
(
"True"
,
"False"
)}
,
</#
if
>
<#
if
(tc.context)??>
context
=
'$
{
tc
.context
}
',
</#
if
>
<#
if
(tc.normalize)??>
normalize
=
$
{
tc
.normalize
?
string
(
"True"
,
"False"
)}
,
</#
if
>
<#
if
(tc.evalMetric)??>
eval_metric
=
'$
{
tc
.evalMetric
}
',
</#
if
>
<#
if
(tc.configuration.optimizer)??>
optimizer
=
'$
{
tc
.optimizerName
}
',
optimizer_params
=
{
<#
list
tc
.optimizerParams
?
keys
as
param
>