Disabled mesh_renderer as dependency when running Windows.

This commit is contained in:
Deconimus 2020-09-10 18:57:17 +02:00
Родитель 4b27ddf422
Коммит 9698245751
2 изменённых файлов: 45 добавлений и 29 удалений

15
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,11 +77,14 @@ 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_ = np.squeeze(recon_img_, (0))
recon_img_ = None
if not is_windows:
recon_img_ = np.squeeze(recon_img_, (0))
# save output files
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})
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)
if __name__ == '__main__':

Просмотреть файл

@ -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
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
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,23 +281,27 @@ 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)
with tf.device('/cpu:0'):
img = mesh_renderer.mesh_renderer(face_shape,
tf.cast(facemodel.face_buf-1,tf.int32),
face_norm,
face_color,
camera_position = camera_position,
camera_lookat = camera_lookat,
camera_up = camera_up,
light_positions = light_positions,
light_intensities = light_intensities,
image_width = 224,
image_height = 224,
fov_y = fov_y, #12.5936
ambient_color = ambient_color,
near_clip = near_clip,
far_clip = far_clip)
return img
if not is_windows:
with tf.device('/cpu:0'):
img = mesh_renderer.mesh_renderer(face_shape,
tf.cast(facemodel.face_buf-1,tf.int32),
face_norm,
face_color,
camera_position = camera_position,
camera_lookat = camera_lookat,
camera_up = camera_up,
light_positions = light_positions,
light_intensities = light_intensities,
image_width = 224,
image_height = 224,
fov_y = fov_y, #12.5936
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)