项目作者: matthias-wright

项目描述 :
PyTorch implementation of the siamese architecture for style transfer I developed for my master's thesis.
高级语言: Python
项目地址: git://github.com/matthias-wright/siamese_architecture.git
创建时间: 2019-11-23T12:33:30Z
项目社区:https://github.com/matthias-wright/siamese_architecture

开源协议:

下载


A Siamese Architecture for Neural Style Transfer

The implementation of the siamese architecture that I developed for my master’s thesis.

Dependencies

  • Python 3.5.2+
  • NumPy 1.11.0+
  • PyTorch 0.4.1+
  • PIL 1.1.7+
  • Matplotlib 3.0.1+

Example



Instructions

Training

  1. import siamese
  2. data_photo = '...' # file path to the photograph images (RGB) folder
  3. data_oil = '...' # file path to the oil images (RGB) folder
  4. siam_model = siamese.Siamese(in_path_photo=data_photo,
  5. in_path_oil=data_oil,
  6. autoencoder_path='saves/autoencoders',
  7. num_epochs=100, batch_size=50,
  8. learning_rate=0.0002,
  9. recon_loss_weight=10,
  10. penalty_coef=10, verbose=True)
  11. siam_model.train()

Load Pretrained Model

  1. import siamese
  2. data_photo = '...' # file path to the photograph images (RGB) folder
  3. data_oil = '...' # file path to the oil images (RGB) folder
  4. siam_model = siamese.Siamese(in_path_photo=data_photo,
  5. in_path_oil=data_oil,
  6. autoencoder_path='saves/autoencoders',
  7. num_epochs=100, batch_size=50,
  8. learning_rate=0.0002,
  9. recon_loss_weight=10,
  10. penalty_coef=10, verbose=True)
  11. siam_model.load(epoch=18, path='saves')

Style Transfer

  1. import siamese
  2. import util
  3. siam_model = siamese.Siamese(autoencoder_path='saves/autoencoders')
  4. siam_model.load(epoch=18, path='saves')
  5. x_photo = util.image_to_tensor('image.jpg')
  6. x_oil = siam_model.translate_photo_to_oil(x_photo)
  7. x_oil = util.tensor_to_numpy(x_oil)
  8. x_oil = util.numpy_to_image(x_oil)
  9. x_oil.save('stylized_image.png')

License

This project is licensed under the MIT Licence