|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "attachments": {}, |
| 5 | + "cell_type": "markdown", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "Generate" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "attachments": {}, |
| 13 | + "cell_type": "markdown", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "Reconstruction of a face from a single image ( Vertex / Redner / Mitsuba)" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "code", |
| 21 | + "execution_count": null, |
| 22 | + "metadata": {}, |
| 23 | + "outputs": [], |
| 24 | + "source": [ |
| 25 | + "! py -u ./optimizer.py --input input/test/s1.png --output output/test/mitsuba_blank_text" |
| 26 | + ] |
| 27 | + }, |
| 28 | + { |
| 29 | + "attachments": {}, |
| 30 | + "cell_type": "markdown", |
| 31 | + "metadata": {}, |
| 32 | + "source": [ |
| 33 | + "Batch reconstruction of a faces from a folder ( Vertex / Redner)" |
| 34 | + ] |
| 35 | + }, |
| 36 | + { |
| 37 | + "cell_type": "code", |
| 38 | + "execution_count": null, |
| 39 | + "metadata": {}, |
| 40 | + "outputs": [], |
| 41 | + "source": [ |
| 42 | + "! py ./optimizer.py --input input/test/ --output output/test/all_images/vertex_reg " |
| 43 | + ] |
| 44 | + }, |
| 45 | + { |
| 46 | + "attachments": {}, |
| 47 | + "cell_type": "markdown", |
| 48 | + "metadata": {}, |
| 49 | + "source": [ |
| 50 | + "Batch reconstruction of faces in loop (Mitsuba)" |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + "cell_type": "code", |
| 55 | + "execution_count": 1, |
| 56 | + "metadata": {}, |
| 57 | + "outputs": [ |
| 58 | + { |
| 59 | + "name": "stdout", |
| 60 | + "output_type": "stream", |
| 61 | + "text": [ |
| 62 | + "py ./optimizer.py --input input/test/s1.png --output output/test/mitsuba_rednermat_clip\n" |
| 63 | + ] |
| 64 | + } |
| 65 | + ], |
| 66 | + "source": [ |
| 67 | + "import os\n", |
| 68 | + "import subprocess\n", |
| 69 | + "# Directory path containing all images\n", |
| 70 | + "imageFolderPath = './input/test/'\n", |
| 71 | + "\n", |
| 72 | + "outputDir = './output/test/mitsuba_rednermat_clip'\n", |
| 73 | + "#setup\n", |
| 74 | + "if not os.path.exists(outputDir):\n", |
| 75 | + " os.makedirs(outputDir) # Create the output directory if it doesn't exist\n", |
| 76 | + "# Get the names of all files in the specified directory\n", |
| 77 | + "image_names = [f for f in os.listdir(imageFolderPath) if os.path.isfile(os.path.join(imageFolderPath, f))]\n", |
| 78 | + "\n", |
| 79 | + "# Filter only image files by extensions (if required)\n", |
| 80 | + "image_paths = [os.path.join(imageFolderPath, image_name) for image_name in image_names if image_name.endswith(('.png', '.jpg', '.jpeg'))]\n", |
| 81 | + "\n", |
| 82 | + "# Print the command for each image\n", |
| 83 | + "for image_path in image_paths:\n", |
| 84 | + " # Removing the './' from the image path\n", |
| 85 | + " image_path = image_path.replace('./', '')\n", |
| 86 | + " outputDir = outputDir.replace('./', '')\n", |
| 87 | + " command = f'py ./optimizer.py --input {image_path} --output {outputDir}'\n", |
| 88 | + " print(command)\n", |
| 89 | + " # Execute the command using os.system(command) if desired\n", |
| 90 | + " # os.system(command)\n", |
| 91 | + " result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)\n", |
| 92 | + " print(result.stdout.decode())\n", |
| 93 | + " " |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "code", |
| 98 | + "execution_count": 1, |
| 99 | + "metadata": {}, |
| 100 | + "outputs": [ |
| 101 | + { |
| 102 | + "name": "stdout", |
| 103 | + "output_type": "stream", |
| 104 | + "text": [ |
| 105 | + "^C\n" |
| 106 | + ] |
| 107 | + } |
| 108 | + ], |
| 109 | + "source": [ |
| 110 | + "! py ./optimizer.py --input input/test/s3.png --output output/test/mitsuba_rednermat_clip" |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "attachments": {}, |
| 115 | + "cell_type": "markdown", |
| 116 | + "metadata": {}, |
| 117 | + "source": [ |
| 118 | + "Display images" |
| 119 | + ] |
| 120 | + }, |
| 121 | + { |
| 122 | + "cell_type": "code", |
| 123 | + "execution_count": null, |
| 124 | + "metadata": {}, |
| 125 | + "outputs": [], |
| 126 | + "source": [ |
| 127 | + "from PIL import Image\n", |
| 128 | + "import matplotlib.pyplot as plt\n", |
| 129 | + "def display_images_in_folder(folder_path):\n", |
| 130 | + " # Iterate through the folder and subfolders\n", |
| 131 | + " for root, dirs, files in os.walk(folder_path):\n", |
| 132 | + " # Look for the file \"render0.png\" in the current directory\n", |
| 133 | + " if \"render_0.png\" in files:\n", |
| 134 | + " image_path = os.path.join(root, \"render_0.png\")\n", |
| 135 | + " # Open the image using PIL\n", |
| 136 | + " image = Image.open(image_path)\n", |
| 137 | + " # Display the image\n", |
| 138 | + " # Plot and display the image using Matplotlib\n", |
| 139 | + " plt.imshow(image)\n", |
| 140 | + " plt.axis('off') # Turn off axis\n", |
| 141 | + " plt.title(f\"Image from: {root}\")\n", |
| 142 | + " plt.show()\n", |
| 143 | + "\n", |
| 144 | + "# Path to the output directory\n", |
| 145 | + "output_folder_path = outputDir\n", |
| 146 | + "\n", |
| 147 | + "# Call the function to find and display the images\n", |
| 148 | + "display_images_in_folder(output_folder_path)\n" |
| 149 | + ] |
| 150 | + } |
| 151 | + ], |
| 152 | + "metadata": { |
| 153 | + "accelerator": "GPU", |
| 154 | + "colab": { |
| 155 | + "name": "demo.ipynb", |
| 156 | + "provenance": [] |
| 157 | + }, |
| 158 | + "kernelspec": { |
| 159 | + "display_name": "Python 3", |
| 160 | + "language": "python", |
| 161 | + "name": "python3" |
| 162 | + }, |
| 163 | + "language_info": { |
| 164 | + "codemirror_mode": { |
| 165 | + "name": "ipython", |
| 166 | + "version": 3 |
| 167 | + }, |
| 168 | + "file_extension": ".py", |
| 169 | + "mimetype": "text/x-python", |
| 170 | + "name": "python", |
| 171 | + "nbconvert_exporter": "python", |
| 172 | + "pygments_lexer": "ipython3", |
| 173 | + "version": "3.9.13" |
| 174 | + } |
| 175 | + }, |
| 176 | + "nbformat": 4, |
| 177 | + "nbformat_minor": 0 |
| 178 | +} |
0 commit comments