GithubHelp home page GithubHelp logo

nazianafis / neural-style-transfer Goto Github PK

View Code? Open in Web Editor NEW
29.0 2.0 5.0 92.21 MB

Transferring the style of one image to the contents of another image, using PyTorch and VGG19.

Home Page: https://medium.com/geekculture/a-lightweight-pytorch-implementation-of-neural-style-transfer-86603e5eb551

License: MIT License

Python 100.00%
neural-style-transfer pytorch vgg19

neural-style-transfer's People

Contributors

nazianafis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

neural-style-transfer's Issues

Normalization Issue

The loss values diverge very quickly for non-compatible content and style images, and in some cases leading to NaN values. By non-compatible, I refer to images that are not fit for style transfer due to lighting etc. issues.

Is there a normalization mechanism in place that can regulate the loss while maintaining the quality of the "transfer"? I tried the following - which is helping - but I'm not sure if hard-coding it like this is best practice.

Normalizing the gram matrix values:

def gram_matrix(x):
    if x.dim() == 3:
        x = x.unsqueeze(0)  # Add a batch dimension if missing
    
    b, ch, h, w = x.size()
    features = x.view(b, ch, w * h)
    G = features.bmm(features.transpose(1, 2))
    return G.div(ch * h * w * b)    # additional normalization by batch size

Normalize TV loss:

def total_variation(y):
    batch_size, channels, height, width = y.size()
    tv_height = torch.abs(y[:, :, :-1, :] - y[:, :, 1:, :]).sum()
    tv_width = torch.abs(y[:, :, :, :-1] - y[:, :, :, 1:]).sum()
    return (tv_height + tv_width) / (batch_size * channels * height * width)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.