multi-modal processing ස්වයංක්රීයව සහාය - එය එකම වැඩසටහන් ආකෘතිය සමඟ teks හා රූප දෙකම ක්රියාත්මක කළ හැකි අතර, එකම පරිශීලක ක්රියාවලිය තුළ නිරීක්ෂණය කළ හැකිය (in ) CocoIndex කොකේස් CocoIndex කොකේස් මෙම බ්ලොග් අඩවියේ, අපි CocoIndex භාවිතා කිරීමෙන් පුළුල් කළ හැකි මුහුණු හඳුනාගැනීමේ පයිප්පලයින් ගොඩනැගීමේ සම්පූර්ණ උදාහරණයක් හරහා ගමන් කරමු.We will show how to extract and embed faces from images, structure the data relationally, and export everything into a vector database for real-time querying. දැන් සීමා පෙට්ටි මත පදනම්ව පින්තූරයේ හඳුනාගත් කොටස් දර්ශනය කළ හැකි අතර AI ආකෘති තේරුම් ගැනීම හා විශ්ලේෂණය කිරීම පහසු කරයි - අමුද්රව්ය නොවන දර්ශන දත්ත සම්බන්ධතාවය තුළ පරිගණක විශේෂාංග සෘජුවම එකතු කිරීම. CocoInsight කොකේස් If you find this tutorial helpful, we’d greatly appreciate it if you could ⭐ star . CocoIndex on GitHub GitHub හි CocoIndex Case භාවිතය ඡායාරූපය Search Face-based Access Control සහ අධීක්ෂණය Visual Deduplication සහ Identity Detection පුද්ගලයන් හෝ මුහුණු හඳුනා ගැනීම සම්බන්ධ multimodal search ඡායාරූප වලින් සමාජ Graph Analysis අපි කුමක් සාර්ථක කරමුද මෙම සමුළුවේ සහභාගීත්වයේ ඡායාරූපය සමහර වෙලාවට , ලෝකයේ ප්රධාන භෞතික විද් යාඥයන් එක් එක් ඡායාරූපයක් තුළ රැස් වූ එහි විස්තරය සඳහා ( ) කවදාවත් කර ඇති වඩාත් බුද්ධිමත් ඡායාරූපය විකිපීඩියා මෙන්න අපි ඉටු කිරීමට අවශ් ය දේ: පින්තූරයේ සියලුම මුහුණු හඳුනාගෙන ඔවුන්ගේ සීමා පෙට්ටිය ඉවත් කරන්න එක් එක් මුහුණ පින්තූරයක් 128-මාර්ගයේ මුහුණ ඇතුළත් කිරීම සඳහා වර්ණ හා කේතය මෙටා දත්ත සහ විචල්ය රඳා පවතී ආකෘතිගත ඉංජිනේරුවක ප්රශ්න සහාය කිරීම සඳහා: "මේ පුද්ගලයා සමඟ සමාන සියලු මුහුණ සොයා" හෝ "මේ පුද්ගලයා ඇතුළත් වන රූප සොයන්න" ඔබට සම්පූර්ණ කේතය සොයා ගත හැකිය . මෙතන Flow Index කිරීම අපි පින්තූර ලැයිස්තුවක් එකතු කළා. For each image, we: Extract faces from the image. Compute embeddings for each face. We export the following fields to a table in Postgres with PGVector: Filename, rect, embedding for each face. මූලික කොටස් ඡායාරූපය Ingestion අපි නිරීක්ෂණය කරනවා built-in භාවිත කිරීම සියලුම අලුතින් එකතු කරන ලද ගොනු ස්වයංක්රීයව පරිශීලක හා ඉංජිනේරු කරනු ලැබේ. images/ LocalFile python CopyEdit @cocoindex.flow_def(name="FaceRecognition") def face_recognition_flow(flow_builder, data_scope): data_scope["images"] = flow_builder.add_source( cocoindex.sources.LocalFile(path="images", binary=True), refresh_interval=datetime.timedelta(seconds=10), ) මේ නිසා මේසයක් හදනවා සහ ගම්මානය filename content ඔබට එය ඔබගේ (SQS සම්බන්ධතාවය සමඟ, ) හෝ . S3 බකට් උදාහරණයක් Azure Blob වෙළඳසැල මුහුණු හඳුනා ගැනීම සහ ඉවත් කිරීම අපි පාවිච්චි කරන්නේ dlib හි CNN මත පදනම් වන මුහුණු දර්ශකය මගින් බලපාන පුවරුවක පුවරුවක.මොකද ආකෘතිය විශාල පින්තූර මත වේගවත් වන බැවින්, අපි දර්ශනය කිරීමට පෙර විශාල පින්තූර පහළ ප්රමාණවත් කරමු. face_recognition @cocoindex.op.function( cache=True, behavior_version=1, gpu=True, arg_relationship=(cocoindex.op.ArgRelationship.RECTS_BASE_IMAGE, "content"), ) def extract_faces(content: bytes) -> list[FaceBase]: orig_img = Image.open(io.BytesIO(content)).convert("RGB") # The model is too slow on large images, so we resize them if too large. if orig_img.width > MAX_IMAGE_WIDTH: ratio = orig_img.width * 1.0 / MAX_IMAGE_WIDTH img = orig_img.resize( (MAX_IMAGE_WIDTH, int(orig_img.height / ratio)), resample=Image.Resampling.BICUBIC, ) else: ratio = 1.0 img = orig_img # Extract face locations. locs = face_recognition.face_locations(np.array(img), model="cnn") faces: list[FaceBase] = [] for min_y, max_x, max_y, min_x in locs: rect = ImageRect( min_x=int(min_x * ratio), min_y=int(min_y * ratio), max_x=int(max_x * ratio), max_y=int(max_y * ratio), ) # Crop the face and save it as a PNG. buf = io.BytesIO() orig_img.crop((rect.min_x, rect.min_y, rect.max_x, rect.max_y)).save( buf, format="PNG" ) face = buf.getvalue() faces.append(FaceBase(rect, face)) return faces අපි පින්තූර අන්තර්ගතය වෙනස් කරමු: with data_scope["images"].row() as image: image["faces"] = image["content"].transform(extract_faces) මෙම පියවරෙන් පසුව, සෑම ඡායාරූපයක්ම නිරීක්ෂිත මුහුණ සහ සීමා පෙට්ටිය ලැයිස්තුවක් ඇත. සෑම නිරීක්ෂිත මුහුණක්ම මුල් ඡායාරූපයෙන් ඉවත් කර PNG ලෙස ගබඩා කරනු ලැබේ. උදාහරණ ආකෘතිය: උදාහරණ ආකෘතිය: Face Embeddings පරිගණක අපි එකම පුස්තකාලය භාවිතා කරමින් සෑම පිටපතක්ම coded කරමු.This generates a 128-dimensional vector representation per face. @cocoindex.op.function(cache=True, behavior_version=1, gpu=True) def extract_face_embedding( face: bytes, ) -> cocoindex.Vector[cocoindex.Float32, typing.Literal[128]]: """Extract the embedding of a face.""" img = Image.open(io.BytesIO(face)).convert("RGB") embedding = face_recognition.face_encodings( np.array(img), known_face_locations=[(0, img.width - 1, img.height - 1, 0)], )[0] return embedding අපි ක්රියාකාරිත්වය ඇතුළත් කර ගනිමු: with image["faces"].row() as face: face["embedding"] = face["image"].transform(extract_face_embedding) මෙම පියවරෙන් පසු, අපි ඉංජිනේරු කිරීම සඳහා සූදානම් embeddings ඇත! Collect and Export Embeddings - ඇතුළත් කිරීම සහ විකිණීම දැන් අපි සෑම මුහුණකටම සංයුක්ත දත්ත රැස් කරනවා: ගොනු නාමය, සීමා පෙට්ටිය සහ ඇතුළත් කිරීම. face_embeddings = data_scope.add_collector() face_embeddings.collect( id=cocoindex.GeneratedField.UUID, filename=image["filename"], rect=face["rect"], embedding=face["embedding"], ) අපි Qdrant රැස්වීම සඳහා විකුණුම්: face_embeddings.export( QDRANT_COLLECTION, cocoindex.targets.Qdrant( collection_name=QDRANT_COLLECTION ), primary_key_fields=["id"], ) දැන් ඔබ Face Vector හරහා Cosine සමානත්වය ප්රශ්න ක්රියාත්මක කළ හැකිය. CocoIndex සහතික 1-line switch with other vector databases . තැපැල් INDEX අවශ්යතා දැන් ඔබට Face Search Apps හෝ Dashboards නිර්මාණය කළ හැකිය. නව මුහුණක් ඇතුළත් කිරීම සඳහා, වඩාත් සමාන මුහුණ සොයා ගන්න ඡායාරූප කිහිපයක් තුළ පෙනෙන සියලුම මුහුණ පින්තූර සොයා ගන්න සෘජු ලෙස සමාන පුද්ගලයන් එකතු කිරීම සඳහා Cluster embeddings to group visually similar people ප් රචණ්ඩත්වය සඳහා, check out . Image Search ව් යාපෘතිය ඡායාරූප ගැලපෙන ප්රශ්න මාර්ගය පිළිබඳ සම්පූර්ණ උදාහරණයක් බලන්න කැමති නම්, එය ප්රකාශ කරන්න . අපගේ කණ්ඩායම අපට සහාය අපි දිගින් දිගටම තවත් උදාහරණ එකතු හා අපගේ runtime වැඩි දියුණු.If you found this helpful, please ⭐ star අනිත් අයටත් බෙදා ගන්න. GitHub හි CocoIndex කියවන්න ස්තුතියි! ඔබ ගොඩනගන්නේ කුඩු කුඩු මොනවාද කියා අපි දැනුවත් කරමු - අපි ඒවා ප්රදර්ශනය කිරීමට කැමතියි.