Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

train pytorch CNN to specific image style

I’m trying to train pytorch CNN model to transform my images into specific style. I found tutorial for this at https://pytorch.org/tutorials/advanced/neural_style_tutorial.html, but this will transform the image in multiple iterations and I need to have a model that do the same thing to use it in C++ project then.

Then I found https://towardsdatascience.com/implementing-neural-style-transfer-using-pytorch-fd8d43fb7bfa that use the same princip, but there is a learning process but optimalizer still working with updating image in every step. When i tried to change optimalizer from

optimizer=optim.Adam([generated_image],lr=lr)

to

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

optimizer=optim.Adam(model.parameters(),lr=lr) 

it just stopped working at all.

Is there any way to train pytorch model to update images into specific style ? Eventualy is there any pretrained model for this ? I not able to find anything except tensorflow models but for this i need to use pytorch.

My inicial goal was to create model that transfer images into grayscale variant of it, but that was hard for me. So if anyone knows solution even for this small task it’s more than enought for me.

>Solution :

Meh, in a traditional neural style transfer the weights are the image itself.
The model should be frozen.
Obviously you can’t just change optimizer=optim.Adam([generated_image],lr=lr) to optimizer=optim.Adam(model.parameters(),lr=lr), it doesn’t make any sense. It would be useless.

But the good news is that there is a new way which is called Fast Neural Transfer Style, which you will have an additional model which will be the one whose parameters will be trained. And this allows the model to be able to transfer the style of different images really fast.

Go to google and search Fast Neural Transfer Style for pytorch.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading