Sophie98 commited on
Commit
bf82406
1 Parent(s): 37c16a8

added style projection

Browse files
Files changed (2) hide show
  1. requirements.txt +4 -1
  2. styleTransfer.py +19 -9
requirements.txt CHANGED
@@ -10,4 +10,7 @@ gradio
10
  segmentation_models
11
  opencv-python-headless
12
  tensorflow-cpu
13
- tensorflow_hub
 
 
 
 
10
  segmentation_models
11
  opencv-python-headless
12
  tensorflow-cpu
13
+ tensorflow_hub
14
+
15
+ paddlepaddle
16
+ paddlehub
styleTransfer.py CHANGED
@@ -2,14 +2,16 @@ from PIL import Image
2
  import numpy as np
3
  import torch
4
  import torch.nn as nn
5
- from PIL import Image
6
  from torchvision import transforms
7
  import transformer as transformer
8
  import StyTR as StyTR
9
- import numpy as np
10
  from collections import OrderedDict
11
- import tensorflow_hub as hub
12
  import tensorflow as tf
 
 
 
 
13
 
14
  ############################################# TRANSFORMER ############################################
15
 
@@ -82,7 +84,7 @@ def StyleTransformer(content_img: Image, style_img: Image):
82
 
83
  ############################################## STYLE-GAN #############################################
84
 
85
- style_transfer_model = hub.load("https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2")
86
 
87
  def StyleGAN(content_image, style_image):
88
  content_image = tf.convert_to_tensor(content_image, np.float32)[tf.newaxis, ...] / 255.
@@ -91,10 +93,18 @@ def StyleGAN(content_image, style_image):
91
  stylized_image = output[0]
92
  return Image.fromarray(np.uint8(stylized_image[0] * 255))
93
 
94
- ################################################# MAIN ################################################
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
 
97
- def create_styledSofa(sofa:Image, style:Image):
98
- #styled_sofa = StyleGAN(sofa,style)
99
- styled_sofa = StyleTransformer(sofa,style)
100
- return styled_sofa
 
2
  import numpy as np
3
  import torch
4
  import torch.nn as nn
 
5
  from torchvision import transforms
6
  import transformer as transformer
7
  import StyTR as StyTR
 
8
  from collections import OrderedDict
9
+ import tensorflow_hub as tfhub
10
  import tensorflow as tf
11
+ import os
12
+ import cv2
13
+ import paddlehub as phub
14
+
15
 
16
  ############################################# TRANSFORMER ############################################
17
 
 
84
 
85
  ############################################## STYLE-GAN #############################################
86
 
87
+ style_transfer_model = tfhub.load("https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2")
88
 
89
  def StyleGAN(content_image, style_image):
90
  content_image = tf.convert_to_tensor(content_image, np.float32)[tf.newaxis, ...] / 255.
 
93
  stylized_image = output[0]
94
  return Image.fromarray(np.uint8(stylized_image[0] * 255))
95
 
96
+ ########################################### STYLE PROJECTION ##########################################
97
+
98
+ stylepro_artistic = phub.Module(name="stylepro_artistic")
99
+
100
+ def styleProjection(content_image,style_image):
101
+ result = stylepro_artistic.style_transfer(
102
+ images=[{
103
+ 'content': np.array(content_image.convert('RGB') )[:, :, ::-1],
104
+ 'styles': [np.array(style_image.convert('RGB') )[:, :, ::-1]]
105
+ }])
106
+
107
+ return Image.fromarray(np.uint8(result[0]['data'])[:,:,::-1]).convert('RGB')
108
+
109
 
110