File size: 8,582 Bytes
61cdcf9
 
 
 
f7f7d9b
61cdcf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7f7d9b
61cdcf9
 
 
 
 
 
 
f7f7d9b
61cdcf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f1946e
 
 
 
 
 
 
 
 
 
 
61cdcf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f1946e
f7f7d9b
61cdcf9
0f1946e
2add774
 
0f1946e
61cdcf9
 
 
 
 
 
 
 
0f1946e
61cdcf9
0f1946e
61cdcf9
 
 
 
 
 
 
f7f7d9b
61cdcf9
 
2add774
61cdcf9
 
 
 
 
 
 
 
 
 
0f1946e
61cdcf9
0f1946e
61cdcf9
 
 
 
 
 
 
f7f7d9b
61cdcf9
 
2add774
61cdcf9
 
 
 
 
 
 
 
 
 
0f1946e
61cdcf9
0f1946e
61cdcf9
 
 
 
 
 
 
 
 
2add774
 
 
 
 
 
61cdcf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": 2.8891853944186117e+38,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 616
    },
    "id": 2.8891853944186117e+38,
    "outputId": "b60a6d5e-045d-4b40-bfd8-6caa407a34df",
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running on local URL:  http://127.0.0.1:7860\n",
      "\n",
      "To create a public link, set `share=True` in `launch()`.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import gradio as gr\n",
    "import os\n",
    "from PIL import Image\n",
    "from functools import partial\n",
    "\n",
    "def retrieve_input_image_wild(dataset, inputs):\n",
    "    img_id = inputs\n",
    "    img_path = os.path.join('online_demo', dataset, 'step-100_scale-6.0')\n",
    "    try:\n",
    "        image = Image.open(os.path.join(img_path, '%s.jpg' % img_id))\n",
    "    except:\n",
    "        image = Image.open(os.path.join(img_path, '%s.png' % img_id))\n",
    "        \n",
    "    image.thumbnail([256, 256], Image.Resampling.LANCZOS) \n",
    "    return image\n",
    "\n",
    "def retrieve_input_image(dataset, inputs):\n",
    "    img_id = inputs\n",
    "    img_path = os.path.join('online_demo', dataset, 'step-100_scale-6.0', img_id, 'input.png')\n",
    "    image = Image.open(img_path)\n",
    "    return image\n",
    "\n",
    "def retrieve_novel_view(dataset, img_id, polar, azimuth, zoom, seed):\n",
    "    polar = polar // 30 + 1\n",
    "    azimuth = azimuth // 30\n",
    "    zoom = int(zoom * 2 + 1)\n",
    "    img_path = os.path.join('online_demo', dataset, 'step-100_scale-6.0', img_id,\\\n",
    "                            'polar-%d_azimuth-%d_distance-%d_seed-%d.png' % (polar, azimuth, zoom, seed))\n",
    "    image = Image.open(img_path)\n",
    "    return image\n",
    "    \n",
    "\n",
    "with gr.Blocks() as demo:\n",
    "    gr.Markdown(\"Flip text or image files using this demo.\")\n",
    "    with gr.Tab(\"In-the-wild Images\"):\n",
    "        with gr.Row():\n",
    "            with gr.Column(scale=1):\n",
    "                default_input_image = Image.open( os.path.join('online_demo', 'nerf_wild', 'step-100_scale-6.0', 'car1.png'))\n",
    "                default_input_image.thumbnail([256, 256], Image.Resampling.LANCZOS) \n",
    "                input_image = gr.Image(default_input_image, shape=[256, 256])\n",
    "                options = sorted(next(os.walk('online_demo/nerf_wild/step-100_scale-6.0'))[1])\n",
    "                img_id = gr.Dropdown(options, value='car1', label='options')\n",
    "                text_button = gr.Button(\"Load Input Image\")\n",
    "                retrieve_input_image_dataset = partial(retrieve_input_image_wild, 'nerf_wild')\n",
    "                text_button.click(retrieve_input_image_dataset, inputs=img_id, outputs=input_image)\n",
    "\n",
    "            with gr.Column(scale=1):\n",
    "                novel_view = gr.Image(shape=[256, 256])\n",
    "                inputs = [img_id,\n",
    "                gr.Slider(-30, 30, value=0, step=30, label='Polar angle (vertical rotation in degrees)'),\n",
    "                gr.Slider(0, 330, value=0, step=30, label='Azimuth angle (horizontal rotation in degrees)'),\n",
    "                gr.Slider(-0.5, 0.5, value=0, step=0.5, label='Zoom'),\n",
    "                gr.Slider(0, 3, value=1, step=1, label='Random seed')]\n",
    "                \n",
    "                submit_button = gr.Button(\"Generate Novel View\")\n",
    "                retrieve_novel_view_dataset = partial(retrieve_novel_view, 'nerf_wild')\n",
    "                submit_button.click(retrieve_novel_view_dataset, inputs=inputs, outputs=novel_view)\n",
    "        \n",
    "    with gr.Tab(\"Google Scanned Objects\"):\n",
    "        with gr.Row():\n",
    "            with gr.Column(scale=1):\n",
    "                default_input_image = Image.open( os.path.join('online_demo', 'GSO', 'step-100_scale-6.0', 'SAMBA_HEMP', 'input.png'))\n",
    "                default_input_image.thumbnail([256, 256], Image.Resampling.LANCZOS) \n",
    "                input_image = gr.Image(default_input_image, shape=[256, 256])\n",
    "                options = sorted(os.listdir('online_demo/GSO/step-100_scale-6.0'))\n",
    "                img_id = gr.Dropdown(options, value='SAMBA_HEMP', label='options')\n",
    "                text_button = gr.Button(\"Choose Input Image\")\n",
    "                retrieve_input_image_dataset = partial(retrieve_input_image, 'GSO')\n",
    "                text_button.click(retrieve_input_image_dataset, inputs=img_id, outputs=input_image)\n",
    "\n",
    "            with gr.Column(scale=1):\n",
    "                novel_view = gr.Image(shape=[256, 256])\n",
    "                inputs = [img_id,\n",
    "                gr.Slider(-30, 30, value=0, step=30, label='Polar angle (vertical rotation in degrees)'),\n",
    "                gr.Slider(0, 330, value=0, step=30, label='Azimuth angle (horizontal rotation in degrees)'),\n",
    "                gr.Slider(-0.5, 0.5, value=0, step=0.5, label='Zoom'),\n",
    "                gr.Slider(0, 3, value=1, step=1, label='Random seed')]\n",
    "                \n",
    "                submit_button = gr.Button(\"Generate Novel View\")\n",
    "                retrieve_novel_view_dataset = partial(retrieve_novel_view, 'GSO')\n",
    "                submit_button.click(retrieve_novel_view_dataset, inputs=inputs, outputs=novel_view)\n",
    "        \n",
    "    with gr.Tab(\"RTMV\"):\n",
    "        with gr.Row():\n",
    "            with gr.Column(scale=1):\n",
    "                default_input_image = Image.open( os.path.join('online_demo', 'RTMV', 'step-100_scale-6.0', '00000', 'input.png'))\n",
    "                default_input_image.thumbnail([256, 256], Image.Resampling.LANCZOS) \n",
    "                input_image = gr.Image(default_input_image, shape=[256, 256])\n",
    "                options = sorted(os.listdir('online_demo/RTMV/step-100_scale-6.0'))\n",
    "                img_id = gr.Dropdown(options, value='00000', label='options')\n",
    "                text_button = gr.Button(\"Choose Input Image\")\n",
    "                retrieve_input_image_dataset = partial(retrieve_input_image, 'RTMV')\n",
    "                text_button.click(retrieve_input_image_dataset, inputs=img_id, outputs=input_image)\n",
    "\n",
    "            with gr.Column(scale=1):\n",
    "                novel_view = gr.Image(shape=[256, 256])\n",
    "                inputs = [img_id,\n",
    "                gr.Slider(-30, 30, value=0, step=30, label='Polar angle (vertical rotation in degrees)'),\n",
    "                gr.Slider(0, 330, value=0, step=30, label='Azimuth angle (horizontal rotation in degrees)'),\n",
    "                gr.Slider(-0.5, 0.5, value=0, step=0.5, label='Zoom'),\n",
    "                gr.Slider(0, 3, value=1, step=1, label='Random seed')]\n",
    "                \n",
    "                submit_button = gr.Button(\"Generate Novel View\")\n",
    "                retrieve_novel_view_dataset = partial(retrieve_novel_view, 'RTMV')\n",
    "                submit_button.click(retrieve_novel_view_dataset, inputs=inputs, outputs=novel_view)\n",
    "    \n",
    "    \n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    demo.launch()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2febec07",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "gpuClass": "standard",
  "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.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}