Commit 87a112a5 authored by Thomas Michael Timmermanns's avatar Thomas Michael Timmermanns Committed by Thomas Michael Timmermanns

Fixed a few code generation bugs.

Added dataset normalization to generated code.
parent 6a4fe6ec
......@@ -261,7 +261,7 @@ public class CNNArchTemplateController {
boolean isFirst = true;
for (Object element : iterable){
if (!isFirst){
stringBuilder.append(",");
stringBuilder.append(separator);
}
stringBuilder.append(elementPrefix);
stringBuilder.append(element.toString());
......
This diff is collapsed.
......@@ -7,12 +7,12 @@
#include <string>
#include <vector>
#include <CNNBufferfile.h>
#include <CNNBufferFile.h>
class ${tc.fileNameWithoutEnding}{
public:
const std::string json_file = "model/${tc.fullArchitectureName}/${tc.architectureName}-symbol.json";
const std::string param_file = "model/${tc.fullArchitectureName}/${tc.architectureName}.params";
const std::string json_file = "model/${tc.fullArchitectureName}/${tc.architectureName}_newest-symbol.json";
const std::string param_file = "model/${tc.fullArchitectureName}/${tc.architectureName}_newest-0000.params";
const std::vector<std::string> input_keys = {"data"};
//const std::vector<std::string> input_keys = {${tc.join(tc.architectureInputs, ",", "\"", "\"")}};
const std::vector<std::vector<mx_uint>> input_shapes = {<#list tc.architecture.inputs as input>{1,${tc.join(input.definition.type.dimensions, ",")}}<#if input?has_next>,</#if></#list>};
......
......@@ -3,19 +3,19 @@
vector<float> CNN_${tc.getName(output)}(<#list shape as dim>${dim?c}<#if dim?has_next>*</#if></#list>);
</#list>
CNN.predict(<#list tc.architecture.inputs as input>CNNTranslator::translate(${input.name}<#if input.arrayAccess.isPresent()>[${input.arrayAccess.get().intValue.get()?c}]</#if>),
_cnn_.predict(<#list tc.architecture.inputs as input>CNNTranslator::translate(${input.name}<#if input.arrayAccess.isPresent()>[${input.arrayAccess.get().intValue.get()?c}]</#if>),
</#list><#list tc.architecture.outputs as output>CNN_${tc.getName(output)}<#if output?has_next>,
</#if></#list>);
<#list tc.architecture.outputs as output>
<#assign shape = output.definition.type.dimensions>
<#if shape?size == 1>
${output.name}<#if output.arrayAccess.isPresent()>[${output.arrayAccess.get().intValue.get()?c}]</#if> = CNNTranslator::translateToCol(CNN_${tc.getName(output)}, std::vector<int> {${shape[0]?c}});
${output.name}<#if output.arrayAccess.isPresent()>[${output.arrayAccess.get().intValue.get()?c}]</#if> = CNNTranslator::translateToCol(CNN_${tc.getName(output)}, std::vector<size_t> {${shape[0]?c}});
</#if>
<#if shape?size == 2>
${output.name}<#if output.arrayAccess.isPresent()>[${output.arrayAccess.get().intValue.get()?c}]</#if> = CNNTranslator::translateToMat(CNN_${tc.getName(output)}, std::vector<int> {${shape[0]?c}, ${shape[1]?c}});
${output.name}<#if output.arrayAccess.isPresent()>[${output.arrayAccess.get().intValue.get()?c}]</#if> = CNNTranslator::translateToMat(CNN_${tc.getName(output)}, std::vector<size_t> {${shape[0]?c}, ${shape[1]?c}});
</#if>
<#if shape?size == 3>
${output.name}<#if output.arrayAccess.isPresent()>[${output.arrayAccess.get().intValue.get()?c}]</#if> = CNNTranslator::translateToCube(CNN_${tc.getName(output)}, std::vector<int> {${shape[0]?c}, ${shape[1]?c}, ${shape[2]?c}});
${output.name}<#if output.arrayAccess.isPresent()>[${output.arrayAccess.get().intValue.get()?c}]</#if> = CNNTranslator::translateToCube(CNN_${tc.getName(output)}, std::vector<size_t> {${shape[0]?c}, ${shape[1]?c}, ${shape[2]?c}});
</#if>
</#list>
\ No newline at end of file
......@@ -7,9 +7,8 @@
<#if widthIndex != 0><#assign indexList = indexList + [widthIndex]></#if>
<#assign dimensions = tc.currentLayer.outputTypes[0].dimensions>
<#if tc.targetLanguage == ".py">
self.${tc.currentName} = mx.sym.var("${tc.currentName}",
${tc.currentName} = mx.sym.var("${tc.currentName}",
shape=(0,${tc.join(dimensions, ",")}))
${tc.currentName} = self.${tc.currentName}
<#include "OutputShape.ftl">
<#if heightIndex != channelIndex + 1 || widthIndex != heightIndex + 1>
${tc.currentName} = mx.symbol.transpose(data=${tc.currentName},
......@@ -20,22 +19,12 @@
${tc.currentName} = mx.symbol.reshape(data=${tc.currentName},
shape=(0,${tc.currentLayer.outputTypes[0].channels?c},${tc.currentLayer.outputTypes[0].height?c},${tc.currentLayer.outputTypes[0].width?c}))
</#if>
<#elseif tc.targetLanguage == ".cpp">
m_${tc.currentName} = Symbol::Variable("${tc.currentName}");
m_${tc.currentName}.SetParam("shape", Shape(0,${tc.join(dimensions, ",")}));
auto ${tc.currentName} = m_${tc.currentName};
<#include "OutputShape.ftl">
<#if heightIndex != channelIndex + 1 || widthIndex != heightIndex + 1>
${tc.currentName} = Operator("transpose")
.SetParam("axes", Shape(0,${tc.join(indexList, ",")}))
.SetInput("data", ${tc.currentName})
.CreateSymbol();
</#if>
<#if indexList?size != 3>
${tc.currentName} = Operator("reshape")
.SetParam("shape", Shape(0,${tc.currentLayer.outputTypes[0].channels?c},${tc.currentLayer.outputTypes[0].height?c},${tc.currentLayer.outputTypes[0].width?c}))
.SetInput("data", ${tc.currentName})
.CreateSymbol();
</#if>
if not data_mean is None:
assert(not data_std is None)
_data_mean_ = mx.sym.Variable("_data_mean_", shape=(${tc.join(dimensions, ",")}), init=MyConstant(value=data_mean.tolist()))
_data_mean_ = mx.sym.BlockGrad(_data_mean_)
_data_std_ = mx.sym.Variable("_data_std_", shape=(${tc.join(dimensions, ",")}), init=MyConstant(value=data_mean.tolist()))
_data_std_ = mx.sym.BlockGrad(_data_std_)
${tc.currentName} = mx.symbol.broadcast_sub(${tc.currentName}, _data_mean_)
${tc.currentName} = mx.symbol.broadcast_div(${tc.currentName}, _data_std_)
</#if>
\ No newline at end of file
<#if tc.targetLanguage == ".py">
<#if tc.softmaxOutput>
self.${tc.currentName} = mx.symbol.SoftmaxOutput(data=${tc.currentInputs[0]},
${tc.currentName} = mx.symbol.SoftmaxOutput(data=${tc.currentInputs[0]},
name="${tc.currentName}")
<#elseif tc.logisticRegressionOutput>
self.${tc.currentName} = mx.symbol.LogisticRegressionOutput(data=${tc.currentInputs[0]},
${tc.currentName} = mx.symbol.LogisticRegressionOutput(data=${tc.currentInputs[0]},
name="${tc.currentName}")
<#elseif tc.linearRegressionOutput>
self.${tc.currentName} = mx.symbol.LinearRegressionOutput(data=${tc.currentInputs[0]},
${tc.currentName} = mx.symbol.LinearRegressionOutput(data=${tc.currentInputs[0]},
name="${tc.currentName}")
</#if>
<#elseif tc.targetLanguage == ".cpp">
......
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