{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "062014f7", "metadata": { "id": "breeding-extra" }, "outputs": [], "source": [ "import torch\n", "MODEL_NAME = \"standard_float\"\n", "DEVICE_NAME = 'cuda'\n", "device = torch.device(DEVICE_NAME)\n", "\n", "def load_poser(model: str, device: torch.device):\n", " print(\"Using the %s model.\" % model)\n", " if model == \"standard_float\":\n", " from tha3.poser.modes.standard_float import create_poser\n", " return create_poser(device)\n", " elif model == \"standard_half\":\n", " from tha3.poser.modes.standard_half import create_poser\n", " return create_poser(device)\n", " elif model == \"separable_float\":\n", " from tha3.poser.modes.separable_float import create_poser\n", " return create_poser(device)\n", " elif model == \"separable_half\":\n", " from tha3.poser.modes.separable_half import create_poser\n", " return create_poser(device)\n", " else:\n", " raise RuntimeError(\"Invalid model: '%s'\" % model)\n", " \n", "poser = load_poser(MODEL_NAME, DEVICE_NAME)\n", "poser.get_modules();" ] }, { "cell_type": "code", "execution_count": null, "id": "breeding-extra", "metadata": { "id": "breeding-extra" }, "outputs": [], "source": [ "import PIL.Image\n", "import io\n", "from io import StringIO, BytesIO\n", "import IPython.display\n", "import numpy\n", "import ipywidgets\n", "import time\n", "import threading\n", "import torch\n", "from tha3.util import resize_PIL_image, extract_PIL_image_from_filelike, \\\n", " extract_pytorch_image_from_PIL_image, convert_output_image_from_torch_to_numpy\n", "\n", "FRAME_RATE = 30.0\n", "\n", "last_torch_input_image = None\n", "torch_input_image = None\n", "\n", "def show_pytorch_image(pytorch_image):\n", " output_image = pytorch_image.detach().cpu()\n", " numpy_image = numpy.uint8(numpy.rint(convert_output_image_from_torch_to_numpy(output_image) * 255.0))\n", " pil_image = PIL.Image.fromarray(numpy_image, mode='RGBA')\n", " IPython.display.display(pil_image)\n", "\n", "upload_input_image_button = ipywidgets.FileUpload(\n", " accept='.png',\n", " multiple=False,\n", " layout={\n", " 'width': '512px'\n", " }\n", ")\n", "\n", "output_image_widget = ipywidgets.Output(\n", " layout={\n", " 'border': '1px solid black',\n", " 'width': '512px',\n", " 'height': '512px'\n", " }\n", ")\n", "\n", "eyebrow_dropdown = ipywidgets.Dropdown(\n", " options=[\"troubled\", \"angry\", \"lowered\", \"raised\", \"happy\", \"serious\"],\n", " value=\"troubled\",\n", " description=\"Eyebrow:\", \n", ")\n", "eyebrow_left_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=0.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Left:\",\n", " readout=True,\n", " readout_format=\".2f\"\n", ")\n", "eyebrow_right_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=0.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Right:\",\n", " readout=True,\n", " readout_format=\".2f\"\n", ")\n", "\n", "eye_dropdown = ipywidgets.Dropdown(\n", " options=[\"wink\", \"happy_wink\", \"surprised\", \"relaxed\", \"unimpressed\", \"raised_lower_eyelid\"],\n", " value=\"wink\",\n", " description=\"Eye:\", \n", ")\n", "eye_left_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=0.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Left:\",\n", " readout=True,\n", " readout_format=\".2f\"\n", ")\n", "eye_right_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=0.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Right:\",\n", " readout=True,\n", " readout_format=\".2f\"\n", ")\n", "\n", "mouth_dropdown = ipywidgets.Dropdown(\n", " options=[\"aaa\", \"iii\", \"uuu\", \"eee\", \"ooo\", \"delta\", \"lowered_corner\", \"raised_corner\", \"smirk\"],\n", " value=\"aaa\",\n", " description=\"Mouth:\", \n", ")\n", "mouth_left_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=0.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Value:\",\n", " readout=True,\n", " readout_format=\".2f\"\n", ")\n", "mouth_right_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=0.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\" \",\n", " readout=True,\n", " readout_format=\".2f\",\n", " disabled=True,\n", ")\n", "\n", "def update_mouth_sliders(change):\n", " if mouth_dropdown.value == \"lowered_corner\" or mouth_dropdown.value == \"raised_corner\":\n", " mouth_left_slider.description = \"Left:\"\n", " mouth_right_slider.description = \"Right:\"\n", " mouth_right_slider.disabled = False\n", " else:\n", " mouth_left_slider.description = \"Value:\"\n", " mouth_right_slider.description = \" \"\n", " mouth_right_slider.disabled = True\n", "\n", "mouth_dropdown.observe(update_mouth_sliders, names='value')\n", "\n", "iris_small_left_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=0.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Left:\",\n", " readout=True,\n", " readout_format=\".2f\"\n", ")\n", "iris_small_right_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=0.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Right:\",\n", " readout=True,\n", " readout_format=\".2f\", \n", ")\n", "iris_rotation_x_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=-1.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"X-axis:\",\n", " readout=True,\n", " readout_format=\".2f\"\n", ")\n", "iris_rotation_y_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=-1.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Y-axis:\",\n", " readout=True,\n", " readout_format=\".2f\", \n", ")\n", "\n", "head_x_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=-1.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"X-axis:\",\n", " readout=True,\n", " readout_format=\".2f\"\n", ")\n", "head_y_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=-1.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Y-axis:\",\n", " readout=True,\n", " readout_format=\".2f\", \n", ")\n", "neck_z_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=-1.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Z-axis:\",\n", " readout=True,\n", " readout_format=\".2f\", \n", ")\n", "body_y_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=-1.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Y-axis rotation:\",\n", " readout=True,\n", " readout_format=\".2f\", \n", ")\n", "body_z_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=-1.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Z-axis rotation:\",\n", " readout=True,\n", " readout_format=\".2f\", \n", ")\n", "breathing_slider = ipywidgets.FloatSlider(\n", " value=0.0,\n", " min=0.0,\n", " max=1.0,\n", " step=0.01,\n", " description=\"Breathing:\",\n", " readout=True,\n", " readout_format=\".2f\", \n", ")\n", "\n", "\n", "control_panel = ipywidgets.VBox([\n", " eyebrow_dropdown,\n", " eyebrow_left_slider,\n", " eyebrow_right_slider,\n", " ipywidgets.HTML(value=\"