Пример #1
0
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
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
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
Пример #6
0
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