stylish.vgg

Training model computation module from a Vgg19 model.

The Vgg19 model pre-trained for image classification is used as a loss network in order to define perceptual loss functions that measure perceptual differences in content and style between images.

The loss network remains fixed during the training process.

See also

Johnson et al. (2016). Perceptual losses for real-time style transfer and superresolution. CoRR, abs/1603.08155.

See also

Simonyan et al. (2014). Very Deep Convolutional Networks for Large-Scale Image Recognition. CoRR, abs/1409.1556.

And the corresponding Vgg19 pre-trained model in the MatConvNet data format.

stylish.vgg.STYLE_LAYERS = ['conv1_1/Relu', 'conv2_1/Relu', 'conv3_1/Relu', 'conv4_1/Relu', 'conv5_1/Relu']

List of layers used to extract style features.

stylish.vgg.CONTENT_LAYER = 'conv4_2/Relu'

Layer used to extract the content features.

stylish.vgg.extract_mapping(path)[source]

Compute and return weights and biases mapping from Vgg19 model path.

The mapping should be returned in the form of:

{
    "conv1_1": {
        "weight": numpy.ndarray([...]),
        "bias": numpy.ndarray([...])
    },
    "conv1_2": {
        "weight": numpy.ndarray([...]),
        "bias": numpy.ndarray([...])
    },
    ...
}

path should be the path to the Vgg19 pre-trained model in the MatConvNet data format.

Raise RuntimeError if the model loaded is incorrect.

stylish.vgg.network(vgg_mapping, input_node)[source]

Compute and return network from mapping with an input_node.

vgg_mapping should gather all weight and bias matrices extracted from a pre-trained Vgg19 model (e.g. extract_mapping()).

input_node should be a 3-D Tensor representing an image of undefined size with 3 channels (Red, Green and Blue). It will be the input of the graph model.

stylish.vgg.conv2d_layer(name, vgg_mapping, input_node)[source]

Add 2D convolution layer named name to mapping.

The layer returned should contain:

name should be the name of the convolution layer.

vgg_mapping should gather all weight and bias matrices extracted from a pre-trained Vgg19 model (e.g. extract_mapping()).

input_node should be a Tensor that will be set as the input of the convolution layer.

Raise KeyError if the weight and bias matrices cannot be extracted from vgg_mapping.

stylish.vgg.pool_layer(name, input_node)[source]

Return max pooling layer named name.

The layer returned should contain:

name should be the name of the max layer.

input_node should be a Tensor that will be set as the input of the max layer.