API Reference¶
stylish¶
-
stylish.
transform_image
(path, style_path, output_path, vgg_path, iterations=None, learning_rate=None, content_weight=None, style_weight=None, tv_weight=None, content_layer=None, style_layers=None, log_path=None)[source]¶ Generate new image from path with style from another image.
Usage example:
>>> transform_image( ... "/path/to/image.jpg", ... "/path/to/style_image.jpg", ... "/path/to/output_image/", ... "/path/to/vgg_model.mat" ... )
Parameters: - path – path to the image to transform.
- style_path – path to an image from which the style features will be extracted.
- output_path – path where the transformed image will be generated.
- vgg_path – path to the Vgg19 pre-trained model in the MatConvNet data format.
- iterations – number of time that image should be trained against
style_path. Default is
stylish.core.ITERATIONS_NUMBER
. - learning_rate – Learning Rate value to train the model.
Default is
stylish.core.LEARNING_RATE
. - content_weight – weight of the content feature cost. Default is
stylish.core.CONTENT_WEIGHT
. - style_weight – weight of the style feature cost. Default is
stylish.core.STYLE_WEIGHT
. - tv_weight – weight of the total variation cost. Default is
stylish.core.TV_WEIGHT
. - content_layer – Layer name from pre-trained Vgg19 model
used to extract the content information. Default is
stylish.vgg.CONTENT_LAYER
. - style_layers – Layer names from pre-trained Vgg19 model
used to extract the style information with corresponding weights.
Default is
stylish.vgg.STYLE_LAYERS
. - log_path – path to extract the log information. Default is the same path as the output path.
Returns: path to transformed image.
-
stylish.
create_model
(training_path, style_path, output_path, vgg_path, learning_rate=None, batch_size=None, batch_shape=None, epoch_number=None, content_weight=None, style_weight=None, tv_weight=None, content_layer=None, style_layers=None, limit_training=None, log_path=None)[source]¶ Train a style generator model based on an image and a dataset folder
Usage example:
>>> create_model( ... "/path/to/training_data/", ... "/path/to/style_image.jpg", ... "/path/to/output_model/", ... "/path/to/vgg_model.mat" ... )
Parameters: - training_path – training dataset folder.
- style_path – path to an image from which the style features will be extracted.
- output_path – path where the trained model and logs should be saved
- vgg_path – path to the Vgg19 pre-trained model in the MatConvNet data format.
- learning_rate – Learning Rate value to train the model.
Default is
stylish.core.LEARNING_RATE
. - batch_size – number of images to use in one training iteration.
Default is
stylish.core.BATCH_SIZE
. - batch_shape – shape used for each images within training dataset.
Default is
stylish.core.BATCH_SHAPE
. - epoch_number – number of time that model should be trained against
training_images. Default is
stylish.core.EPOCHS_NUMBER
. - content_weight – weight of the content feature cost. Default is
stylish.core.CONTENT_WEIGHT
. - style_weight – weight of the style feature cost. Default is
stylish.core.STYLE_WEIGHT
. - tv_weight – weight of the total variation cost. Default is
stylish.core.TV_WEIGHT
. - content_layer – Layer name from pre-trained Vgg19 model
used to extract the content information. Default is
stylish.vgg.CONTENT_LAYER
. - style_layers – Layer names from pre-trained Vgg19 model
used to extract the style information with corresponding weights.
Default is
stylish.vgg.STYLE_LAYERS
. - limit_training – maximum number of files to use from the training dataset folder. By default, all files from the training dataset folder are used.
- log_path – path to extract the log information. Default is the same path as the output path.
Returns: None
-
stylish.
apply_model
(model_path, input_path, output_path)[source]¶ Apply style generator model to a new image.
Usage example:
>>> apply_model( ... "/path/to/saved_model/", ... "/path/to/image.jpg", ... "/path/to/output_image/" ... ) /path/to/output/image.jpg
Parameters: - model_path – path to trained model saved.
- input_path – path to image to inferred model to.
- output_path – path folder to save image output.
Returns: path to transformed image.
-
stylish.
extract_style_pattern
(path, output_path, vgg_path, style_layers=None)[source]¶ Generate style pattern images from image path.
Usage example:
>>> apply_model( ... "/path/to/style_image.jpg", ... "/path/to/output/" ... "/path/to/vgg_model.mat" ... ) /path/to/output/image.jpg
Parameters: - path – path to the image to extract style pattern images from.
- output_path – path where the images will be generated.
- vgg_path – path to the Vgg19 pre-trained model in the MatConvNet data format.
- style_layers – Layer names from pre-trained Vgg19 model
used to extract the style information with corresponding weights.
Default is
stylish.vgg.STYLE_LAYERS
.
Returns: list of image paths generated.