<jupyter_start><jupyter_text>A simple demostration of how to run<jupyter_code># before import, make sure FaceBoxes and Sim3DR are built successfully, e.g.,
# sh build.sh

import cv2
import yaml

from FaceBoxes import FaceBoxes
from TDDFA import TDDFA
from utils.functions import draw_landmarks
from utils.render import render
from utils.depth import depth

import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Load configs<jupyter_code># load config
cfg = yaml.load(open('configs/mb1_120x120.yml'), Loader=yaml.SafeLoader)
tddfa = TDDFA(gpu_mode=False, **cfg)

# Initialize FaceBoxes
face_boxes = FaceBoxes()
# given an image path
img_fp = 'examples/inputs/emma.jpg'
img = cv2.imread(img_fp)
plt.imshow(img[..., ::-1])<jupyter_output><empty_output><jupyter_text>Detect faces using FaceBoxes<jupyter_code># face detection
boxes = face_boxes(img)
print(f'Detect {len(boxes)} faces')
print(boxes)<jupyter_output><empty_output><jupyter_text>Regressing 3DMM parameters, reconstruction and visualization<jupyter_code># regress 3DMM params
param_lst, roi_box_lst = tddfa(img, boxes)
# reconstruct vertices and visualizing sparse landmarks
dense_flag = False
ver_lst = tddfa.recon_vers(param_lst, roi_box_lst, dense_flag=dense_flag)
draw_landmarks(img, ver_lst, dense_flag=dense_flag)
# reconstruct vertices and visualizing dense landmarks
dense_flag = True
ver_lst = tddfa.recon_vers(param_lst, roi_box_lst, dense_flag=dense_flag)
draw_landmarks(img, ver_lst, dense_flag=dense_flag)
# reconstruct vertices and render
ver_lst = tddfa.recon_vers(param_lst, roi_box_lst, dense_flag=dense_flag)
render(img, ver_lst, alpha=0.6, show_flag=True);
# reconstruct vertices and render depth
ver_lst = tddfa.recon_vers(param_lst, roi_box_lst, dense_flag=dense_flag)
depth(img, ver_lst, show_flag=True);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09482288828337875, 'fraction_numerical': 0.008174386920980926, 'mean_word_length': 8.319796954314722, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '5287', 'license': 'MIT', 'n_tokens_mistral': 681, 'n_tokens_neox': 657, 'n_words': 148, 'path': 'demo.ipynb', 'repo_name': 'datvo06/3ddfav2_modified', 'size': '1835'}