Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How we can call it from code? #56

Open
skanel opened this issue Nov 21, 2019 · 2 comments
Open

How we can call it from code? #56

skanel opened this issue Nov 21, 2019 · 2 comments

Comments

@skanel
Copy link

skanel commented Nov 21, 2019

How we can call it from code like call a function to generate style image?

@momo-the-monster
Copy link

momo-the-monster commented Jan 14, 2020

Here's my suggestion on how to make this function as-is as well as from code.
Edit: Now encapsulated in this pull request

in neural_style.py, rename the 'main' function to 'transfer', and have it accept a params object so it looks like this:
def transfer(params):

then create another function to replace main like this:

def main():
    transfer(params)

To construct this object, we'll add a Class for all of the known params:

class TransferParams():
    style_image = 'examples/inputs/seated-nude.jpg'
    style_blend_weights = None
    content_image = 'examples/inputs/tubingen.jpg'
    image_size = 512
    gpu = 0
    content_weight = 5e0
    style_weight = 1e2
    normalize_weights = False
    tv_weight = 1e-3
    num_iterations = 1000
    init = 'random'
    init_image = None
    optimizer = 'lbfgs'
    learning_rate = 1e0
    lbfgs_num_correction = 100
    print_iter = 50
    save_iter = 100
    output_image = 'out.png'
    log_level = 10
    style_scale = 1.0
    original_colors = 0
    pooling = 'max'
    model_file = 'models/vgg19-d01eb7cb.pth'
    disable_check = False
    backend = 'nn'
    cudnn_autotune = False
    seed = -1
    content_layers = 'relu4_2'
    style_layers = 'relu1_1,relu2_1,relu3_1,relu4_1,relu5_1'
    multidevice_strategy = '4,7,29'

Finally, you can now use it in another file like this:

import neural_style

params = neural_style.TransferParams()
params.gpu = 0
params.backend = 'cudnn'
params.image_size = 128
neural_style.transfer(params)

I've got a project where it would be handy to have a Style Transfer web server, so this is how I'm implementing it.

@owos
Copy link

owos commented Sep 11, 2022

Hey are you done building already?
I would love to see your webserver @momo-the-monster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants