Skip to content

Commit 69709d3

Browse files
author
Abdallah DIB
committed
fixed bug in graident not reachign the camera position. new optim strategy for the second and third stage
1 parent b0b2ef4 commit 69709d3

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

optimConfig.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
device = 'cuda' #'cuda' or 'cpu'
33

44
#tracker
5-
lamdmarksDetectorType = 'mediapipe' # 'mediapipe' or 'fan (mediapipe is much more stable than fan)
5+
lamdmarksDetectorType = 'fan' # 'mediapipe' or 'fan (mediapipe is much more stable than fan)
66

77
#morphable model
88
path = './baselMorphableModel'

optimizer.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def setImage(self, imagePath, sharedIdentity = False):
133133
imagesLandmark = self.landmarksDetector.drawLandmarks(self.inputImage.tensor[i], self.landmarks[i])
134134
cv2.imwrite(self.outputDir + '/landmarks' + str(i) + '.png', cv2.cvtColor(imagesLandmark, cv2.COLOR_BGR2RGB) )
135135
self.pipeline.initSceneParameters(self.framesNumber, sharedIdentity)
136-
self.enableGrad()
137136
self.initCameraPos() #always init the head pose (rotation + translation)
137+
self.enableGrad()
138138

139139
def initCameraPos(self):
140140
print('init camera pose...', file=sys.stderr, flush=True)
@@ -224,15 +224,17 @@ def runStep2(self):
224224

225225
optimizer = torch.optim.Adam([
226226
{'params': self.pipeline.vShCoeffs, 'lr': 0.005},
227-
{'params': self.pipeline.vShapeCoeff, 'lr': 0.01},
228-
{'params': self.pipeline.vAlbedoCoeff, 'lr': 0.007},
229-
{'params': self.pipeline.vExpCoeff, 'lr': 0.01},
230-
{'params': self.pipeline.vRotation, 'lr': 0.001},
231-
{'params': self.pipeline.vTranslation, 'lr': 0.001}
227+
{'params': self.pipeline.vAlbedoCoeff, 'lr': 0.007}
232228
])
233229
losses = []
234230

235231
for iter in tqdm.tqdm(range(self.config.iterStep2 + 1)):
232+
if iter == 100:
233+
optimizer.add_param_group({'params': self.pipeline.vShapeCoeff, 'lr': 0.01})
234+
optimizer.add_param_group({'params': self.pipeline.vExpCoeff, 'lr': 0.01})
235+
optimizer.add_param_group({'params': self.pipeline.vRotation, 'lr': 0.0001})
236+
optimizer.add_param_group({'params': self.pipeline.vTranslation, 'lr': 0.0001})
237+
236238
optimizer.zero_grad()
237239
vertices, diffAlbedo, specAlbedo = self.pipeline.morphableModel.computeShapeAlbedo(self.pipeline.vShapeCoeff, self.pipeline.vExpCoeff, self.pipeline.vAlbedoCoeff)
238240
cameraVerts = self.pipeline.camera.transformVertices(vertices, self.pipeline.vTranslation, self.pipeline.vRotation)
@@ -288,15 +290,17 @@ def runStep3(self):
288290
vRoughTextures.requires_grad = True
289291

290292
optimizer = torch.optim.Adam([
291-
{'params': self.pipeline.vShCoeffs, 'lr': 0.005 * 2.},
292-
{'params': vDiffTextures, 'lr': 0.005 },
293+
{'params': vDiffTextures, 'lr': 0.005},
293294
{'params': vSpecTextures, 'lr': 0.02},
294-
{'params': vRoughTextures, 'lr': 0.02},
295-
{'params': self.pipeline.vShapeCoeff, 'lr': 0.01},
296-
{'params': self.pipeline.vExpCoeff, 'lr': 0.01},
297-
{'params': self.pipeline.vRotation, 'lr': 0.0005},
298-
{'params': self.pipeline.vTranslation, 'lr': 0.0005}
295+
{'params': vRoughTextures, 'lr': 0.02}
299296
])
297+
''''
298+
{'params': self.pipeline.vShCoeffs, 'lr': 0.005 * 2.},
299+
{'params': self.pipeline.vShapeCoeff, 'lr': 0.01},
300+
{'params': self.pipeline.vExpCoeff, 'lr': 0.01},
301+
{'params': self.pipeline.vRotation, 'lr': 0.0005},
302+
{'params': self.pipeline.vTranslation, 'lr': 0.0005}'''
303+
300304
losses = []
301305

302306
for iter in tqdm.tqdm(range(self.config.iterStep3 + 1)):

0 commit comments

Comments
 (0)