TimoBolkart / TF_FLAME

Tensorflow framework for the FLAME 3D head model. The code demonstrates how to sample 3D heads from the model, fit the model to 2D or 3D keypoints, and how to generate textured head meshes from Images.
http://flame.is.tue.mpg.de/
444 stars 77 forks source link

fit_2d_landmarks.py Pyglet error #17

Closed plmsmile closed 4 years ago

plmsmile commented 4 years ago

Thanks the great work share~ I am trying the demo, run the following command on my Mac.

img_name="imgHQ00088.jpeg"
python fit_2D_landmarks.py \
    --tf_model_fname './models/generic_model' \
    --template_fname './data/template.ply' \
    --flame_lmk_path './data/flame_static_embedding.pkl'\
    --texture_mapping './data/texture_data.npy' \
    --target_img_path "./data/${img_name}" \
    --target_lmk_path './data/imgHQ00088_lmks.npy' \
    --out_path './results'

However, it always have a problem after some minutes. And I have tried other image and other versions of pyrender, pyglet. Sadly, the error always is there. I hope maybe you can give me some advice. Thank you very much~~

lmk_dist: 0.015134, shape_reg: 0.004308, exp_reg: 0.002860, neck_pose_reg: 0.000000, jaw_pose_reg: 0.000016, eyeballs_pose_reg: 0.000000
lmk_dist: 0.015124, shape_reg: 0.004314, exp_reg: 0.002863, neck_pose_reg: 0.000000, jaw_pose_reg: 0.000016, eyeballs_pose_reg: 0.000000
lmk_dist: 0.015116, shape_reg: 0.004319, exp_reg: 0.002866, neck_pose_reg: 0.000000, jaw_pose_reg: 0.000016, eyeballs_pose_reg: 0.000000
lmk_dist: 0.015107, shape_reg: 0.004325, exp_reg: 0.002869, neck_pose_reg: 0.000000, jaw_pose_reg: 0.000016, eyeballs_pose_reg: 0.000000
Traceback (most recent call last):
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/pyrender/platforms/pyglet_platform.py", line 32, in init_context
    width=1, height=1)
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/pyglet/window/__init__.py", line 632, in __init__
    self._create()
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/pyglet/window/cocoa/__init__.py", line 194, in _create
    self.context.attach(self.canvas)
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/pyglet/gl/cocoa.py", line 291, in attach
    self._nscontext.setView_(canvas.nsview)
AttributeError: 'NoneType' object has no attribute 'setView_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "fit_2D_landmarks.py", line 215, in <module>
    run_2d_lmk_fitting(args.tf_model_fname, args.template_fname, args.flame_lmk_path, args.texture_mapping, args.target_img_path, args.target_lmk_path, args.out_path)
File "fit_2D_landmarks.py", line 171, in run_2d_lmk_fitting
    result_mesh, result_scale = fit_lmk2d(target_img, lmk_2d, template_fname, tf_model_fname, lmk_face_idx, lmk_b_coords, weights)
  File "fit_2D_landmarks.py", line 126, in fit_lmk2d
    lmk_dist, shape_reg, exp_reg, neck_pose_reg, jaw_pose_reg, eyeballs_pose_reg], loss_callback=on_step)
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/tensorflow/contrib/opt/python/training/external_optimizer.py", line 207, in minimize
    optimizer_kwargs=self.optimizer_kwargs)
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/tensorflow/contrib/opt/python/training/external_optimizer.py", line 402, in _minimize
    result = scipy.optimize.minimize(*minimize_args, **minimize_kwargs)
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/scipy/optimize/_minimize.py", line 610, in minimize
    callback=callback, **options)
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/scipy/optimize/lbfgsb.py", line 345, in _minimize_lbfgsb
    f, g = func_and_grad(x)
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/scipy/optimize/lbfgsb.py", line 295, in func_and_grad
    f = fun(x, *args)
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/scipy/optimize/optimize.py", line 327, in function_wrapper
    return function(*(wrapper_args + args))
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/scipy/optimize/optimize.py", line 65, in __call__
    fg = self.fun(x, *args)
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/tensorflow/contrib/opt/python/training/external_optimizer.py", line 367, in loss_grad_func_wrapper
    loss, gradient = loss_grad_func(x)
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/tensorflow/contrib/opt/python/training/external_optimizer.py", line 281, in eval_func
    callback(*augmented_fetch_vals[num_tensors:])
  File "fit_2D_landmarks.py", line 106, in on_step
    rendered_img = render_mesh(Mesh(scale*verts, faces), height=target_img.shape[0], width=target_img.shape[1])
  File "/Users/plm/pro/TF_FLAME/utils/render_mesh.py", line 30, in render_mesh
    r = pyrender.OffscreenRenderer(viewport_width=width, viewport_height=height)
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/pyrender/offscreen.py", line 31, in __init__
    self._create()
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/pyrender/offscreen.py", line 134, in _create
    self._platform.init_context()
  File "/Users/plm/app/anaconda3/envs/flame/lib/python3.6/site-packages/pyrender/platforms/pyglet_platform.py", line 38, in init_context
    'internal error message was "{}"'.format(e)
ValueError: Failed to initialize Pyglet window with an OpenGL >= 3+ context. If you're logged in via SSH, ensure that you're running your script with vglrun (i.e. VirtualGL). The internal error message was "'NoneType' object has no attribute 'setView_'"
OmarWagih1 commented 4 years ago

did you figure this out? having the same problem

TimoBolkart commented 4 years ago

@plmsmile and @OmarWagih1 thanks for pointing this out. It seems the rendering fails for certain configurations. However the visualization is not essential for the fitting even though it helps finding better parameter configurations. As a workaround, please pull the newest version of the code and run the demo with a flag --visualize False, this will disable the visualization.