Skip to content

Commit c37a688

Browse files
committed
Implement new renderers and utilitary methods
1 parent cd279b5 commit c37a688

25 files changed

+1475
-416
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.h5 filter=lfs diff=lfs merge=lfs -text

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.vscode/settings.json
2+
__pycache__/*
3+
output/*
4+
input/*
5+
baselMorphableModel/*
6+
faceNext/*
7+
drjit/*
8+
mitsuba/*
9+
*.pyc
10+
ext/*
11+
chi2_data.py

INSTALL

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ pip install redner-gpu
55
conda install -c conda-forge opencv
66
conda install -c 1adrianb face_alignment=1.2.0
77
conda install -c anaconda h5py
8-
pip install mediapipe
8+
pip install mediapipe
9+
pip install mitsuba

README.md

Lines changed: 83 additions & 44 deletions
Large diffs are not rendered by default.

commands_demo.ipynb

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
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+
}

config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self):
1212

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

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

5353
self.debugFrequency = 10 #display frequency during optimization
54+
self.debugOutput = False # generate outputs at each debugFrequency
5455
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
56+
self.saveTime = False # if True will save the time taken in the txt
5557
self.verbose = False #display loss on terminal if true
5658

5759
self.rtSamples = 500 #the number of ray tracer samples to render the final output
5860
self.rtTrainingSamples = 8 # number of ray tracing to use during training
61+
self.bounces = 2 # number of bounces
62+
self.smoothing = True #should we smooth the face when doing diff
63+
self.rendererName = 'redner' #default renderer name
5964
def fillFromDicFile(self, filePath):
6065
'''
6166
overwrite default config

0 commit comments

Comments
 (0)