nazianafis / neural-style-transfer Goto Github PK
View Code? Open in Web Editor NEWTransferring the style of one image to the contents of another image, using PyTorch and VGG19.
License: MIT License
Transferring the style of one image to the contents of another image, using PyTorch and VGG19.
License: MIT License
I want to
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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.