Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new renderers and utilitary methods #64

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.h5 filter=lfs diff=lfs merge=lfs -text
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.vscode/settings.json
__pycache__/*
output/*
input/*
baselMorphableModel/*
faceNext/*
drjit/*
mitsuba/*
*.pyc
ext/*
chi2_data.py
6 changes: 6 additions & 0 deletions .polyscope.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"windowHeight": 845,
"windowPosX": 531,
"windowPosY": 130,
"windowWidth": 1122
}
3 changes: 2 additions & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pip install redner-gpu
conda install -c conda-forge opencv
conda install -c 1adrianb face_alignment=1.2.0
conda install -c anaconda h5py
pip install mediapipe
pip install mediapipe
pip install mitsuba
10 changes: 10 additions & 0 deletions NextFace.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"git.ignoreLimitWarning": true
}
}
127 changes: 83 additions & 44 deletions README.md

Large diffs are not rendered by default.

178 changes: 178 additions & 0 deletions commands_demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Generate"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Reconstruction of a face from a single image ( Vertex / Redner / Mitsuba)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"! py -u ./optimizer.py --input input/test/s1.png --output output/test/mitsuba_blank_text"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Batch reconstruction of a faces from a folder ( Vertex / Redner)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"! py ./optimizer.py --input input/test/ --output output/test/all_images/vertex_reg "
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Batch reconstruction of faces in loop (Mitsuba)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"py ./optimizer.py --input input/test/s1.png --output output/test/mitsuba_rednermat_clip\n"
]
}
],
"source": [
"import os\n",
"import subprocess\n",
"# Directory path containing all images\n",
"imageFolderPath = './input/test/'\n",
"\n",
"outputDir = './output/test/mitsuba_rednermat_clip'\n",
"#setup\n",
"if not os.path.exists(outputDir):\n",
" os.makedirs(outputDir) # Create the output directory if it doesn't exist\n",
"# Get the names of all files in the specified directory\n",
"image_names = [f for f in os.listdir(imageFolderPath) if os.path.isfile(os.path.join(imageFolderPath, f))]\n",
"\n",
"# Filter only image files by extensions (if required)\n",
"image_paths = [os.path.join(imageFolderPath, image_name) for image_name in image_names if image_name.endswith(('.png', '.jpg', '.jpeg'))]\n",
"\n",
"# Print the command for each image\n",
"for image_path in image_paths:\n",
" # Removing the './' from the image path\n",
" image_path = image_path.replace('./', '')\n",
" outputDir = outputDir.replace('./', '')\n",
" command = f'py ./optimizer.py --input {image_path} --output {outputDir}'\n",
" print(command)\n",
" # Execute the command using os.system(command) if desired\n",
" # os.system(command)\n",
" result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)\n",
" print(result.stdout.decode())\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"^C\n"
]
}
],
"source": [
"! py ./optimizer.py --input input/test/s3.png --output output/test/mitsuba_rednermat_clip"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Display images"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from PIL import Image\n",
"import matplotlib.pyplot as plt\n",
"def display_images_in_folder(folder_path):\n",
" # Iterate through the folder and subfolders\n",
" for root, dirs, files in os.walk(folder_path):\n",
" # Look for the file \"render0.png\" in the current directory\n",
" if \"render_0.png\" in files:\n",
" image_path = os.path.join(root, \"render_0.png\")\n",
" # Open the image using PIL\n",
" image = Image.open(image_path)\n",
" # Display the image\n",
" # Plot and display the image using Matplotlib\n",
" plt.imshow(image)\n",
" plt.axis('off') # Turn off axis\n",
" plt.title(f\"Image from: {root}\")\n",
" plt.show()\n",
"\n",
"# Path to the output directory\n",
"output_folder_path = outputDir\n",
"\n",
"# Call the function to find and display the images\n",
"display_images_in_folder(output_folder_path)\n"
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"name": "demo.ipynb",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"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.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
7 changes: 6 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self):

#morphable model
self.path = 'baselMorphableModel'
self.textureResolution = 256 #256 or 512
self.textureResolution = 512 #256 or 512
self.trimPca = False # if True keep only a subset of the pca basis (eigen vectors)

#spherical harmonics
Expand Down Expand Up @@ -51,11 +51,16 @@ def __init__(self):
self.weightRoughnessSmoothnessReg = 0.002 # smoothness regularizer weight for roughness texture (at step 3)

self.debugFrequency = 10 #display frequency during optimization
self.debugOutput = False # generate outputs at each debugFrequency
self.saveIntermediateStage = False #if True the output of stage 1 and 2 are saved. stage 3 is always saved which is the output of the optim
self.saveTime = False # if True will save the time taken in the txt
self.verbose = False #display loss on terminal if true

self.rtSamples = 500 #the number of ray tracer samples to render the final output
self.rtTrainingSamples = 8 # number of ray tracing to use during training
self.bounces = 2 # number of bounces
self.smoothing = True #should we smooth the face when doing diff
self.rendererName = 'redner' #default renderer name
def fillFromDicFile(self, filePath):
'''
overwrite default config
Expand Down
2 changes: 2 additions & 0 deletions customRenderer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""This package includes a miscellaneous collection of useful helper functions."""
from customRenderer import *
Loading