Modules¶
Main module.
-
pastafy.pastafy.
combine_content_style
(content: numpy.ndarray, style: numpy.ndarray) → tuple[source]¶ Combines style and content image and generates input tensor using this combination.
- Args:
content: Array containing the content image.
style: Array containing the style image.
- Returns:
- Tuple of Tensorflow Tensors: combination tensor and input tensor.
-
pastafy.pastafy.
content_loss
(content: tensorflow.python.framework.ops.Tensor, combination: tensorflow.python.framework.ops.Tensor) → tensorflow.python.framework.ops.Tensor[source]¶ Computes content loss based on content and combination.
- Args:
content: Content tensor.
combination: Combination tensor.
- Returns:
- Loss tensor.
-
pastafy.pastafy.
generate_loss_from_layers
(model_layers: dict, desired_layer: tensorflow.python.framework.ops.Tensor, combination: tensorflow.python.framework.ops.Tensor, ratio: float, content_weight: float = 0.025, total_variation_weight: float = 1) → tensorflow.python.framework.ops.Tensor[source]¶ Generates loss tensor.
- Args:
model_layers: Dict of model layers’ names and outputs.
desired_layer: Desired layer name.
ratio: Ratio of the weights assigned to the style and content image (Alpha Beta ratio).
- Returns:
- Loss tensor.
-
pastafy.pastafy.
get_VGG16_layers
(input_tensor: tensorflow.python.framework.ops.Tensor, layer: int) → tuple[source]¶ Get VGG16 layers with ImageNet weights and extract specified feature layer.
- Args:
input_tensor: Input tensor for VGG16.
layer: Feature layer to be extracted.
- Returns:
- VGG16 layers and desired feature layer name to be extracted.
-
pastafy.pastafy.
gram_matrix
(x: tensorflow.python.framework.ops.Tensor) → tensorflow.python.framework.ops.Tensor[source]¶ Computes the Gram Matrix.
- Args:
- Tensor to be considered in Gramian Matrix calculation. Must be 4D (batch,.,.,.) or 3D.
- Returns:
- Gram Matrix.
-
pastafy.pastafy.
img_shape
(img_path: str) → tuple[source]¶ Return the shape of an image array.
- Args:
- img_path: Path to image.
- Returns:
- Height and width of the image.
-
pastafy.pastafy.
keras_function
(inputs: list, outputs: list) → list[source]¶ Instantiates a Keras function as described in tensorflow docs.
- Args:
inputs: List of placeholder tensors.
outputs: List of output tensors.
- Returns:
- Output values as Numpy arrays.
-
pastafy.pastafy.
keras_gradients
(loss: tensorflow.python.ops.resource_variable_ops.ResourceVariable, variables: list) → list[source]¶ Returns the gradients of loss w.r.t. variables as described in tensorflow docs.
- Args:
loss: Scalar tensor to minimize.
variables: List of variables.
- Returns:
- A gradients tensor.
-
pastafy.pastafy.
keras_variable
(value: float) → tensorflow.python.ops.resource_variable_ops.ResourceVariable[source]¶ - Args:
- value: Float/int value to be stored as a Keras variable.
- Returns:
- Keras varibale.
-
pastafy.pastafy.
preprocess_image
(img_path: str, height: int = 512, width: int = 512) → numpy.ndarray[source]¶ Loads and adequate image to the format the VGG16 requires.
- Args:
img_path: Path to image.
height: Height of target size. Depends on the model used (512 for VGG16).
width: Width of target size. Depends on the model used (512 for VGG16).
- Returns:
- Loaded and preprocessed image.
-
pastafy.pastafy.
save_output
(y: numpy.ndarray, size: tuple, output: str)[source]¶ Prepares and saves ouput image.
- Args:
y: Array with results that must be prepared and converted to image.
size: (width,height) resolution for output image.
output: Output image file name.
-
pastafy.pastafy.
style_loss
(style: tensorflow.python.framework.ops.Tensor, combination: tensorflow.python.framework.ops.Tensor) → tensorflow.python.framework.ops.Tensor[source]¶ Computes style loss based on style and combination.
- Args:
style: Content tensor. Must be 4D (batch,.,.,.) or 3D.
combination: Combination tensor. Must be 4D (batch,.,.,.) or 3D.
- Returns:
- Loss tensor.
-
pastafy.pastafy.
total_variation_loss
(x: tensorflow.python.framework.ops.Tensor) → tensorflow.python.framework.ops.Tensor[source]¶ Computes total loss.
- Args:
- x: Tensor considered. Must be 4D (batch,.,.,.) or 3D.
- Returns:
- Computed loss.
Console script for pastafy.
-
pastafy.cli.
main
()[source]¶ Console script for catify.
- CLI Args:
-i/–images: Images to be used. First one should be the content image (you) and second one the style (kitty). Alternatively, you could specify any desired content and style.
-n/–number: Number of iterations. Defaults to 10.
-l/–layer: Feature layer to be extracted. Defaults to 3.
-o/–output: Name of output image. Defaults to a concatenation of style image name and content image name.
-r/–ratio: Ratio of the weights assigned to the style and content image (Alpha Beta ratio). Defaults to 0.1.