natively multi-modal processing - 동일한 프로그래밍 모델을 사용하여 텍스트와 이미지를 모두 처리하고 동일한 사용자 흐름에서 관찰할 수 있습니다. ) 코코인덱스 코코인사이트 코코인덱스 코코인사이트 이 블로그에서는 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 추출을 이해하고 평가하는 것이 더 쉬워지며 비 구조화 된 시각적 데이터의 맥락에서 컴퓨팅 된 기능을 완벽하게 연결할 수 있습니다. 코코인사이트 코코인사이트 If you find this tutorial helpful, we’d greatly appreciate it if you could ⭐ star . CocoIndex on GitHub GitHub에 있는 CocoIndex 케이스 사용 사진 검색 얼굴 기반 액세스 제어 및 감시 Visual Deduplication 및 Identity Detection 사람이나 얼굴 정체성을 포함하는 멀티모델 검색 사진에서 소셜 그래프 분석 우리는 무엇을 이룰 것인가 이 컨퍼런스의 참가자들의 사진은 때때로 , 세계 최고의 물리학자들의 묘사로 하나의 샷에 모인 ( ) ‘지금까지 찍은 가장 똑똑한 사진’ 위키피디아 이것은 우리가 성취하고자하는 것입니다 : 이미지의 모든 얼굴을 감지하고 그들의 경계 상자를 추출 각 얼굴 이미지를 128 차원의 얼굴 삽입으로 재배하고 코딩합니다.Crop and encode each face image into a 128-dimensional face embedding 메타데이터와 벡터를 구조화된 인덱스에 저장하여 "이 사람과 비슷한 얼굴을 찾으십시오"또는 "이 사람을 포함하는 이미지 검색"과 같은 쿼리를 지원합니다.Store metadata and vectors in a structured index to support queries such as: "Find all similar faces to this one" or "Search images that include this person" 당신은 전체 코드를 찾을 수 있습니다. . 여기에 흐름 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. 핵심 부품 이미지 삽입 우리는 모니터링 an 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), ) 이것은 테이블을 만듭니다 with 그리고 필드 filename content 당신은 그것을 당신의 (SQS 통합을 통해 ) 또는 . S3 버킷 예를 들면 Azure Blob 스토어 얼굴 탐지 및 추출 우리는 그것을 사용합니다 dlib의 CNN 기반 얼굴 탐지기에 의해 구동되는 캡 아래의 도서관.모델이 대형 이미지에서 느리기 때문에, 우리는 감지하기 전에 넓은 이미지를 저축합니다.E 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 우리는 동일한 라이브러리를 사용하여 각각의 조각된 얼굴을 인코딩합니다.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 이제 우리는 각 얼굴에 대한 구조화 된 데이터를 수집합니다 : 파일 이름, 경계 상자 및 삽입. 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"], ) 이제 얼굴 벡터에서 cosine 유사성 쿼리를 실행할 수 있습니다.Now you can run cosine similarity queries over facial vectors. CocoIndex는 다른 벡터 데이터베이스와 같은 1 라인 스위치를 지원합니다. . 포스트 원하는 index 이제 얼굴 검색 앱 또는 대시보드를 구축할 수 있습니다.For example: 새로운 얼굴을 삽입하면 가장 비슷한 얼굴을 찾으십시오. 사진 세트에 나타나는 모든 얼굴 이미지를 찾으십시오. 시각적으로 비슷한 사람들을 그룹화하는 클러스터 삽입 쿼리 삽입, 체크 아웃 . Image Search 프로젝트 이미지 일치가 있는 쿼리 경로에 대한 전체 예제를 보고 싶으시다면, 그것에 비명을 지르세요.If you want to see a full example on the query path with image match, give it a shout at . 우리 그룹 우리를 지지 우리는 끊임없이 더 많은 예를 추가하고 우리의 런타임을 개선하고 있습니다.당신이이 유용하다고 생각한다면, ⭐ 스타 그리고 그것을 다른 사람들과 공유하십시오. GitHub에 있는 CocoIndex 읽어주셔서 감사합니다! 당신이 어떤 파이프라인을 건설하고 있는지 알려주십시오 - 우리는 그들을 보여주고 싶습니다.