Skip to content

Instantly share code, notes, and snippets.

@priyanlc
Created April 19, 2024 06:13
Show Gist options
  • Save priyanlc/f3dde6aa32df13dca13150769266091b to your computer and use it in GitHub Desktop.
Save priyanlc/f3dde6aa32df13dca13150769266091b to your computer and use it in GitHub Desktop.
Identify Images with faces with face_recongnition
import os
from multiprocessing import Pool, cpu_count
class ImageBatchManager:
def __init__(self, processor, batch_size=100):
self.processor = processor
self.batch_size = batch_size
def process_batch(self, batch):
with Pool(cpu_count()) as pool:
results = pool.map(self.processor.process_image, batch)
for result in results:
print(result)
def process_folder(self, folder_path):
image_files = [os.path.join(folder_path, f) for f in os.listdir(folder_path) if f.endswith(".jpg")]
for i in range(0, len(image_files), self.batch_size):
batch = image_files[i:i + self.batch_size]
self.process_batch(batch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment