apple / turicreate

Turi Create simplifies the development of custom machine learning models.
BSD 3-Clause "New" or "Revised" License
11.2k stars 1.14k forks source link

Bad result with 100.000 iterations #1899

Closed banoslo closed 5 years ago

banoslo commented 5 years ago

Thanks for your great work on the framework. I am trying to apply style transfer on an image. But why is the result so bad looking? (I tested 100.000 and 10.000 iterations the results are similar)

This is my setting: I use Ubuntu 18 and the recent Turicreate version for Python 3.6 with mxnet CUDA 9.1 on a NVIDIA GTX 950. I use the code lines from the Docs with a 100.000 training iterations.

Style image: gogh

Test image: architecture-buildings-chicago-416942

Result image: result8

srikris commented 5 years ago

@banoslo What version of Turi Create as you using? We recently made some improvements that improved the quality of style transfer drastically.

banoslo commented 5 years ago

It is version 5.5. Should this show better results?

nickjong commented 5 years ago

The improvements that @srikris referenced should be in 5.5, so we should take a look at what's going on here

abhishekpratapa commented 5 years ago

Parameters to help train Style Transfer Models

Hopefully these tips will help you achieve a better result @banoslo. It'll go over the things you could experiment with and modify to iteratively achieve the model you desire.

style_loss_mult

The larger the values of the style_loss_mult, the more stylized the image is. The diagram below illustrates this effect (Note: the model was trained for 64,000 iterations.)

style_loss_computation

An example of setting the style_loss_mult flag is show below:

model = tc.style_transfer.create(styles, content, _advanced_parameters={"style_loss_mult":[1e-4, 1e-4, 1e-4, 1e-4]})

finetune_all_params

There are two different approaches to updating parameters in the style transfer network.

An example of setting the finetune_all_params flag is show below:

model = tc.style_transfer.create(styles, content, _advanced_parameters={"finetune_all_params":False})
finetune_all_params = False

Pros

Cons

finetune_all_params = True

Pros

Cons

pretrained_weights

This option allows for the loading of pre-trained weights from a model trained with 32 distinct style images. For some styles, pre-trained weights can act as a warm-start for the training; for other styles these weights can by a hinderance, potentially introducting artifacts when stylizing images. As convergence is heavily determined by the style images chosen, further user experimentation is required.

When finetune_all_params is False, pretrained_weights is required to be True else the model won't converge.

An example of setting the pretrained_weights flag is show below:

model = tc.style_transfer.create(styles, content, _advanced_parameters={"pretrained_weights":True})

See how-it-works for the paper from which these weights were procured.

Checkpointing

To assist with the qualatative nature of training the style transfer network, a checkpointing feature is exposed in the advanced parameters section. Rather than create multiple training loops for training models with different iterations, simply set the checkpoint flag to true and a turicreate model is saved with the prefix specified by checkpoint_prefix parameter every nth iteration which is specified by the checkpoint_increment parameter.

An example of using the checkpointing feature is show below:

model = tc.style_transfer.create(styles, content, _advanced_parameters={"checkpoint":True, "checkpoint_prefix":"./awesome-model", "checkpoint_increment":100})

If you need any additional help, let us know!