not sure if my settings are correct? by t0mni in deepdream

[–]jcjohnss 2 points3 points  (0 children)

Reduce the style weight. Maybe try 5e1?

[D] TensorFlow vs. PyTorch: why is dynamic better? by whoeverwhatever in MachineLearning

[–]jcjohnss 2 points3 points  (0 children)

If you try and implement this in TF as a static graph, routing between nodes with conditionals, then your static graph needs to contain all possible dynamic graphs as subgraphs. In the worst case this could lead to an exponential blowup in the size of the graph, which will very quickly cause the problem to become intractible.

[D] TensorFlow vs. PyTorch: why is dynamic better? by whoeverwhatever in MachineLearning

[–]jcjohnss 8 points9 points  (0 children)

In my mind, the best example of a model that needs dynamic graph are neural module networks [1, 2]. These models address the problem of question answering (possibly conditioned on an image) where you want to answer a natural-language question (about an image).

For a question like "what color is the thing to the right of the cat" we imagine that there are several subtasks: first find the cat, then look to the right, then check the color. A neural module network trains jointly a set of modules that specialize in subtasks like finding objects or shifting attention; for every question these modules are assembled into a custom neural network architecture that answers the question.

This style of algorithm, where every input has its own unique computational graph, would be very difficult to implement in most frameworks but is a very natural fit for a dynamic framework like PyTorch. Neural module networks were in fact implemented in ApolloCaffe which is a Caffe fork that adds support for dynamic graph construction.

[1] https://arxiv.org/abs/1511.02799

[2] https://arxiv.org/abs/1601.01705

UHD style transfer with multi-gPU neural-style by jcjohnss in deepdream

[–]jcjohnss[S] 1 point2 points  (0 children)

I think Infiniband is more trouble than it's worth for your use cases.

You can do a lot with just a single GPU - almost all the research projects I have worked on have trained on just a single fast GPU; high-resolution neural-style is one of the first times I've needed to use multiple GPUs on a single machine, and I've never needed to distribute any job across multiple machines using Infiniband.

It's also worth pointing out that distributing jobs across multiple servers does not have good support in standard frameworks, so you'll end up writing a lot of code yourself if you want to do any sort of multi-machine work.

[D] What is the configuration of your ML rig? by AntixK in MachineLearning

[–]jcjohnss 2 points3 points  (0 children)

My personal desktop has i7-4790k, 32GB RAM, SSD, 1x Maxwell Titan X and 1x Pascal Titan X; I have another similar machine with 1x Titan Z. I do a lot of my development on these machines.

My lab has a bunch of 4x Pascal Titan X machines with dual Xeon E5-2620-v4 (8-core) and 128GB RAM that I use for experiments.

UHD style transfer with multi-gPU neural-style by jcjohnss in deepdream

[–]jcjohnss[S] 1 point2 points  (0 children)

Our servers are these:

http://www.colfax-intl.com/nd/workstations/sxt9600.aspx

Each machine has 4 local GPUs connected over standard PCI-E.

Infiniband allows for fast GPU-to-GPU communication over a network which is useful for distributed training over many servers; we don't do that and instead just keep jobs local to one server.

In addition to these servers, students in our lab have standalone machines for development with the following configuration:

https://pcpartpicker.com/list/xfBgtJ

This is about $1200 before GPUs and could support any two GPUs of your choice.

For a more barebones budget build you could do something like the following:

https://pcpartpicker.com/list/mZrrD8

This is about $1100 for a build with a GTX 1070, and it should be able to support a second GPU.

Total loss not monotone decreasing by Thelonius--Drunk in deepdream

[–]jcjohnss 0 points1 point  (0 children)

If you are using neural-style with TV regularization, then the TV term does not contribute to the printed loss but it does affect the optimization. This could be one explanation for non-monotonic losses.

This is what happens when you continuously decrease style scale while Upsizing a multires image by SwoosHkiD in deepdream

[–]jcjohnss 2 points3 points  (0 children)

This is a very nice effect - good work!

When I zoom in there is a little lit of blurring at the pixel level that I don't find very appealing; are you using TV regularization? I've found that with multires you can sometimes get better results turning off TV smoothing entirely.

UHD style transfer with multi-gPU neural-style by jcjohnss in deepdream

