Disabled mesh_renderer as dependency when running Windows.
This commit is contained in:
Родитель
4b27ddf422
Коммит
9698245751
9
demo.py
9
demo.py
|
@ -1,15 +1,15 @@
|
|||
import tensorflow as tf
|
||||
import numpy as np
|
||||
import cv2
|
||||
from PIL import Image
|
||||
import os
|
||||
import glob
|
||||
import os, glob, cv2, platform
|
||||
from scipy.io import loadmat,savemat
|
||||
|
||||
from preprocess_img import Preprocess
|
||||
from load_data import *
|
||||
from face_decoder import Face3D
|
||||
|
||||
is_windows = platform.system() == "Windows"
|
||||
|
||||
def load_graph(graph_filename):
|
||||
with tf.gfile.GFile(graph_filename,'rb') as f:
|
||||
graph_def = tf.GraphDef()
|
||||
|
@ -77,9 +77,12 @@ def demo():
|
|||
face_texture_ = np.squeeze(face_texture_, (0))
|
||||
face_color_ = np.squeeze(face_color_, (0))
|
||||
landmarks_2d_ = np.squeeze(landmarks_2d_, (0))
|
||||
recon_img_ = None
|
||||
if not is_windows:
|
||||
recon_img_ = np.squeeze(recon_img_, (0))
|
||||
|
||||
# save output files
|
||||
if recon_img_:
|
||||
savemat(os.path.join(save_path,file.split(os.path.sep)[-1].replace('.png','.mat').replace('jpg','mat')),{'cropped_img':input_img[:,:,::-1],'recon_img':recon_img_,'coeff':coeff_,\
|
||||
'face_shape':face_shape_,'face_texture':face_texture_,'face_color':face_color_,'lm_68p':landmarks_2d_,'lm_5p':lm_new})
|
||||
save_obj(os.path.join(save_path,file.split(os.path.sep)[-1].replace('.png','_mesh.obj').replace('jpg','_mesh.obj')),face_shape_,tri_,np.clip(face_color_,0,255)/255) # 3D reconstruction face (in canonical view)
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
import tensorflow as tf
|
||||
import math as m
|
||||
import numpy as np
|
||||
import mesh_renderer
|
||||
from scipy.io import loadmat
|
||||
import platform, PIL
|
||||
|
||||
is_windows = platform.system() == "Windows"
|
||||
|
||||
if not is_windows:
|
||||
import mesh_renderer
|
||||
|
||||
###############################################################################################
|
||||
# Reconstruct 3D face based on output coefficients and facemodel
|
||||
###############################################################################################
|
||||
|
@ -56,10 +62,13 @@ class Face3D():
|
|||
self.face_color = face_color
|
||||
|
||||
# reconstruction images
|
||||
if not is_windows:
|
||||
render_imgs = self.Render_block(face_shape_t,norm_r,face_color,self.facemodel,batchsize)
|
||||
render_imgs = tf.clip_by_value(render_imgs,0,255)
|
||||
render_imgs = tf.cast(render_imgs,tf.float32)
|
||||
self.render_imgs = render_imgs
|
||||
else:
|
||||
self.render_imgs = []
|
||||
|
||||
######################################################################################################
|
||||
def Split_coeff(self,coeff):
|
||||
|
@ -272,6 +281,8 @@ class Face3D():
|
|||
far_clip = 50*tf.ones([batchsize])
|
||||
#using tf_mesh_renderer for rasterization (https://github.com/google/tf_mesh_renderer)
|
||||
# img: [batchsize,224,224,4] images in RGBA order (0-255)
|
||||
|
||||
if not is_windows:
|
||||
with tf.device('/cpu:0'):
|
||||
img = mesh_renderer.mesh_renderer(face_shape,
|
||||
tf.cast(facemodel.face_buf-1,tf.int32),
|
||||
|
@ -288,7 +299,9 @@ class Face3D():
|
|||
ambient_color = ambient_color,
|
||||
near_clip = near_clip,
|
||||
far_clip = far_clip)
|
||||
|
||||
return img
|
||||
else:
|
||||
#return PIL.Image.new('RGB', (224, 224))
|
||||
return np.zeros([224, 224], dtype=np.int32)
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче