| 1 | 1 |
"cells": [
|
| 2 | 2 |
{
|
| 3 | 3 |
"cell_type": "code",
|
| 4 | |
"execution_count": 3,
|
| 5 | |
"id": "34f17c80",
|
|
4 |
"execution_count": 9,
|
|
5 |
"id": "4695fed2",
|
| 6 | 6 |
"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": [],
|
| 27 | 8 |
"source": [
|
| 28 | 9 |
"import tensorflow.compat.v1 as tf\n",
|
| 29 | 10 |
"tf.disable_v2_behavior()\n",
|
|
| 38 | 19 |
},
|
| 39 | 20 |
{
|
| 40 | 21 |
"cell_type": "code",
|
| 41 | |
"execution_count": 4,
|
| 42 | |
"id": "8335c665",
|
|
22 |
"execution_count": 10,
|
|
23 |
"id": "5a4f0882",
|
| 43 | 24 |
"metadata": {},
|
| 44 | 25 |
"outputs": [],
|
| 45 | 26 |
"source": [
|
| 46 | 27 |
"model_PATH='/home/jovyan/work/src/output/models/model2000.ckpt'\n",
|
|
28 |
"out_PATH='/home/jovyan/work/results/test_output.png'\n",
|
| 47 | 29 |
"IMAGE_SZ = 128"
|
| 48 | 30 |
]
|
| 49 | 31 |
},
|
| 50 | 32 |
{
|
| 51 | 33 |
"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",
|
| 54 | 53 |
"metadata": {},
|
| 55 | 54 |
"outputs": [],
|
| 56 | 55 |
"source": [
|
|
| 62 | 61 |
},
|
| 63 | 62 |
{
|
| 64 | 63 |
"cell_type": "code",
|
| 65 | |
"execution_count": 11,
|
| 66 | |
"id": "a9d338ee",
|
|
64 |
"execution_count": 13,
|
|
65 |
"id": "eee977d9",
|
| 67 | 66 |
"metadata": {},
|
| 68 | 67 |
"outputs": [],
|
| 69 | 68 |
"source": [
|
| 70 | 69 |
"def image_to_path(img):\n",
|
| 71 | 70 |
" resize_img = img\n",
|
| 72 | |
" path = uuid.uuid4().hex + '.png'\n",
|
|
71 |
" path = out_PATH\n",
|
| 73 | 72 |
" resize_img.save(path)\n",
|
| 74 | 73 |
" return path"
|
| 75 | 74 |
]
|
| 76 | 75 |
},
|
| 77 | 76 |
{
|
| 78 | 77 |
"cell_type": "code",
|
| 79 | |
"execution_count": 6,
|
| 80 | |
"id": "254b5ac4",
|
|
78 |
"execution_count": 14,
|
|
79 |
"id": "dd1d2883",
|
| 81 | 80 |
"metadata": {},
|
| 82 | 81 |
"outputs": [],
|
| 83 | 82 |
"source": [
|
|
83 |
"@run_time\n",
|
| 84 | 84 |
"def inference(model_PATH, img_p):\n",
|
| 85 | 85 |
" G_Z = tf.placeholder(tf.float32, shape=[None, IMAGE_SZ, IMAGE_SZ, 4], name='G_Z')\n",
|
| 86 | 86 |
" G_sample = src.model.generator(G_Z)\n",
|
|
| 97 | 97 |
},
|
| 98 | 98 |
{
|
| 99 | 99 |
"cell_type": "code",
|
| 100 | |
"execution_count": 12,
|
| 101 | |
"id": "0ad73ad4",
|
|
100 |
"execution_count": 15,
|
|
101 |
"id": "a87b9ed1",
|
| 102 | 102 |
"metadata": {},
|
| 103 | 103 |
"outputs": [],
|
| 104 | 104 |
"source": [
|
|
| 117 | 117 |
" image_str = image_to_path(res)\n",
|
| 118 | 118 |
" return {'Output': image_str}\n",
|
| 119 | 119 |
" "
|
|
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'})"
|
| 120 | 149 |
]
|
| 121 | 150 |
}
|
| 122 | 151 |
],
|