in preprocess_img.py [0:0]
def preprocessing():
args = parse_args()
image_path = args.img_path
save_path = args.save_path
if not os.path.isdir(save_path):
os.makedirs(save_path)
if not os.path.isdir(os.path.join(save_path,'lm')):
os.makedirs(os.path.join(save_path,'lm'))
if not os.path.isdir(os.path.join(save_path,'lm_bin')):
os.makedirs(os.path.join(save_path,'lm_bin'))
if not os.path.isdir(os.path.join(save_path,'mask')):
os.makedirs(os.path.join(save_path,'mask'))
img_list = sorted(glob.glob(image_path + '/' + '*.png'))
img_list += sorted(glob.glob(image_path + '/' + '*.jpg'))
lm3D = load_lm3d()
with tf.Graph().as_default() as graph, tf.device('/gpu:0'):
lm_detector = load_graph(os.path.join('network','landmark68_detector.pb'))
tf.import_graph_def(lm_detector,name='')
sess = tf.InteractiveSession()
for file in img_list:
print(file)
name = file.split('/')[-1].replace('.png','').replace('.jpg','')
img,lm5p = load_img(file,file.replace('png','txt').replace('jpg','txt'))
img_align,_,_ = align_img(img,lm5p,lm3D) # [1,224,224,3] BGR image
lm68p = get_68landmark(img_align,graph,sess)
lm68p = lm68p.astype(np.float64)
skin_mask = get_skinmask(img_align)
Image.fromarray(img_align.squeeze(0)[:,:,::-1].astype(np.uint8),'RGB').save(os.path.join(save_path,name+'.png'))
Image.fromarray(skin_mask.astype(np.uint8)).save(os.path.join(save_path,'mask',name+'.png'))
np.savetxt(os.path.join(save_path,'lm',name+'.txt'),lm68p)
lm_bin = np.reshape(lm68p,[-1])
lm_bin.tofile(os.path.join(save_path,'lm_bin',name+'.bin'))