rashid996958 commited on
Commit
cc079b9
·
1 Parent(s): 1296f70

Add application files

Browse files
Files changed (5) hide show
  1. app.py +76 -0
  2. dmt.pb +3 -0
  3. input/original.png +0 -0
  4. input/ref.png +0 -0
  5. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import numpy as np
3
+ from imageio.v2 import imread
4
+ import os, glob, cv2, shutil
5
+ from super_image import EdsrModel, ImageLoader
6
+ from PIL import Image
7
+ import gradio as gr
8
+
9
+ pb = 'dmt.pb'
10
+ style_dim = 8
11
+ img_size=256
12
+
13
+ model_scale = EdsrModel.from_pretrained('eugenesiow/edsr-base', scale=2)
14
+
15
+ def preprocess(img):
16
+ return (img / 255. - 0.5) * 2
17
+
18
+ def deprocess(img):
19
+ return (img + 1) / 2
20
+
21
+ def load_image(path):
22
+ img = cv2.resize(imread(path), (img_size, img_size))
23
+ img_ = np.expand_dims(preprocess(img), 0)
24
+ return img / 255., img_
25
+
26
+ def inference(A,B):
27
+ with tf.Graph().as_default():
28
+ output_graph_def = tf.compat.v1.GraphDef()
29
+
30
+ with open(pb, 'rb') as fr:
31
+ output_graph_def.ParseFromString(fr.read())
32
+ tf.import_graph_def(output_graph_def, name='')
33
+
34
+ sess = tf.compat.v1.Session()
35
+ sess.run(tf.compat.v1.global_variables_initializer())
36
+ graph = tf.compat.v1.get_default_graph()
37
+ Xs = graph.get_tensor_by_name('decoder_1/g:0')
38
+ X = graph.get_tensor_by_name('X:0')
39
+ Y = graph.get_tensor_by_name('Y:0')
40
+ print("1")
41
+ A_img, A_img_ = load_image(A)
42
+ B_img, B_img_ = load_image(B)
43
+ Xs_ = sess.run(Xs, feed_dict={X: A_img_, Y: B_img_})
44
+ print("2")
45
+ output = deprocess(Xs_)[0]
46
+ output = np.array(np.array(output)*255,dtype=np.uint8)
47
+ # output = cv2.cvtColor(output, cv2.COLOR_RGB2BGR)
48
+
49
+ image = Image.fromarray(output)
50
+ inputs = ImageLoader.load_image(image)
51
+ preds = model_scale(inputs)
52
+ print(preds.shape)
53
+ ImageLoader.save_image(preds, 'output/scaled_2x.png')
54
+
55
+
56
+
57
+ def makeupTransfer(arr1,arr2):
58
+ print("-"*8)
59
+ shutil.rmtree("input/")
60
+ os.makedirs("input/")
61
+ output1 = cv2.cvtColor(arr1, cv2.COLOR_BGR2RGB)
62
+ output2 = cv2.cvtColor(arr2, cv2.COLOR_BGR2RGB)
63
+ cv2.imwrite("input/original.png",output1)
64
+ cv2.imwrite("input/ref.png",output2)
65
+ no_makeup = "input/original.png"
66
+ makeup = "input/ref.png"
67
+ inference(no_makeup, makeup)
68
+ return cv2.cvtColor(cv2.imread("output/scaled_2x.png"), cv2.COLOR_BGR2RGB)
69
+
70
+ app = gr.Interface(fn=makeupTransfer,
71
+ inputs=[gr.Image(label="Reference Image",type='numpy'),
72
+ gr.Image(label="Makeup Image",type='numpy')],
73
+ outputs=gr.Image(label="Makeup Transfer Image",type='numpy'),
74
+ title="MakeUp Transfer APP")
75
+
76
+ app.launch(share=True)
dmt.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9d4a54b5d6fad0b2be7939630aec03506ec8912b7a1b5e8529a709ec5e022947
3
+ size 47937309
input/original.png ADDED
input/ref.png ADDED
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ imageio==2.31.6
2
+ numpy==1.25.2
3
+ opencv_contrib_python==4.8.0.76
4
+ opencv_python==4.8.0.76
5
+ opencv_python_headless==4.9.0.80
6
+ tensorflow==2.15.0
7
+ super-image
8
+ gradio