bigfunctions > generate_face_embedding
generate_face_embedding¶
Call or Deploy generate_face_embedding
?
✅ You can call this generate_face_embedding
bigfunction directly from your Google Cloud Project (no install required).
- This
generate_face_embedding
function is deployed inbigfunctions
GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error). - Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework
Public BigFunctions Datasets:
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Description¶
Signature
generate_face_embedding(image_url)
Description
Detect Face on image and Generate its Embedding using deepface.
image_url
is the url of a photo which contains a face. It can be a signed url of a cloud storage object. Then this function works well with object tables.output
is the output ofDeepFace.represent
method. It is like:
{
embedding: [...], # A 4096 float vector
facial_areal: {...}, # Coordinated of detected face
face_confidence: 1.0, # Confidence score for face detection
}
Examples¶
Public test image from deepface
select bigfunctions.eu.generate_face_embedding('https://raw.githubusercontent.com/serengil/deepface/master/tests/dataset/img1.jpg')
select bigfunctions.us.generate_face_embedding('https://raw.githubusercontent.com/serengil/deepface/master/tests/dataset/img1.jpg')
select bigfunctions.europe_west1.generate_face_embedding('https://raw.githubusercontent.com/serengil/deepface/master/tests/dataset/img1.jpg')
+-------------------------------------------------------------------------+
| output |
+-------------------------------------------------------------------------+
| {
embedding: [...],
facial_areal: {...},
face_confidence: 1.0,
}
|
+-------------------------------------------------------------------------+
Need help using generate_face_embedding
?
The community can help! Engage the conversation on Slack
For professional suppport, don't hesitate to chat with us.
Found a bug using generate_face_embedding
?
If the function does not work as expected, please
- report a bug so that it can be improved.
- or open the discussion with the community on Slack.
For professional suppport, don't hesitate to chat with us.
Use cases¶
This generate_face_embedding
function is useful for facial recognition tasks within BigQuery. Here's a use case:
Scenario: You have a large dataset of images stored in Google Cloud Storage, represented as an object table in BigQuery. You want to identify all images that contain a specific person.
Implementation using generate_face_embedding
:
-
Pre-calculate the embedding of the target person: Take a known image of the target person and use
generate_face_embedding
to calculate their facial embedding. Store this embedding (a vector of numbers) somewhere accessible, like a small BigQuery table. -
Process your image dataset: Query your object table and apply
generate_face_embedding
to the image URL column for each row. This will generate facial embeddings for all faces detected in your dataset. -
Compare embeddings: Use a BigQuery function (e.g., a user-defined function or a built-in function for vector similarity like cosine similarity) to compare the embeddings generated in step 2 with the target person's embedding from step 1.
-
Filter based on similarity: Filter the results based on a similarity threshold. Images with embeddings that are highly similar to the target person's embedding likely contain the target person.
Example SQL Snippet (Illustrative):
# Assuming 'target_embeddings' table contains pre-calculated embedding
# and 'image_table' is your object table with 'image_url' column
SELECT
image_url
FROM
image_table
WHERE EXISTS (
SELECT
1
FROM
target_embeddings
WHERE
cosine_similarity(bigfunctions.us.generate_face_embedding(image_table.image_url).embedding, target_embeddings.embedding) > 0.9 -- Example threshold
);
Benefits of using generate_face_embedding
within BigQuery:
- Scalability: BigQuery's distributed processing power allows you to analyze massive image datasets efficiently.
- Integration: Seamlessly integrates with your existing BigQuery data and workflows. No need to export data or use external tools.
- Cost-effectiveness: BigQuery's pricing model can be advantageous for large-scale processing compared to other solutions.
Other Use Cases:
- Face clustering: Group similar faces together to identify different individuals in a dataset.
- Security and surveillance: Identify known individuals in security footage.
- Image search: Search for images containing similar faces.
- Social media analysis: Analyze profile pictures for demographic information or to identify influencers.
Spread the word¶
BigFunctions is fully open-source. Help make it a success by spreading the word!