Skip to main content

Neural Style Transfer using VGG19

Project description

NST_VGG19

Neural Style Transfer using VGG19.

Original paper link.

VGG19 weights from torchvision.

Installation

pip install nst_vgg19

Usage

from nst_vgg19 import NST_VGG19

# images must be Numpy arrays. Use np.array(pil_image)

style_image = load_image('style.png')
content_image_1 = load_image('img1.jpg')
content_image_2 = load_image('img2.png')

nst = NST_VGG19(style_image)

result_1 = nst(content_image_1)
result_2 = nst(content_image_2)

NST_VGG19 constructor options

  • style_image_numpy: Numpy array of the style image in format (Heght, Width, Channels). This is a default Numpy image array.
  • content_layers_weights: Dictionary of weights for content losses.
  • style_layers_weights: Dictionary of weights for style losses.
  • quality_loss_weight: Weight for quality loss.
  • delta_loss_threshold: Loss change threshold for stopping optimization.

If you do not specify weights of loss, the folowing parameters will be used:

DEFAULT_CONTENT_WEIGHTS = {
    'conv_1': 35000,  # Shape?
    'conv_2': 28000,
    'conv_4': 30000,
}
DEFAULT_STYLE_WEIGHTS = {
    'conv_2': 0.000001,  # Light/shadow?
    'conv_4': 0.000009,  # Contrast?
    'conv_5': 0.000006,  # Volume?
    'conv_7': 0.000003,
    'conv_8': 0.000002,  # Dents?
    'conv_9': 0.000003
}
quality_loss_weight=2e-4

If optimization delta becomes less than delta_loss_threshold then style transfer stops.

nst = NST_VGG19(style_image, style_layers_weights=my_weights, delta_loss_threshold=0.001)

result = nst(content_image) # no params except of image

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nst_vgg19-0.1.5.tar.gz (87.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nst_vgg19-0.1.5-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file nst_vgg19-0.1.5.tar.gz.

File metadata

  • Download URL: nst_vgg19-0.1.5.tar.gz
  • Upload date:
  • Size: 87.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for nst_vgg19-0.1.5.tar.gz
Algorithm Hash digest
SHA256 d92f91cb92ed88a6a5e22c1cfd2a7ef11d5f208860c8a3ff76a76c3945d3a1fa
MD5 5f5937b169f1e44f64e3c5664fe305aa
BLAKE2b-256 c04a197dc57aeccd784d30c6e40d466deeeceb55531cf87cb85362573ab8f67f

See more details on using hashes here.

File details

Details for the file nst_vgg19-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: nst_vgg19-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for nst_vgg19-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 aff122a93f96d205a059691cfb876a4eae82031c99be45488113d4b470b620c5
MD5 98e79a63a988d9220fc738f203d1a3a7
BLAKE2b-256 a49b64dcbfcc6ad5a6134045dc5fb1b0785eafefbe8dab9b3a82fa8b21674451

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page