Commit e9c99269 authored by Carlos Alfredo Yeverino Rodriguez's avatar Carlos Alfredo Yeverino Rodriguez
Browse files

Corrected Convolution, Pooling and FullyConnected layer templates: Adapted...

Corrected Convolution, Pooling and FullyConnected layer templates: Adapted stride with same and different height and width in convolution and pooling layers. Corrected dim_in value in convolution and fullyconnected layers.
parent 91473f2b
<#assign input = element.inputs[0]>
<#assign strideHeight = element.stride[0]>
<#assign strideWidth = element.stride[1]>
<#if element.padding??> <#-- Check wheather padding null is. -->
<#assign input = element.name>
#TODO: check how to adapt CNNArchLang argument pad_width=${element.padding}
<#-- TODO: check how to adapt CNNArchLang argument pad_width=${element.padding[0]} -->
</#if>
${element.name} = brew.conv(model, ${input}, '${element.name}', dim_in=1, dim_out=${element.channels?c}, kernel=${element.kernel}, stride=${element.stride})
#TODO: check how to adapt CNNArchLang argument no_bias=${element.noBias?string("True","False")}
#TODO: check how to adapt CNNArchLang argument pad_width=${element.padding}
<#if input = tc.architectureInputs[0]> <#-- TODO: CHECK COMPARISON -->
<#if strideHeight == strideWidth>
${element.name} = brew.conv(model, '${input}', '${element.name}', dim_in=1, dim_out=${element.channels?c}, kernel=${element.kernel[0]}, stride=${strideHeight})
<#else>
${element.name} = brew.conv(model, '${input}', '${element.name}', dim_in=1, dim_out=${element.channels?c}, kernel=${element.kernel[0]}, stride_h=${strideHeight}, stride_w=${strideWidth})
</#if>
<#else>
<#if strideHeight == strideWidth>
${element.name} = brew.conv(model, ${input}, '${element.name}', dim_in=${element.element.inputTypes[0].channels?c}, dim_out=${element.channels?c}, kernel=${element.kernel[0]}, stride=${strideHeight})
<#else>
${element.name} = brew.conv(model, ${input}, '${element.name}', dim_in=${element.element.inputTypes[0].channels?c}, dim_out=${element.channels?c}, kernel=${element.kernel[0]}, stride_h=${strideHeight}, stride_w=${strideWidth})
</#if>
</#if>
<#-- TODO: check how to adapt CNNArchLang argument no_bias=${element.noBias?string("True","False")} -->
<#include "OutputShape.ftl">
# Yeverino input layer name: ${element.inputs[0]}
# Yeverino input/previous layer dim_out: ${element.element.inputTypes[0].channels?c}
# Yeverino current layer dim_out: ${element.element.outputTypes[0].channels?c}
<#assign flatten = element.element.inputTypes[0].height != 1 || element.element.inputTypes[0].width != 1>
<#assign input = element.inputs[0]>
<#assign inputLayerType = element.element.getInputElement().get()?string>
<#assign inputChannels = element.element.inputTypes[0].channels?c>
<#assign inputHeight = element.element.inputTypes[0].height>
<#assign inputWidth = element.element.inputTypes[0].width>
<#if flatten>
${element.name} = mx.symbol.flatten(data=${input}) #TODO: check how to adapt CNNArchLang flatten
<#assign input = element.name>
<#-- TODO: check how to adapt CNNArchLang flatten #${element.name} = mx.symbol.flatten(data=${input}) -->
</#if>
${element.name} = brew.fc(model, ${input}, '${element.name}', dim_in=50 * 4 * 4, dim_out=${element.units?c})
#TODO: check how to adapt CNNArchLang argument no_bias=${element.noBias?string("True","False")}
<#if inputLayerType?matches("FullyConnected") || (inputHeight == 1 && inputWidth == 1)>
${element.name} = brew.fc(model, ${input}, '${element.name}', dim_in=${inputChannels}, dim_out=${element.units?c})
<#else>
${element.name} = brew.fc(model, ${input}, '${element.name}', dim_in=${inputChannels} * ${inputHeight} * ${inputWidth}, dim_out=${element.units?c})
</#if>
<#-- TODO: check how to adapt CNNArchLang argument no_bias=${element.noBias?string("True","False")} -->
# Yeverino input layer type: ${inputLayerType}
# Yeverino current layer type: ${element.element}
<#include "OutputShape.ftl">
\ No newline at end of file
<#assign input = element.inputs[0]>
<#assign strideHeight = element.stride[0]>
<#assign strideWidth = element.stride[1]>
<#if element.padding??>
<#assign input = element.name>
#TODO: check how to adapt CNNArchLang argument pad_width=${element.padding}
<#-- TODO: check how to adapt CNNArchLang argument pad_width=${element.padding[0]} -->
</#if>
<#if element.poolType == "max">
${element.name} = brew.max_pool(model, ${input}, '${element.name}', kernel=${element.kernel}, stride=${element.stride})
<#if strideHeight == strideWidth>
${element.name} = brew.max_pool(model, ${input}, '${element.name}', kernel=${element.kernel[0]}, stride=${strideHeight})
<#else>
${element.name} = brew.max_pool(model, ${input}, '${element.name}', kernel=${element.kernel[0]}, stride_h=${strideHeight}, stride_w=${strideWidth})
</#if>
<#elseif element.poolType == "avg">
${element.name} = brew.average_pool(model, ${input}, '${element.name}', kernel=${element.kernel}, stride=${element.stride})
<#if strideHeight == strideWidth>
${element.name} = brew.average_pool(model, ${input}, '${element.name}', kernel=${element.kernel[0]}, stride=${strideHeight})
<#else>
${element.name} = brew.average_pool(model, ${input}, '${element.name}', kernel=${element.kernel[0]}, stride_h=${strideHeight}, stride_w=${strideWidth})
</#if>
</#if>
<#include "OutputShape.ftl">
\ No newline at end of file
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