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

Commit 3d05bdd4 authored by nilsfreyer's avatar nilsfreyer
Browse files

Merge branch 'oneclick_nn_training' of...

Merge branch 'oneclick_nn_training' of https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/generators/EMADL2CPP into oneclick_nn_training
parents 74bd0027 a307c995
Pipeline #101589 failed with stages
in 25 seconds
......@@ -181,6 +181,7 @@ public class EMADLGenerator {
}
List<FileContent> fileContentsTrainingHashes = new ArrayList<>();
List<String> newHashes = new ArrayList<>();
for (ExpandedComponentInstanceSymbol componentInstance : allInstances) {
Optional<ArchitectureSymbol> architecture = componentInstance.getSpannedScope().resolve("", ArchitectureSymbol.KIND);
......@@ -188,39 +189,35 @@ public class EMADLGenerator {
continue;
}
String fullName = componentInstance.getFullName().replaceAll("\\.", "_");
String creatorScriptName = "CNNCreator_" + fullName + ".py";
String creatorScript = fileContentMap.get(creatorScriptName);
int creatorScriptHash = creatorScript.hashCode();
if(forced == "n") {
continue;
}
String configFilename = getConfigFilename(componentInstance.getComponentType().getFullName(), componentInstance.getFullName(), componentInstance.getName());
String emadlPath = getModelsPath() + configFilename + ".emadl";
String cnntPath = getModelsPath() + configFilename + ".cnnt";
String parsedFullName = fullName.substring(0, 1).toLowerCase() + fullName.substring(1);
String trainerScriptName = "CNNTrainer_" + parsedFullName + ".py";
System.out.println("CNNTrainer file: " + trainerScriptName);
String trainerScript = fileContentMap.get(trainerScriptName);
int trainerScriptHash = trainerScript.hashCode();
byte emadlHash[] = checksum(Paths.get(emadlPath));
byte cnntHash[] = checksum(Paths.get(cnntPath));
// This is not the real path to the training data! Adapt accordingly once sub-task 4 is solved
String trainConfigFilename = "NOT_FOUND";
String componentConfigFilename = componentInstance.getFullName().replaceAll("\\.", "/");
String componentConfigFilename = componentInstance.getComponentType().getReferencedSymbol().getFullName().replaceAll("\\.", "/");
String instanceConfigFilename = componentInstance.getFullName().replaceAll("\\.", "/") + "_" + componentInstance.getName();
if (Files.exists(Paths.get( getModelsPath() + instanceConfigFilename + ".cnnt"))) {
trainConfigFilename = instanceConfigFilename;
}
else if (Files.exists(Paths.get( getModelsPath() + componentConfigFilename + ".cnnt"))){
trainConfigFilename = componentConfigFilename;
}
byte[] dataHash = checksum(Paths.get(architecture.get().getDataPath()));
String trainingHash = creatorScriptHash + "-" + trainerScriptHash + "-" + convertByteArrayToHexString(dataHash);
String trainingHash = convertByteArrayToHexString(emadlHash) + "#" +
convertByteArrayToHexString(cnntHash) + "#" +
convertByteArrayToHexString(dataHash);
System.out.println(trainingHash);
boolean alreadyTrained = isAlreadyTrained(trainingHash, componentInstance);
if((alreadyTrained && forced !="y") || forced=="n") {
boolean alreadyTrained = newHashes.contains(trainingHash) || isAlreadyTrained(trainingHash, componentInstance);
if(alreadyTrained && forced !="y") {
System.out.println("Already trained");
}
else {
System.out.println("Not trained yet");
String parsedFullName = componentInstance.getFullName().substring(0, 1).toLowerCase() + componentInstance.getFullName().substring(1).replaceAll("\\.", "_");
String trainerScriptName = "CNNTrainer_" + parsedFullName + ".py";
String trainingPath = getGenerationTargetPath() + trainerScriptName;
String pythonExe = "/home/christopher/anaconda3/bin/python";
if(Files.exists(Paths.get(trainingPath))){
......@@ -234,16 +231,22 @@ public class EMADLGenerator {
catch(InterruptedException e) {
//throw new Exception("Error: Training aborted" + e.toString());
System.out.println("Error: Training aborted" + e.toString());
continue;
}
if(exitCode != 0) {
//throw new Exception("Error: Training error");
System.out.println("Error: Training failed" + Integer.toString(exitCode));
}
}else{System.out.println("Trainingfile not found.");}
continue;
}
fileContentsTrainingHashes.add(new FileContent(trainingHash, componentConfigFilename + ".training_hash"));
newHashes.add(trainingHash);
}else{
System.out.println("Trainingfile " + trainingPath + " not found.");
}
}
}
for (FileContent fileContent : fileContentsTrainingHashes) {
......@@ -288,12 +291,13 @@ public class EMADLGenerator {
String checkFilePathString = getGenerationTargetPath() + componentConfigFilename + ".training_hash";
Path checkFilePath = Paths.get( checkFilePathString);
if(Files.exists(checkFilePath)) {
String hash = Files.readAllLines(checkFilePath).get(0);
List<String> hashes = Files.readAllLines(checkFilePath);
for(String hash : hashes) {
if(hash.equals(trainingHash)) {
return true;
}
}
}
return false;
}
......@@ -440,17 +444,11 @@ public class EMADLGenerator {
}
}
public List<FileContent> generateCNNTrainer(Set<ExpandedComponentInstanceSymbol> allInstances, String mainComponentName) {
List<FileContent> fileContents = new ArrayList<>();
for (ExpandedComponentInstanceSymbol componentInstance : allInstances) {
ComponentSymbol component = componentInstance.getComponentType().getReferencedSymbol();
Optional<ArchitectureSymbol> architecture = component.getSpannedScope().resolve("", ArchitectureSymbol.KIND);
if (architecture.isPresent()) {
private String getConfigFilename(String mainComponentName, String componentFullName, String componentName) {
String trainConfigFilename;
String mainComponentConfigFilename = mainComponentName.replaceAll("\\.", "/");
String componentConfigFilename = component.getFullName().replaceAll("\\.", "/");
String instanceConfigFilename = component.getFullName().replaceAll("\\.", "/") + "_" + component.getName();
String componentConfigFilename = componentFullName.replaceAll("\\.", "/");
String instanceConfigFilename = componentFullName.replaceAll("\\.", "/") + "_" + componentName;
if (Files.exists(Paths.get( getModelsPath() + instanceConfigFilename + ".cnnt"))) {
trainConfigFilename = instanceConfigFilename;
}
......@@ -469,6 +467,17 @@ public class EMADLGenerator {
" These files denote respectively the configuration for the single instance, the component or the whole system.");
return null;
}
return trainConfigFilename;
}
public List<FileContent> generateCNNTrainer(Set<ExpandedComponentInstanceSymbol> allInstances, String mainComponentName) {
List<FileContent> fileContents = new ArrayList<>();
for (ExpandedComponentInstanceSymbol componentInstance : allInstances) {
ComponentSymbol component = componentInstance.getComponentType().getReferencedSymbol();
Optional<ArchitectureSymbol> architecture = component.getSpannedScope().resolve("", ArchitectureSymbol.KIND);
if (architecture.isPresent()) {
String trainConfigFilename = getConfigFilename(mainComponentName, component.getFullName(), component.getName());
//should be removed when CNNTrain supports packages
List<String> names = Splitter.on("/").splitToList(trainConfigFilename);
......
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