b2c88da
user_wwq 3 years ago
2 changed file(s) with 74 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
11 "cells": [
22 {
33 "cell_type": "code",
4 "execution_count": 3,
5 "id": "34f17c80",
4 "execution_count": 9,
5 "id": "4695fed2",
66 "metadata": {},
7 "outputs": [
8 {
9 "name": "stderr",
10 "output_type": "stream",
11 "text": [
12 "2022-06-27 17:55:39.372674: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory\n",
13 "2022-06-27 17:55:39.372709: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.\n"
14 ]
15 },
16 {
17 "name": "stdout",
18 "output_type": "stream",
19 "text": [
20 "WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/python/compat/v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.\n",
21 "Instructions for updating:\n",
22 "non-resource variables are not supported in the long term\n",
23 "Imported model (for Places365, 128x128 images)\n"
24 ]
25 }
26 ],
7 "outputs": [],
278 "source": [
289 "import tensorflow.compat.v1 as tf\n",
2910 "tf.disable_v2_behavior()\n",
3819 },
3920 {
4021 "cell_type": "code",
41 "execution_count": 4,
42 "id": "8335c665",
22 "execution_count": 10,
23 "id": "5a4f0882",
4324 "metadata": {},
4425 "outputs": [],
4526 "source": [
4627 "model_PATH='/home/jovyan/work/src/output/models/model2000.ckpt'\n",
28 "out_PATH='/home/jovyan/work/results/test_output.png'\n",
4729 "IMAGE_SZ = 128"
4830 ]
4931 },
5032 {
5133 "cell_type": "code",
52 "execution_count": 8,
53 "id": "2709c7f3",
34 "execution_count": 11,
35 "id": "678d0cd4",
36 "metadata": {},
37 "outputs": [],
38 "source": [
39 "import time\n",
40 "def run_time(func):\n",
41 " def inner(model_PATH, img_p):\n",
42 " back = func(model_PATH, img_p)\n",
43 " print(\"Runned time: {} s\".format(round((time.time() - t)/10, 3)))\n",
44 " return back\n",
45 " t = time.time()\n",
46 " return inner"
47 ]
48 },
49 {
50 "cell_type": "code",
51 "execution_count": 12,
52 "id": "8f5ac323",
5453 "metadata": {},
5554 "outputs": [],
5655 "source": [
6261 },
6362 {
6463 "cell_type": "code",
65 "execution_count": 11,
66 "id": "a9d338ee",
64 "execution_count": 13,
65 "id": "eee977d9",
6766 "metadata": {},
6867 "outputs": [],
6968 "source": [
7069 "def image_to_path(img):\n",
7170 " resize_img = img\n",
72 " path = uuid.uuid4().hex + '.png'\n",
71 " path = out_PATH\n",
7372 " resize_img.save(path)\n",
7473 " return path"
7574 ]
7675 },
7776 {
7877 "cell_type": "code",
79 "execution_count": 6,
80 "id": "254b5ac4",
78 "execution_count": 14,
79 "id": "dd1d2883",
8180 "metadata": {},
8281 "outputs": [],
8382 "source": [
83 "@run_time\n",
8484 "def inference(model_PATH, img_p):\n",
8585 " G_Z = tf.placeholder(tf.float32, shape=[None, IMAGE_SZ, IMAGE_SZ, 4], name='G_Z')\n",
8686 " G_sample = src.model.generator(G_Z)\n",
9797 },
9898 {
9999 "cell_type": "code",
100 "execution_count": 12,
101 "id": "0ad73ad4",
100 "execution_count": 15,
101 "id": "a87b9ed1",
102102 "metadata": {},
103103 "outputs": [],
104104 "source": [
117117 " image_str = image_to_path(res)\n",
118118 " return {'Output': image_str}\n",
119119 " "
120 ]
121 },
122 {
123 "cell_type": "code",
124 "execution_count": 16,
125 "id": "afe3b627",
126 "metadata": {},
127 "outputs": [
128 {
129 "name": "stdout",
130 "output_type": "stream",
131 "text": [
132 "INFO:tensorflow:Restoring parameters from /home/jovyan/work/src/output/models/model2000.ckpt\n",
133 "Runned time: 0.317 s\n"
134 ]
135 },
136 {
137 "data": {
138 "text/plain": [
139 "{'Output': '/home/jovyan/work/results/test_output.png'}"
140 ]
141 },
142 "execution_count": 16,
143 "metadata": {},
144 "output_type": "execute_result"
145 }
146 ],
147 "source": [
148 "handle({'Photo': '/home/jovyan/work/images/test.png'})"
120149 ]
121150 }
122151 ],
88 import sys
99
1010 model_PATH='/home/jovyan/work/src/output/models/model2000.ckpt'
11 out_PATH='/home/jovyan/work/results/test_output.png'
1112 IMAGE_SZ = 128
13
14 import time
15 def run_time(func):
16 def inner(model_PATH, img_p):
17 back = func(model_PATH, img_p)
18 print("Runned time: {} s".format(round((time.time() - t)/10, 3)))
19 return back
20 t = time.time()
21 return inner
1222
1323 def load_demo_image(in_PATH):
1424 img = np.array(Image.open(in_PATH).convert('RGB'))[np.newaxis] / 255.0
1727
1828 def image_to_path(img):
1929 resize_img = img
20 path = uuid.uuid4().hex + '.png'
30 path = out_PATH
2131 resize_img.save(path)
2232 return path
2333
34 @run_time
2435 def inference(model_PATH, img_p):
2536 G_Z = tf.placeholder(tf.float32, shape=[None, IMAGE_SZ, IMAGE_SZ, 4], name='G_Z')
2637 G_sample = src.model.generator(G_Z)