From 321e259b3c24742297d286fd741a67a65cbf1f34 Mon Sep 17 00:00:00 2001 From: Emmanuel Bustos Date: Wed, 5 Jan 2022 19:11:06 +0100 Subject: [PATCH 1/2] Format file using Black --- pycore/blocks.py | 180 +++++++++++++++++++++++++++++++---------------- 1 file changed, 121 insertions(+), 59 deletions(-) diff --git a/pycore/blocks.py b/pycore/blocks.py index 82c2c2a..8ca4454 100644 --- a/pycore/blocks.py +++ b/pycore/blocks.py @@ -1,75 +1,137 @@ - from .tikzeng import * -#define new block -def block_2ConvPool( name, botton, top, s_filer=256, n_filer=64, offset="(1,0,0)", size=(32,32,3.5), opacity=0.5 ): +# define new block +def block_2ConvPool( + name, + botton, + top, + s_filer=256, + n_filer=64, + offset="(1,0,0)", + size=(32, 32, 3.5), + opacity=0.5, +): return [ - to_ConvConvRelu( - name="ccr_{}".format( name ), - s_filer=str(s_filer), - n_filer=(n_filer,n_filer), - offset=offset, - to="({}-east)".format( botton ), - width=(size[2],size[2]), - height=size[0], - depth=size[1], - ), - to_Pool( - name="{}".format( top ), - offset="(0,0,0)", - to="(ccr_{}-east)".format( name ), - width=1, - height=size[0] - int(size[0]/4), - depth=size[1] - int(size[0]/4), - opacity=opacity, ), - to_connection( - "{}".format( botton ), - "ccr_{}".format( name ) - ) + to_ConvConvRelu( + name="ccr_{}".format(name), + s_filer=str(s_filer), + n_filer=(n_filer, n_filer), + offset=offset, + to="({}-east)".format(botton), + width=(size[2], size[2]), + height=size[0], + depth=size[1], + ), + to_Pool( + name="{}".format(top), + offset="(0,0,0)", + to="(ccr_{}-east)".format(name), + width=1, + height=size[0] - int(size[0] / 4), + depth=size[1] - int(size[0] / 4), + opacity=opacity, + ), + to_connection("{}".format(botton), "ccr_{}".format(name)), ] -def block_Unconv( name, botton, top, s_filer=256, n_filer=64, offset="(1,0,0)", size=(32,32,3.5), opacity=0.5 ): +def block_Unconv( + name, + botton, + top, + s_filer=256, + n_filer=64, + offset="(1,0,0)", + size=(32, 32, 3.5), + opacity=0.5, +): return [ - to_UnPool( name='unpool_{}'.format(name), offset=offset, to="({}-east)".format(botton), width=1, height=size[0], depth=size[1], opacity=opacity ), - to_ConvRes( name='ccr_res_{}'.format(name), offset="(0,0,0)", to="(unpool_{}-east)".format(name), s_filer=str(s_filer), n_filer=str(n_filer), width=size[2], height=size[0], depth=size[1], opacity=opacity ), - to_Conv( name='ccr_{}'.format(name), offset="(0,0,0)", to="(ccr_res_{}-east)".format(name), s_filer=str(s_filer), n_filer=str(n_filer), width=size[2], height=size[0], depth=size[1] ), - to_ConvRes( name='ccr_res_c_{}'.format(name), offset="(0,0,0)", to="(ccr_{}-east)".format(name), s_filer=str(s_filer), n_filer=str(n_filer), width=size[2], height=size[0], depth=size[1], opacity=opacity ), - to_Conv( name='{}'.format(top), offset="(0,0,0)", to="(ccr_res_c_{}-east)".format(name), s_filer=str(s_filer), n_filer=str(n_filer), width=size[2], height=size[0], depth=size[1] ), - to_connection( - "{}".format( botton ), - "unpool_{}".format( name ) - ) + to_UnPool( + name="unpool_{}".format(name), + offset=offset, + to="({}-east)".format(botton), + width=1, + height=size[0], + depth=size[1], + opacity=opacity, + ), + to_ConvRes( + name="ccr_res_{}".format(name), + offset="(0,0,0)", + to="(unpool_{}-east)".format(name), + s_filer=str(s_filer), + n_filer=str(n_filer), + width=size[2], + height=size[0], + depth=size[1], + opacity=opacity, + ), + to_Conv( + name="ccr_{}".format(name), + offset="(0,0,0)", + to="(ccr_res_{}-east)".format(name), + s_filer=str(s_filer), + n_filer=str(n_filer), + width=size[2], + height=size[0], + depth=size[1], + ), + to_ConvRes( + name="ccr_res_c_{}".format(name), + offset="(0,0,0)", + to="(ccr_{}-east)".format(name), + s_filer=str(s_filer), + n_filer=str(n_filer), + width=size[2], + height=size[0], + depth=size[1], + opacity=opacity, + ), + to_Conv( + name="{}".format(top), + offset="(0,0,0)", + to="(ccr_res_c_{}-east)".format(name), + s_filer=str(s_filer), + n_filer=str(n_filer), + width=size[2], + height=size[0], + depth=size[1], + ), + to_connection("{}".format(botton), "unpool_{}".format(name)), ] - - -def block_Res( num, name, botton, top, s_filer=256, n_filer=64, offset="(0,0,0)", size=(32,32,3.5), opacity=0.5 ): +def block_Res( + num, + name, + botton, + top, + s_filer=256, + n_filer=64, + offset="(0,0,0)", + size=(32, 32, 3.5), + opacity=0.5, +): lys = [] - layers = [ *[ '{}_{}'.format(name,i) for i in range(num-1) ], top] - for name in layers: - ly = [ to_Conv( - name='{}'.format(name), - offset=offset, - to="({}-east)".format( botton ), - s_filer=str(s_filer), - n_filer=str(n_filer), - width=size[2], - height=size[0], - depth=size[1] + layers = [*["{}_{}".format(name, i) for i in range(num - 1)], top] + for name in layers: + ly = [ + to_Conv( + name="{}".format(name), + offset=offset, + to="({}-east)".format(botton), + s_filer=str(s_filer), + n_filer=str(n_filer), + width=size[2], + height=size[0], + depth=size[1], ), - to_connection( - "{}".format( botton ), - "{}".format( name ) - ) - ] + to_connection("{}".format(botton), "{}".format(name)), + ] botton = name - lys+=ly - + lys += ly + lys += [ - to_skip( of=layers[1], to=layers[-2], pos=1.25), + to_skip(of=layers[1], to=layers[-2], pos=1.25), ] return lys - - From 5fa352462ac43980f17d492ad4ee986a4f941ea8 Mon Sep 17 00:00:00 2001 From: Emmanuel Bustos Date: Wed, 5 Jan 2022 19:13:07 +0100 Subject: [PATCH 2/2] Add caption option to current blocks --- pycore/blocks.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pycore/blocks.py b/pycore/blocks.py index 8ca4454..d57d48c 100644 --- a/pycore/blocks.py +++ b/pycore/blocks.py @@ -10,6 +10,7 @@ def block_2ConvPool( offset="(1,0,0)", size=(32, 32, 3.5), opacity=0.5, + caption="", ): return [ to_ConvConvRelu( @@ -21,6 +22,7 @@ def block_2ConvPool( width=(size[2], size[2]), height=size[0], depth=size[1], + caption=caption, ), to_Pool( name="{}".format(top), @@ -44,6 +46,7 @@ def block_Unconv( offset="(1,0,0)", size=(32, 32, 3.5), opacity=0.5, + caption="", ): return [ to_UnPool( @@ -75,6 +78,7 @@ def block_Unconv( width=size[2], height=size[0], depth=size[1], + caption=caption, ), to_ConvRes( name="ccr_res_c_{}".format(name), @@ -111,10 +115,11 @@ def block_Res( offset="(0,0,0)", size=(32, 32, 3.5), opacity=0.5, + caption="", ): lys = [] layers = [*["{}_{}".format(name, i) for i in range(num - 1)], top] - for name in layers: + for i, name in enumerate(layers): ly = [ to_Conv( name="{}".format(name), @@ -125,6 +130,7 @@ def block_Res( width=size[2], height=size[0], depth=size[1], + caption=caption if i == num // 2 else "", ), to_connection("{}".format(botton), "{}".format(name)), ]