Adapted Templates Convolution, FullyConnected and Pooling. Added LeNet.cnna model

parent abeb3c80
<#assign input = element.inputs[0]>
<#if element.padding??>
<#if element.padding??> <#-- Check wheather padding null is. -->
<#assign input = element.name>
${element.name} = mx.symbol.pad(data=${element.inputs[0]}, #TODO: pending to adapt
mode='constant',
pad_width=(${tc.join(element.padding, ",")}),
constant_value=0)
#TODO: check how to adapt CNNArchLang argument pad_width=${element.padding}
</#if>
${element.name} = brew.conv(model, ${input}, '${element.name}', dim_in=1, dim_out=20, kernel=5)
${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}
<#include "OutputShape.ftl">
<#assign flatten = element.element.inputTypes[0].height != 1 || element.element.inputTypes[0].width != 1>
<#assign input = element.inputs[0]>
<#if flatten>
${element.name} = mx.symbol.flatten(data=${input}) #TODO: Pending to adapt
${element.name} = mx.symbol.flatten(data=${input}) #TODO: check how to adapt CNNArchLang flatten
<#assign input = element.name>
</#if>
${element.name} = brew.fc(model, ${input}, '${element.name}', dim_in=50 * 4 * 4, dim_out=500)
${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")}
<#assign input = element.inputs[0]>
<#if element.padding??>
<#assign input = element.name>
${element.name} = mx.symbol.pad(data=${element.inputs[0]}, #TODO: Pending to adapt o eliminate
mode='constant',
pad_width=(${tc.join(element.padding, ",")}),
constant_value=0)
</#if>
${element.name} = brew.max_pool(model, ${input}, '${element.name}', kernel=2, stride=2)
<#assign input = element.inputs[0]>
<#if element.padding??>
<#assign input = element.name>
${element.name} = mx.symbol.pad(data=${element.inputs[0]},
mode='constant',
pad_width=(${tc.join(element.padding, ",")}),
constant_value=0)
#TODO: check how to adapt CNNArchLang argument pad_width=${element.padding}
</#if>
${element.name} = mx.symbol.Pooling(data=${input},
kernel=(${tc.join(element.kernel, ",")}),
pool_type=${element.poolType},
stride=(${tc.join(element.stride, ",")}),
name="${element.name}")
<#if element.poolType == "max">
${element.name} = brew.max_pool(model, ${input}, '${element.name}', kernel=${element.kernel}, stride=${element.stride})
<#elseif element.poolType == "avg">
${element.name} = brew.average_pool(model, ${input}, '${element.name}', kernel=${element.kernel}, stride=${element.stride})
</#if>
<#include "OutputShape.ftl">
\ No newline at end of file
architecture LeNet(img_height=28, img_width=28, img_channels=3, classes=10){
architecture LeNet(img_height=32, img_width=32, img_channels=3, classes=10){
def input Z(0:255)^{img_channels, img_height, img_width} image
def output Q(0:1)^{classes} predictions
image ->
Convolution(kernel=(5,5), channels=20, stride=(1,1), padding="no_loss") ->
MaxPooling(kernel=(3,3), stride=(2,2), padding="no_loss") ->
FullyConnected(units=64, no_bias=true) ->
Tanh() ->
FullyConnected(units=classes, no_bias=true) ->
Convolution(kernel=(5,5), channels=20) ->
Pooling(pool_type="max", kernel=(2,2), stride=(2,2)) ->
Convolution(kernel=(5,5), channels=50) ->
Pooling(pool_type="max", kernel=(2,2), stride=(2,2)) ->
FullyConnected(units=500) ->
Relu() ->
FullyConnected(units=classes) ->
Softmax() ->
predictions
}
\ 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