#!/usr/bin/env python # coding: utf-8 # # Face Detection from Videos # # In this tutorial, we will use fastdup with a face detection model to detect and crop from videos. Following that we analyze the cropped faces for issues such as duplicates, near-duplicates, outliers, bright/dark/blurry faces. # # > This is an advanced functionality of fastdup. Sign up for free to be an beta tester and get early access at info@visual-layer.com . # ## Installation & Setting Up # In[1]: get_ipython().system('pip install pip -U') get_ipython().system('pip install fastdup') # In[2]: import fastdup fastdup.__version__ # ## Download & Extract Dataset # In[3]: get_ipython().system('gdown --fuzzy https://drive.google.com/file/d/1fzmOgmRu557aU4lEbzL7XCf78KntFCeQ/view') # In[4]: get_ipython().system('unzip data.zip') # ## Video to Images # # fastdup works on images. We must first turn the videos into frames of images. # # We can use a one-liner fastdup utility function to turn all the videos in a folder into frames: # In[5]: fastdup.extract_video_frames(input_dir="data", work_dir="frames") # ## Run fastdup # # Now that we have the frames of images, let's run fastdup and analyze the frames. # In[6]: fd = fastdup.create(input_dir='frames', work_dir='face_detection_work_dir') # As this is an advance functionality of fastdup, you'd need a license key to use this function, sign up and get your license key for free at info@visual-layer.com . # In[7]: fd.run(bounding_box='face', license='your_license_key', overwrite=True) # ## Components Gallery # # We can visualize the cluster of similar detections using the components gallery view. Specify `draw_bbox=True` to see the detection bounding box on the original image. # In[8]: fd.vis.component_gallery(draw_bbox=True) # If you'd like to view just the cropped bounding box images, specify `draw_bbox=False` # In[9]: fd.vis.component_gallery(draw_bbox=False) # ## Find Similar Faces Across Videos # # Using the `similarity_gallery` view, we can find similar looking faces (bounding boxes) across all the extracted frames. # In[10]: fd.vis.similarity_gallery(draw_bbox=False) # ## Find Outliers # # Useing the `outliers_gallery` we can also viaualize faces (detections) that looks visually different from others. # In[11]: fd.vis.outliers_gallery() # ## Duplicate Faces # # With the `duplicates_gallery` view, visualize duplicate image pairs across videos. # In[12]: fd.vis.duplicates_gallery() # ## Dark Faces # # Using the `stats_gallery` view, we can sort the faces (detections) following a desired `metric` such as 'dark', 'bright' and 'blur'. # In[13]: fd.vis.stats_gallery(metric='dark') # ## Bright Faces # In[14]: fd.vis.stats_gallery(metric='bright') # ## Blurry Faces # In[15]: fd.vis.stats_gallery(metric='blur') # In[ ]: