{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "ea42a489",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"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",
"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"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"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",
"Instructions for updating:\n",
"non-resource variables are not supported in the long term\n",
"Imported model (for Places365, 128x128 images)\n"
]
}
],
"source": [
"import tensorflow.compat.v1 as tf\n",
"tf.disable_v2_behavior()\n",
"tf.reset_default_graph()\n",
"import numpy as np\n",
"from PIL import Image\n",
"import model\n",
"import util\n",
"import os\n",
"import sys"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "24a28be9",
"metadata": {},
"outputs": [],
"source": [
"model_PATH='/home/jovyan/work/src/output/models/model2000.ckpt'"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "2f04ed3d",
"metadata": {},
"outputs": [],
"source": [
"def load_demo_image(in_PATH):\n",
" img = np.array(Image.open(in_PATH).convert('RGB'))[np.newaxis] / 255.0\n",
" img_p = util.preprocess_images_outpainting(img)\n",
" return img_p"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4cc717e4",
"metadata": {},
"outputs": [],
"source": [
"def inference(model_PATH, img_p):\n",
" G_Z = tf.placeholder(tf.float32, shape=[None, IMAGE_SZ, IMAGE_SZ, 4], name='G_Z')\n",
" G_sample = model.generator(G_Z)\n",
" \n",
" saver = tf.train.Saver()\n",
" with tf.Session() as sess:\n",
" saver.restore(sess, model_PATH)\n",
" output, = sess.run([G_sample], feed_dict={G_Z: img_p})\n",
" img_norm = (output[0] * 255.0).astype(np.uint8)\n",
" img = Image.fromarray(img_norm, 'RGB')\n",
" #util.save_image(output[0], out_PATH)\n",
" return img"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9ce2fc25",
"metadata": {},
"outputs": [],
"source": [
"def handle(conf):\n",
" \"\"\"\n",
" 该方法是部署之后,其他人调用你的服务时候的处理方法。\n",
" 请按规范填写参数结构,这样我们就能替你自动生成配置文件,方便其他人的调用。\n",
" 范例:\n",
" params['key'] = value # value_type: str # description: some description\n",
" value_type 可以选择:img, video, audio, str, int, float, [int], [str], [float]\n",
" 参数请放到params字典中,我们会自动解析该变量。\n",
" \"\"\"\n",
" base64_str = conf['Photo']\n",
" image = load_demo_image(base64_str, image_size, device)\n",
" res = inference(model, image)\n",
" # add your code\n",
" return {'Output': res}\n",
" "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}