I want to test if two pictures belong to the same person using Google Cloud Function. The function would recieve the images in base64 format. During runtime, these images would be converted to JPEG format and would be stored in a temporary folder. I want to implement a Facial recognition algorithm to see if these pictures belong to the same person. If any of you guys have suggestions for a framework that can be used on google cloud functions for face identification, kindly let me know. currently, I'm using DeepFace and VGGFace model for image recogniton but the google cloud function doesnt seem to support DeepFace. When I try to deploy the code that imports deepface, it generates the following error
For the sake of debugging, I've deployed the following code, this code would be converted to the desired code when I'm able to find a way around the error.
from flask import jsonify
import base64
from PIL import Image
from io import BytesIO
from deepface import DeepFace
def hello_world(request):
"""Responds to any HTTP request.
Args:
request (flask.Request): HTTP request object.
Returns:
Te response text or any set of values that can be turned into a
Response object using
`make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
"""
request_json = request.get_json()
data = request.json
if request.args and 'num1' in request.args:
base64_string=request.args.get('num1')
elif request_json and 'num1' in request_json:
base64_string=request_json['num1']
else:
return "Invalid data"
# convert base64 string to bytes
img_data = base64.b64decode(base64_string)
# create PIL image object from bytes
img = Image.open(BytesIO(img_data))
# save the image as a JPEG file
img.save('/tmp/output.jpg', "JPEG")
embedding_objs = DeepFace.represent(img_path = "/tmp/output.jpg")
return embedding_objs[0]["facial_area"]['x']
This code, when deployed on Google Cloud Functions, generates the following error:
Deployment failure:
Function failed on loading user code. This is likely due to a bug in the user code. Error message: Traceback (most recent call last):
File "/layers/google.python.pip/pip/bin/functions-framework", line 8, in <module>
sys.exit(_cli())
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/functions_framework/_cli.py", line 37, in _cli
app = create_app(target, source, signature_type)
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/functions_framework/__init__.py", line 288, in create_app
spec.loader.exec_module(source_module)
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/workspace/main.py", line 5, in <module>
from deepface import DeepFace
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/deepface/DeepFace.py", line 13, in <module>
import cv2
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/layers/google.python.pip/pip/lib/python3.10/site-packages/cv2/__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "/layers/google.python.runtime/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.