[–]jcjohnss[S] 1 point2 points  (0 children)

The total render time for that image was only about 10 minutes.

I can't get my images to turn out like anyone elses by [deleted] in deepdream

[–]jcjohnss 0 points1 point  (0 children)

The -init_image option is relatively new; you may need to update neural-style in order to use it.

Pointing at directories of content and style images is pretty straightforward; you could easily do this with a bash or Python script.

UHD style transfer with multi-gPU neural-style by jcjohnss in deepdream

[–]jcjohnss[S] 2 points3 points  (0 children)

(1) The -multigpu_strategy flag interacts with the -gpu flag: -gpu tells you which GPUs to use, and in what order to use them; -multigpu_strategy tells how to distribute layers across the different GPUs.

In starry_stanford.sh, we give the flag -gpu 0,1,2,3 which tells neural-style that we want to use 4 GPUs: GPU 0, 1, 2, and 3 in that order. The flag -multigpu_strategy 3,6,12 means to run layers 1-2 on GPU 0, layers 3-5 on GPU 1, layers 6-11 on GPU 2, and all remaining layers on GPU 3.

For this to work out, -multigpu_strategy needs to be a list with one element less than -gpu; the assertion error you are seeing checks that this is the case.

(2) L-BFGS and Adam are two different optimization algorithms; in general L-BFGS gives better results than Adam, but uses a lot more memory. The -lbfgs_num_corrections parameter lets you trade off memory usage and accuracy within the L-BFGS algorithm; the higher values of -lbfgs_num_corrections will use more memory but may give better results (the default is 100).

L-BFGS and Adam are both approximate second-order optimization algorithms, meaning that they use samples of the first derivative (slope, gradient) to approximate the second derivative (curvature, Hessian). L-BFGS (roughly speaking) keeps an explicit history of first derivatives while Adam uses various running averages of first derivative statistics; using explicit histories allows L-BFGS to better approximate the true second derivative, but keeping an explicit history takes a lot of memory. The -lbfgs_num_corrections argument controls the size of the gradient history that L-BFGS keeps, which can reduce the memory usage at the expense of less accurate estimates of the second derivative.

UHD style transfer with multi-gPU neural-style by jcjohnss in deepdream

[–]jcjohnss[S] 3 points4 points  (0 children)

Yes, you should be able to split the computation even between cards of different sizes. You'll have to manually specify the split using the -multigpu_strategy flag.

UHD style transfer with multi-gPU neural-style by jcjohnss in deepdream

[–]jcjohnss[S] 9 points10 points  (0 children)

Over the past couple evenings I've added multi-GPU support to neural-style:

https://github.com/jcjohnson/neural-style/issues/351

When combined with multi-scale rendering, this allows for high-quality style transfer at very high resolutions. On my desktop with two Titan X I can generate images with a width of 2800px, and on a server with four Titan X I can generate images up to about 3600px in width.

I can't get my images to turn out like anyone elses by [deleted] in deepdream

[–]jcjohnss 2 points3 points  (0 children)

In addition to adjusting style and content weights, you also need to play with the style scale and the output size; these can have a big impact on the generated image.

For really good results at high resolution you need to use multiscale processing: first generate a low-resolution image, then use the output as initialization for a higher-resolution result. Here's an example:

http://imgur.com/a/snG5J

This was generated with the following script, which you should be able to tweak for your needs:

https://gist.github.com/jcjohnson/ca1f29057a187bc7721a3a8c418cc7db

The style image here was an ultra-high-res scan of Starry Night from the Google Art Project (warning: 200MB image)

https://upload.wikimedia.org/wikipedia/commons/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg

Trying to setup fast-neural-style to work with an AMD GPU by tychonov in deepdream

[–]jcjohnss 1 point2 points  (0 children)

fast-neural-style uses a SpatialReflectionPadding layer which apparently is not currently implemented in the OpenCL backend for Torch; I've opened an issue to try and address the issue.

Until this gets fixed you won't be able to use fast-neural-style on AMD GPUs ... Sorry =(

What are some good books for Deep Learning? by TheNASAguy in deepdream

[–]jcjohnss 2 points3 points  (0 children)

You should check out the book by Goodfellow, Bengio, and Courville:

http://www.deeplearningbook.org/

