steps = kwargs.pop("num_stages") or len(inputs)-2
factor = kwargs.pop("factor") or [2]*steps
skip, upsample, block_args, order = cls.pop(["skip", "upsample", "blocks", "order"], kwargs)
order = "".join([item[0] for item in order])
base_block = block_args.get("base")
if isinstance(factor, int):
factor = int(factor ** (1/steps))
factor = [factor] * steps
elif not isinstance(factor, list):
raise TypeError("factor should be int or list of int, but %s was given" % type(factor))
with tf.variable_scope(name):
x = inputs[-1]
for i in range(steps):
with tf.variable_scope("decoder-"+str(i)):
// Skip some of the steps
if factor[i] == 1:
continue
args = {**kwargs, **block_args, **unpack_args(block_args, i, steps)} // enforce priority of subkeys
upsample_args = {**kwargs, **upsample, **unpack_args(upsample, i, steps)}
if order == "ub":
if upsample.get("layout") is not None:
x = cls.upsample(x, factor=factor[i], name="upsample-{}".format(i), **upsample_args)
x = base_block(x, name="post", **args)
elif order == "bu":
x = base_block(x, name="post", **args)
if upsample.get("layout") is not None:
x = cls.upsample(x, factor=factor[i], name="upsample-{}".format(i), **upsample_args)
else:
raise ValueError("Unknown order, use one of {"ub", "bu"}")
// Combine it with stored encoding of the ~same shape
if skip and (i < len(inputs)-2):
combine_op = args.get("combine_op")