Example #1
0
def generate(style_img_path, content_image, num_iteration=50):
    content_image = BytesIO(content_image)
    style_image = image_loader(
        os.path.join("frontend", "style", style_img_path))
    content_image = image_loader(content_image)
    input_img = content_image.clone()
    output_image = run_style_transfer(cnn,
                                      cnn_normalization_mean,
                                      cnn_normalization_std,
                                      content_image,
                                      style_image,
                                      input_img,
                                      num_steps=num_iteration)
    image = output_image.cpu().clone()
    image = image.squeeze(0)
    image = unloader(image)
    img_byte_arr = io.BytesIO()
    image.save(img_byte_arr, format='PNG')
    img_byte_arr = img_byte_arr.getvalue()
    return img_byte_arr