question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fork implementing multi-region spatial control

See original GitHub issue

First of all, this is a great repo! It seems a bit faster and more memory efficient than the original lua-based neural-style.

I’ve made a fork of this repo trying to add masked style transfer as described by Gatys, and going off of the gist you wrote for the lua version.

I’ve almost got it working, but my implementation is suffering from two bugs. The first is that, testing with two style images and segmentations, my implementation seems only to get gradients for the first mask but not the second.

So for example, the following command:

python neural_style.py -backend cudnn -style_image examples/inputs/cubist.jpg,examples/inputs/starry_night.jpg -style_seg examples/segments/cubist.png,examples/segments/starry_night.png -content_seg examples/segments/monalisa.png -color_codes white,black

produces the following output:

out1

where the first style (cubist) and corresponding segmentation get good gradients and works in the mask provided, but the second mask (starry night) has little or no gradient signal.

By simply swapping the order of the style images, as in:

python neural_style.py -backend cudnn -style_image examples/inputs/starry_night.jpg,examples/inputs/cubist.jpg -style_seg examples/segments/starry_night.png,examples/segments/cubist.png -content_seg examples/segments/monalisa.png -color_codes white,black

I get the opposite effect where only the starry night style works and the cubist style in its mask is not there.

out2

I have been trying to debug this, checking the masks, and everything seems right to me, and I can’t figure out the problem. This was almost a pytorch mirror of what you made in your gist, which does appear to work fine. I’m not sure if there’s some typo I’m missing or something deeper.

Additionally, loss.backward() without keeping the gradients with retain_graph=True produces a runtime error (RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time.), which makes me think I setup the graph wrong.

If you are able to see what I’m doing wrong so that we can fix it, I’d love to see this implemented in PyTorch. I think it would be a really nice addition to the repo.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:34 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
genekogancommented, Dec 11, 2019

I just updated my histogram_loss branch with your Histogram loss module, and made it support masking in the same way the Style Loss does. I also added a covariance loss option for the normal StyleLoss module. So far with limited tests, histogram loss does not seem to do much to fix the blending problem. I’m going to do some tests combining the style loss parameters and see if I can either improve that issue somehow or at least get the general style transfer to look nicer.

1reaction
genekogancommented, Dec 8, 2019

Another note about transitional blending problem. I e-mailed Leon Gatys about it and he suggested that since covariance loss seems to reduce the smudging effect more than Gram, to try using covariance loss on the lower layers (where the differences between the styles are greatest) and using Gram on the higher layers to preserve better style reconstruction. Going to try that next.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Self-standing quasi-random-dots fork gratings for single-order ...
Both simulation and experimental results confirm that quasi-random-dots fork gratings can effectively eliminate diffractions of second order and higher orders, ...
Read more >
Loss of PBRM1 rescues VHL dependent replication stress to ...
To directly explore the effect of Vhl inactivation on DNA replication, we evaluated replication fork dynamics using DNA fibre assays.
Read more >
The EU's farm‐to‐fork strategy: An assessment from the ...
The EU Farm to Fork (F2F) strategy includes a number of policy objectives that have implications for agricultural production in the EU and ......
Read more >
Going Global to Local: Connecting Top-Down Accounting and ...
(26) They can also be modeled by using spatially explicit simulations that often ... Multiregion input–output tables at the regional level, ...
Read more >
spectral and spatial control of broadband light using
and spatial domains using wavefront control for solar energy, ... A variety of the DOE profiles exist as fork grating [49], diffractive axi-....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found