I'll also give a shameless plug for cs231n at Stanford:

http://cs231n.stanford.edu/

fast-neural-style: Feedforward style transfer by jcjohnss in deepdream

[–]jcjohnss[S] 3 points4 points  (0 children)

The webcam demo does not have any temporal consistency; it just runs the model on each frame.

fast-neural-style: Feedforward style transfer by jcjohnss in deepdream

[–]jcjohnss[S] 0 points1 point  (0 children)

Surprisingly, in Torch it is easier to handle webcams than it is to handle video. One solution is to use ffmpeg to extract frames from your video, stylize each frame using fast_neural_style.lua, and then recombine the stylized frames using ffmpeg.

fast-neural-style: Feedforward style transfer by jcjohnss in deepdream

[–]jcjohnss[S] 1 point2 points  (0 children)

I just added a print_options.lua script that you can use to see the options used to train any feedforward model:

https://github.com/jcjohnson/fast-neural-style/blob/master/print_options.lua

fast-neural-style: Feedforward style transfer by jcjohnss in deepdream

[–]jcjohnss[S] 1 point2 points  (0 children)

The slow_neural_style.lua script here is implementing the same algorithm as neural_style.lua, but the code is cleaner and more modular; this modularity means that both slow_neural_style.lua and train.lua call into the exact same code to compute losses, allowing for fair apples-to-apples comparisons between the optimization-based method and the feedforward method.

The exact details of normalization are a bit different between neural_style.lua and slow_neural_style.lua, so they will probably give different results for the same hyperparameters.

The two different implementations also have slightly different sets of features; neural_style.lua supports multiple style images and color-preserving style transfer, which are not implemented in slow_neural_style.lua. On the other hand slow_neural_style.lua should work with a much larger set of CNNs than neural_style.lua; I know for sure that it works with ResNets, and it should also work with GoogLeNet. I haven't written up documentation for it yet, but slow_neural_style.lua also supports simultaneous style transfer and DeepDream, which can give some pretty cool results.

fast-neural-style: Feedforward style transfer by jcjohnss in deepdream

[–]jcjohnss[S] 2 points3 points  (0 children)

Training a feedforward model takes a lot more resources than standard neural-style; training takes around 2-3 hours on a Pascal Titan X and takes roughly 6 GB of GPU memory.

Once you have a trained model, using it to stylize images uses a lot less resources than standard neural-style. Stylizing an image requires a single forward pass through the model which can easily be hundreds of times faster than standard neural-style. It should also use significantly less memory than standard neural-style, but the memory savings are not as extreme as the computational savings; I haven't measured but I would expect to see somewhere around 2x to 5x memory reduction compared to standard neural-style.

You should easily be able to stylize images larger than 1200px. Also because of the massive time speedup, it is feasible to run run very large images on CPU if you are constrained by memory.

Quality is obviously a lot more subjective; I think that the best optimization-based results are better than the best feedforward results, but models with instance normalization come pretty close.

However I have found that feedforward models can be more consistent in terms of quality - once you have trained a good feedforward model, it gives pretty consistent results across all input images. Standard neural-style sometimes requires a lot more tuning per-image to get good results.

fast-neural-style: Feedforward style transfer by jcjohnss in deepdream

[–]jcjohnss[S] 3 points4 points  (0 children)

Using the webcam demo on AWS is probably not going to work; I'm not sure how you would forward the local webcam to the AWS instance. Even if you did figure out how to do that it probably would not be realtime since you'd have to ship frames back and forth over the network.

slow_neural_style.lua is fundamentally the same as the original neural style, but the implementation is different so the same hyperparameters may not apply. It does not currently support multiple style images or color preservation, but it does support more networks like ResNets and GoogLeNet, and supports per-layer weights for content and style loss terms. It also supports simultaneous DeepDream and style transfer which I need to make a nice example for.

It should be totally fine to install this alongside the original neural style.

For those who have purchased the TITAN XP or are planning on purchasing the 1080 Ti: what made you choose one over the other? by aphilentus in nvidia

[–]jcjohnss 2 points3 points  (0 children)

I do deep learning - 8GB in the 1080 is not enough memory for me, and the Titan XP is around 10 - 15% faster for common workloads. Absolutely no regrets, even though I have yet to game on it.