def get_content_module(prefix, dshape, ctx, params): sym = vgg.get_vgg_symbol(prefix, True) init = PretrainedInit(prefix, params) mod = mx.mod.Module(symbol=sym, data_names=("%s_data" % prefix, ), label_names=None, context=ctx) mod.bind(data_shapes=[("%s_data" % prefix, dshape)], for_training=False) mod.init_params(init) return mod
def get_content_module(prefix, dshape, ctx, params): sym = vgg.get_vgg_symbol(prefix, True) init = PretrainedInit(prefix, params) mod = mx.mod.Module(symbol=sym, data_names=("%s_data" % prefix,), label_names=None, context=ctx) mod.bind(data_shapes=[("%s_data" % prefix, dshape)], for_training=False) mod.init_params(init) return mod
def get_style_module(prefix, dshape, ctx, params): input_shape = {"%s_data" % prefix: dshape} style, content = vgg.get_vgg_symbol(prefix) gram, gscale = style_gram_symbol(input_shape, style) init = PretrainedInit(prefix, params) mod = mx.mod.Module(symbol=gram, data_names=("%s_data" % prefix, ), label_names=None, context=ctx) mod.bind(data_shapes=[("%s_data" % prefix, dshape)], for_training=False) mod.init_params(init) return mod
def get_style_module(prefix, dshape, ctx, params): input_shape = {"%s_data" % prefix : dshape} style, content = vgg.get_vgg_symbol(prefix) gram, gscale = style_gram_symbol(input_shape, style) init = PretrainedInit(prefix, params) mod = mx.mod.Module(symbol=gram, data_names=("%s_data" % prefix,), label_names=None, context=ctx) mod.bind(data_shapes=[("%s_data" % prefix, dshape)], for_training=False) mod.init_params(init) return mod
def get_loss_module(prefix, dshape, ctx, params): input_shape = {"%s_data" % prefix : dshape} style, content = vgg.get_vgg_symbol(prefix) gram, gscale = style_gram_symbol(input_shape, style) style_loss, content_loss = get_loss(gram, content) sym = mx.sym.Group([style_loss, content_loss]) init = PretrainedInit(prefix, params) gram_size = len(gram.list_outputs()) mod = mx.mod.Module(symbol=sym, data_names=("%s_data" % prefix,), label_names=None, context=ctx) mod.bind(data_shapes=[("%s_data" % prefix, dshape)], for_training=True, inputs_need_grad=True) mod.init_params(init) return mod, gscale