Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add caption to blocks #123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 127 additions & 59 deletions pycore/blocks.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,143 @@

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,
caption="",
):
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],
caption=caption,
),
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,
caption="",
):
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],
caption=caption,
),
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,
caption="",
):
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 i, name in enumerate(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],
caption=caption if i == num // 2 else "",
),
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