microsoft / cognitive-face-python Goto Github PK
View Code? Open in Web Editor NEWPython SDK for the Microsoft Face API, part of Cognitive Services
Home Page: https://www.microsoft.com/cognitive-services/en-us/face-api
License: Other
Python SDK for the Microsoft Face API, part of Cognitive Services
Home Page: https://www.microsoft.com/cognitive-services/en-us/face-api
License: Other
Hi, if I use your service in my research paper, how to cite it properly?
https://azure.microsoft.com/zh-cn/services/cognitive-services/face/
I am using python2
Steps I've followed are:
pip install cognitive_face
python setup.py install
getting a valid subscription key
Copy cognitive_face/tests/config.sample.py into cognitive_face/tests/config.py.
Change the KEY and BASE_URL parameters to your own subscription's API key and endpoint.
Run the following:
python setup.py test
pip install -r requirements.txt
At requirements.txt an exception occurs at line 6 completed 21%
Exception:
Traceback (most recent call last):
File "/usr/share/python-wheels/urllib3-1.15.1-py2.py3-none-any.whl/urllib3/response.py", line 228, in _error_catcher
yield
I would like to ask you, can i do something like migration or scale up the data from existing person group to large person group?
From the first place I use person group as planed the person might not go over the limitation but I found the growth is faster than I expected, so, now it go over the limitation of "person group" spec.
But I still want to continue implementing on existing data, and don't want to do the subscription process like - create group -> create person -> add faces to person from the start again.
How can I achieve for what I want, or is it possible?
Following the regular instructions in the read me on Win10 using Py3, it fails running "python sample" or "python3 sample"
$ python sample
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\runpy. py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\runpy. py", line 85, in _run_code
exec(code, run_globals)
File "sample\__main__.py", line 8, in
from view import MyApp
File "sample\view\__init__.py", line 15, in
from view.panel_detection import DetectionPanel
File "sample\view\panel_detection.py", line 90
@util.async
SyntaxError: invalid syntax
I am trying to add one photo to a person_group
name = "Alice"
user_data = 'More information can go here'
response = CF.person.create(PERSON_GROUP_ID, name, user_data)
person_id = response['personId']
CF.person.add_face('/Images/IMG_0325.jpg', PERSON_GROUP_ID, person_id)**
But I got the following error. Can someone help?
CognitiveFaceException: Error when calling Cognitive Face API:
status_code: 400
code: InvalidURL
message: Invalid image URL.
I am a student that got tasked to run a lot of face compares through the verification function of the API with a custom algorithm written to automate it. How I understand it works by running the App is that it first needs to detect both faces submitted after that you get the faceid's back from both and those face Id's get compared to each other. I'm trying to find the section in the code samples where it goes through these steps but I can't find it. could someone point me towards the file/line I need to go to where it happens?
I'm not a python guy so I'm really struggling but we are required to write in Python.
Also is it possible to specify that you only want the faceId of an image returned instead of all the other info included? Sorry if I sound like a complete amateur it's because I am one. :(
Below is the comment of the detect method.
attributes: [Optional] Analyze and return the one or more specified
face attributes in the comma-separated string like
"returnFaceAttributes=age,gender". Supported face attributes
include age, gender, headPose, smile, facialHair, glasses and
emotion. Note that each face attribute analysis has additional
computational and time cost.
quote from face.py
The attributes arg should be "age,gender", not "returnFaceAttributes=age,gender".
This comment is difficult to understand.
Current unittests only cover the most basic functionality, it could be better.
Hi,
It said on https://wxpython.org/ that
(16-April-2017) wxPython 4.0.0a1 is now available on PyPI. This is the first official release of the new Phoenix version of wxPython, including support for Python 2.7 and 3.4+, installation from PyPI, fully self-contained and relocatable so it can be installed in virtual environments, etc.
Should we be expecting a release to support Python 3.6 soon?
Hi, I saw that one of the pull requests "recognition_model" hasn't been merged yet. Because of this, I am experiencing a Response 400 error: BadArgument | 'recognitionModel' is incompatible.
I am guessing this is because my largeFaceList has been trained with recognition_model = 2 but my new faces are being detected with recognition_model = 1?
Is this now unsupported API functionality? Have not been able to return attributes.
Hi! i want to learn the inside structure of the face API, where can i see? Or microsoft doesn't make the code public?
2017-08-15 09:52:44.543 Python[785:19602] *** Assertion failure in void assertRunningOnAppKitThread()(), /Library/Caches/com.apple.xbs/Sources/ViewBridge/ViewBridge-283/ViewBridgeUtilities.m:1045
2017-08-15 09:52:44.549 Python[785:19602] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'not running on AppKit (main) thread'
*** First throw call stack:
(
0 CoreFoundation 0x00007fffb06ff2cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fffc550f48d objc_exception_throw + 48
2 CoreFoundation 0x00007fffb0704042 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00007fffb21b4da6 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166
4 ViewBridge 0x00007fffc3f5938d -[NSRemoteView _preSuperInit] + 28
5 ViewBridge 0x00007fffc3f59793 -[NSRemoteView initWithFrame:] + 25
6 ViewBridge 0x00007fffc3f8aaa8 +[NSRemoteViewController requestViewController:withServiceSubclassIdentifier:connectionHandler:withBlock:] + 244
7 ViewBridge 0x00007fffc3f8b04c +[NSRemoteViewController requestViewController:fromServiceListenerEndpoint:connectionHandler:] + 78
8 HIToolbox 0x00007fffafe41841 -[IMKInputSession presentFunctionRowItemTextInputViewWithEndpoint:completionHandler:] + 1760
9 HIToolbox 0x00007fffafe36b39 __80-[IMKInputSession imkxpc_presentFunctionRowItemTextInputViewWithEndpoint:reply:]_block_invoke + 538
10 CoreFoundation 0x00007fffb069517c CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12
11 CoreFoundation 0x00007fffb0675f84 __CFRunLoopDoBlocks + 356
12 CoreFoundation 0x00007fffb0675ac6 __CFRunLoopRun + 1878
13 CoreFoundation 0x00007fffb0675114 CFRunLoopRunSpecific + 420
14 HIToolbox 0x00007fffafe1219e -[IMKInputSessionXPCInvocation invocationAwaitXPCReply] + 606
15 HIToolbox 0x00007fffafe14750 -[IMKInputSession activate] + 3471
16 HIToolbox 0x00007fffafdc87ab IMKInputSessionActivate + 36
17 HIToolbox 0x00007fffafdc7b3c ActivateInputMethodInstance + 100
18 HIToolbox 0x00007fffafdbc4ca utOpenActivateSelectedInputMethodInDoc + 369
19 HIToolbox 0x00007fffafdbc334 utOpenActivateAllSelectedIMInDocIterator + 21
20 CoreFoundation 0x00007fffb0637e34 CFArrayApplyFunction + 68
21 HIToolbox 0x00007fffafbf1384 utOpenActivateAllSelectedIMInDoc + 187
22 HIToolbox 0x00007fffafbe9ee8 MyActivateTSMDocument + 1910
23 AppKit 0x00007fffae2b288d -[NSTextInputContext activate] + 284
24 AppKit 0x00007fffaeb43ec2 +[NSTextInputContext currentInputContext_withFirstResponderSync:] + 362
25 AppKit 0x00007fffae252060 -[NSTextView(NSSharing) setEditable:] + 250
26 libwx_osx_cocoau_core-3.0.dylib 0x0000000105c7001b _ZN19wxNSTextViewControl9WriteTextERK8wxString + 57
27 libwx_osx_cocoau_core-3.0.dylib 0x0000000105bfecaa _ZN11wxTextEntry9WriteTextERK8wxString + 84
28 core.so 0x000000010491427d Z29_wrap_TextEntryBase_WriteTextP7_objectS0_S0 + 194
29 Python 0x00000001045280ac PyEval_EvalFrameEx + 13560
30 Python 0x00000001045249be PyEval_EvalCodeEx + 1617
31 Python 0x000000010452b3e2 _PyEval_SliceIndex + 338
32 Python 0x0000000104527e4e PyEval_EvalFrameEx + 12954
33 Python 0x000000010452b475 _PyEval_SliceIndex + 485
34 Python 0x0000000104527e4e PyEval_EvalFrameEx + 12954
35 Python 0x00000001045249be PyEval_EvalCodeEx + 1617
36 Python 0x00000001044ca4d1 PyFunction_SetClosure + 826
37 Python 0x00000001044ac6fb PyObject_Call + 99
38 Python 0x0000000104527fe5 PyEval_EvalFrameEx + 13361
39 Python 0x000000010452b475 _PyEval_SliceIndex + 485
40 Python 0x0000000104527e4e PyEval_EvalFrameEx + 12954
41 Python 0x000000010452b475 _PyEval_SliceIndex + 485
42 Python 0x0000000104527e4e PyEval_EvalFrameEx + 12954
43 Python 0x00000001045249be PyEval_EvalCodeEx + 1617
44 Python 0x00000001044ca4d1 PyFunction_SetClosure + 826
45 Python 0x00000001044ac6fb PyObject_Call + 99
46 Python 0x00000001044b73ac PyMethod_New + 1221
47 Python 0x00000001044ac6fb PyObject_Call + 99
48 Python 0x000000010452adbb PyEval_CallObjectWithKeywords + 165
49 Python 0x0000000104557d4e initthread + 2833
50 libsystem_pthread.dylib 0x00007fffc600e93b _pthread_body + 180
51 libsystem_pthread.dylib 0x00007fffc600e887 _pthread_body + 0
52 libsystem_pthread.dylib 0x00007fffc600e08d thread_start + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6
I usually develop application in environment under proxy.
Please support proxy.
The following coding style may be good.
import cognitive_face as CF
CF.Proxy.set('proxy')
Currently there are five url to get information about faces, but I do not know how to set up another.
I tried to run the sample by following the steps in the readme (installed python 2.7, installed wxPython, installed cognitive_face).
However, I got this error:
C:\Users\mparn\Desktop\Cognitive-Face-Python (master)
λ python sample\
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Users\mparn\Desktop\Cognitive-Face-Python\sample\__main__.py", line 8, in <module>
from view import MyApp
File "sample\view\__init__.py", line 15, in <module>
from view.panel_detection import DetectionPanel
File "sample\view\panel_detection.py", line 10, in <module>
import util
File "sample\util.py", line 12, in <module>
from PIL import Image
ImportError: No module named PIL
This is fixed by running pip install image
.
Although now I get a different error...
λ python sample\
Traceback (most recent call last):
File "sample\view\__init__.py", line 100, in OnInit
frame = MyFrame(None)
File "sample\view\__init__.py", line 80, in __init__
self.book = MyLabelBook(self)
File "sample\view\__init__.py", line 31, in __init__
subscription_panel = SubscriptionPanel(self)
File "sample\view\panel_subscription.py", line 42, in __init__
subgridsizer = wx.GridSizer(rows=2, cols=2)
TypeError: GridSizer(): arguments did not match any overloaded call:
overload 1: 'rows' is not a valid keyword argument
overload 2: 'rows' is not a valid keyword argument
overload 3: not enough arguments
overload 4: not enough arguments
OnInit returned false, exiting...
I'm using Python 2.7.14
I executed an Identify faces from a Large group person. However, if I identify faces in a photo which has more than 10 faces, I will get the error "The length of faceIds is not in a valid range".
I suspected that the number of faces that can be identified at the same time is limited. How can I increase the limit of number of faces to be identified at once?
Rate limiting is hard to handle higher up in code. It would be extremely useful if there was a globally shared rate limiter that can be set (or voided entirely) at the call level with the API. Maybe look at https://github.com/tomasbasham/ratelimit which would work well since all calls go through CF.util requests.
I am using the identify operation to identify the face in persongroup. I have a person group with three images of same person. I am using the detect_with_stream to detect the face of test image. The operation - face_client.face.identify(face_ids, PERSON_GROUP_ID) is failing for me.
Code Snippet -
`
image_bytes = base64.b64decode(base64Str.split(',')[1])
face_ids = []
# We use detection model 3 to get better performance.
faces = face_client.face.detect_with_stream(io.BytesIO(image_bytes), detection_model='detection_03')
for face in faces:
face_ids.append(face.face_id)
print ('Length of face id', face_ids)
# Identify faces
results = face_client.face.identify(face_ids, PERSON_GROUP_ID)
print (results)
`
base64Str - is the base64 string coming from the web application. Please note, that this code was working fine and i was able to identify the faces and also tested for negative scenario. Its just stopped working and I cant figure out why.
Python Console output -
Length of face id [] ERROR:main:Exception on /login [POST] Traceback (most recent call last): File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "c:\program files (x86)\python36-32\lib\site-packages\flask_cors\extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "c:\program files (x86)\python36-32\lib\site-packages\flask\_compat.py", line 39, in reraise raise value File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "C:\Users\T9SAU2\OneDrive - Chubb\Documents\AngularJs\dashboard\backend\main.py", line 98, in login result = iden.convert_to_image(body['base64']) File "C:\Users\T9SAU2\OneDrive - Chubb\Documents\AngularJs\dashboard\backend\identify_users.py", line 48, in convert_to_image results = face_client.face.identify(face_ids, PERSON_GROUP_ID) File "c:\program files (x86)\python36-32\lib\site-packages\azure\cognitiveservices\vision\face\operations\_face_operations.py", line 313, in identify raise models.APIErrorException(self._deserialize, response) azure.cognitiveservices.vision.face.models._models_py3.APIErrorException: (BadArgument) The length of faceIds is not in a valid range. INFO:werkzeug:127.0.0.1 - - [21/Feb/2021 10:44:58] "POST /login HTTP/1.1"
Face
, FaceList
, Person
and PersonGroup
for different entity.rect
, attrs
models and so on for rectangle and attributes information.Microsoft by default sets maximum length of faceIds to 20 whereas the limit is 1000. I want to increase it. I am unable to resolve the issue. Thanks for the help in advace!!
https://github.com/Microsoft/Cognitive-Face-Python/blob/master/cognitive_face/face.py#L14 comment here can become more helpful if additional attributes can be added.
"age,gender,headPose,smile,facialHair,glasses,emotion,makeup,hair,accessories"
Also, not sure if this is the right place to mention this but in the [https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236](official documentation) faceAttributes
include accessory
as a param but when using that it returns a Bad Request response. The correct attribute is accessories
It would be great if the requirements.txt would include versions of the packages. Thanks!
I'm wondering what is the difference between this SDK (Microsoft/Cognitive-Face-Python) and the azure.cognitiveservices.vision.face
module in Azure/azure-sdk-for-python?
Against which SDK should a user integrate? E.g. which SDK will receive more support for API changes/etc.?
It would be great if you could add some guidance to the README on what's the relationship between the SDKs and which one should be preferred for which sort of use-cases.
Thanks in advance!
I've tried the package today and it doesn't work for me. The error message is below :
KeyError Traceback (most recent call last)
import cognitive_face as cf
cf.Key.set(key)
cf.BaseUrl.set(baseUrl)
group_id = "myfriends5"
group_name = "My friends"
group_data = "No data added for instant"
group = cf.person_group.create(group_id, group_name, group_data)
cognitive_face\util.py in request(method, url, data, json, headers, params)
101 try:
--> 102 error_msg = response.json()['error']
103 except:
KeyError: 'error'
During handling of the above exception, another exception occurred:
CognitiveFaceException Traceback (most recent call last)
<ipython-input-5-c52595173f41> in <module>()
2 group_name = "My friends"
3 group_data = "No data added for instant"
----> 4 group = cf.person_group.create(group_id, group_name, group_data)
cognitive_face\person_group.py in create(person_group_id, name, user_data)
31 }
32
---> 33 return util.request('PUT', url, json=json)
34
35
\cognitive_face\util.py in request(method, url, data, json, headers, params)
103 except:
104 raise CognitiveFaceException(response.status_code,
--> 105 response.status_code, response.text)
106 raise CognitiveFaceException(response.status_code,
107 error_msg.get('code'),
CognitiveFaceException: Error when calling Cognitive Face API:
status_code: 404
code: 404
message: { "statusCode": 404, "message": "Resource not found" }
It takes much time to figure out what is the problem : currently, urls passed to request()
are not well parsed. Instead of url = 'persongroups/{}'.format(person_group_id)
we must have url = "face/v1.0/persongroups/{}".format(person_group_id)
. Things worked for me when I clone the repo and modifies the urls.
There is a GUI Application in the Repo but there is not a simple minimum working example for Face Identification.
The GUI Application intimidated me as I started to look into it, as a beginner myself.
I would like to make a PR of something like this Simple Working Example, of course after cleaning it up.
Would this be a good idea?
Yes, I have read the Contributing Guidelines, which state that UI needs to be included. But would a Simple Working Example make things easier?
Hi,
Microsoft Cognitive Services Face API also has face identification, such as here: https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/howtoidentifyfacesinimage
However, this all seems to be in CSharp. Is there a python version of this? Is your repo connecting to the identification call in pyhton?
Thank you,
Selin
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.