So, I started with this article https://towardsdatascience.com/predict-age-and-gender-using-convolutional-neural-network-and-opencv-fd90390e3ce6 for age and gender detection and, I am facing a trivial problem. I am not able to run caffe on pictures downloaded from google. Actually, it's running only on the pictures that I take from my phone or webcam. Is there any specific reason or am I doing something incorrectly? Also I wrapping all of this with flask.
for example:- when I feed this image that i took from google search https://www.hanselman.com/blog/content/binary/WindowsLiveWriter/DIYMakingaWideAngleWebcam_1478B/2010-02-16%2023-01-29.283_2.jpg
I get this as my logs:-
127.0.0.1 - - [12/Mar/2020 11:51:57] "?[1m?[35mPOST /predicWithImage HTTP/1.1?[0m" 500 -
Traceback (most recent call last):
File "C:\Users\abc\AppData\Local\Continuum\anaconda3\lib\site-
packages\flask\app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\abc\AppData\Local\Continuum\anaconda3\lib\site-
packages\flask\app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\abc\AppData\Local\Continuum\anaconda3\lib\site-
packages\flask_cors\extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\abc\AppData\Local\Continuum\anaconda3\lib\site-
packages\flask\app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\abc\AppData\Local\Continuum\anaconda3\lib\site-
packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\abc\AppData\Local\Continuum\anaconda3\lib\site-
packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\abc\AppData\Local\Continuum\anaconda3\lib\site-
packages\flask\app.py", line 1952, in full_dispatch_request
return self.finalize_request(rv)
File "C:\Users\abc\AppData\Local\Continuum\anaconda3\lib\site-
packages\flask\app.py", line 1967, in finalize_request
response = self.make_response(rv)
File "C:\Users\abc\AppData\Local\Continuum\anaconda3\lib\site-
packages\flask\app.py", line 2097, in make_response
"The view function did not return a valid response. The"
TypeError: The view function did not return a valid response. The
function either returned None or ended without a return statement.
vs Logs If I feed the picture taken from my webcam/phone.
Found 1 faces
printing the blob
Gender: Male
Age Range: (15, 20)
127.0.0.1 - - [12/Mar/2020 11:56:07] "?[37mPOST /predicWithImage HTTP/1.1?[0m" 200 -
As you can see i am getting 200 for pictures from webcam vs 500 for google pictures. It's not an issue with flask wrapper, rather I tested the code directly with a picture on my disk into cv.imread(), the Caffe model is not picking it up.
Related
I suspect the code below ran out connection capacity, etc. Is there any interface I can send batch requests with? Or sleep a few ms?
def archive_pending_blobs(bucket: Bucket, blobs: typing.List[Blob], pending_prefix: str,
loaded_prefix: str) -> None:
"""Archive pending blobs to loaded prefix."""
try:
for b in blobs:
bucket.copy_blob(b, bucket, b.name.replace(pending_prefix, loaded_prefix))
bucket.delete_blobs(blobs)
except Exception as e:
print('gcs achieving error for path: {} err: {}'.format(pending_prefix, e))
raise e
Traceback (most recent call last): File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request six.raise_from(e, None) File "", line 2, in raise_from File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request httplib_response = conn.getresponse()
File "/opt/python3.7/lib/python3.7/http/client.py", line 1321, in getresponse response.begin() File "/opt/python3.7/lib/python3.7/http/client.py", line 296, in begin version, status, reason = self._read_status() File "/opt/python3.7/lib/python3.7/http/client.py", line 257, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/opt/python3.7/lib/python3.7/socket.py", line 589, in readinto return self._sock.recv_into(b) File "/opt/python3.7/lib/python3.7/ssl.py", line 1049, in recv_into return self.read(nbytes, buffer) File "/opt/python3.7/lib/python3.7/ssl.py", line 908, in read return self._sslobj.read(len, buffer) ConnectionResetError: [Errno 104] Connection reset by peer During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/env/local/lib/python3.7/site-packages/requests/adapters.py", line 445, in send timeout=timeout File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen _stacktrace=sys.exc_info()[2]) File "/env/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 367, in increment raise six.reraise(type(error), error, _stacktrace) File "/env/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 685, in reraise raise value.with_traceback(tb) File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request six.raise_from(e, None) File "", line 2, in raise_from File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request httplib_response = conn.getresponse() File "/opt/python3.7/lib/python3.7/http/client.py", line 1321, in getresponse response.begin() File "/opt/python3.7/lib/python3.7/http/client.py", line 296, in begin version, status, reason = self._read_status() File "/opt/python3.7/lib/python3.7/http/client.py", line 257, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/opt/python3.7/lib/python3.7/socket.py", line 589, in readinto return self._sock.recv_into(b) File "/opt/python3.7/lib/python3.7/ssl.py", line 1049, in recv_into return self.read(nbytes, buffer) File "/opt/python3.7/lib/python3.7/ssl.py", line 908, in read return self._sslobj.read(len, buffer) urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/user_code/main.py", line 230, in bq_merge archive_pending_blobs(bucket, blobs[min_idx:max_idx], pending_prefix, loaded_prefix) File "/user_code/main.py", line 44, in archive_pending_blobs raise e File "/user_code/main.py", line 40, in archive_pending_blobs bucket.copy_blob(b, bucket, b.name.replace(pending_prefix, loaded_prefix)) File "/env/local/lib/python3.7/site-packages/google/cloud/storage/bucket.py", line 711, in copy_blob _target_object=new_blob, File "/env/local/lib/python3.7/site-packages/google/cloud/_http.py", line 290, in api_request headers=headers, target_object=_target_object) File "/env/local/lib/python3.7/site-packages/google/cloud/_http.py", line 183, in _make_request return self._do_request(method, url, headers, data, target_object) File "/env/local/lib/python3.7/site-packages/google/cloud/_http.py", line 212, in _do_request url=url, method=method, headers=headers, data=data) File "/env/local/lib/python3.7/site-packages/google/auth/transport/requests.py", line 201, in request method, url, data=data, headers=request_headers, **kwargs) File "/env/local/lib/python3.7/site-packages/requests/sessions.py", line 512, in request resp = self.send(prep, **send_kwargs) File "/env/local/lib/python3.7/site-packages/requests/sessions.py", line 622, in send r = adapter.send(request, **kwargs) File "/env/local/lib/python3.7/site-packages/requests/adapters.py", line 495, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/env/local/lib/python3.7/site-packages/google/cloud/functions_v1beta2/worker.py", li
Per this StackOverflow answer about Connection reset by peer, seems like this is a fatal error were the remote server sends a RST packet to inmediatly drop the connection.
This other SO answer tackles how to solve it. The solution given is using time.sleep but, as we discussed on the comments, didn't work in your case. That's why I'm suggesting a different approach by using truncated exponential backoff:
Truncated exponential backoff is a standard error handling strategy for network applications in which a client periodically retries a failed request with increasing delays between requests.
[...]
Accessing Cloud Storage through a client library. Note that some client libraries, such as the Cloud Storage Client Library for Node.js, have built-in exponential backoff.
There's no built-in exponential backoff for Python, but there's an example of how handle retries in Python with this method.
I have implemented Google Assistant in RaspBerry PI B model with the latest OS. I have followed google's instructions from here.
Audio sample testing working fine.
Many times it is working.
.asoundrc file
pcm.!default{
type asym
playback.pcm{type plug slave.pcm "hw:0"}
capture.pcm{type plug slave.pcm "hw:1"}
}
ctl.!default{
type hw
card 0
}
Error :-
INFO:root:Recording audio request.
File "/usr/lib/python3.5/runpy.py", line 193, in _run_module_as_main"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_codeexec(code, run_globals)
File "/home/pi/teamaker/grpc/pushtotalk_back.py", line 337, in <module>main()
File "/home/pi/teamaker/grpc/env_local/lib/python3.5/site-packages/click/core.py", line 722, in __call__return self.main(*args, **kwargs)
File "/home/pi/teamaker/grpc/env_local/lib/python3.5/site-packages/click/core.py", line 697, in main\ rv = self.invoke(ctx)
File "/home/pi/teamaker/grpc/env_local/lib/python3.5/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/pi/teamaker/grpc/env_local/lib/python3.5/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/pi/teamaker/grpc/pushtotalk_back.py", line 326, in main
continue_conversation = assistant.converse()
File "/home/pi/teamaker/grpc/env_local/lib/python3.5/site-packages/tenacity/__init__.py", line 87, in wrapped_f
return r.call(f, *args, **kw)
File "/home/pi/teamaker/grpc/env_local/lib/python3.5/site-packages/tenacity/__init__.py", line 235, in call
do = self.iter(result=result, exc_info=exc_info)
File "/home/pi/teamaker/grpc/env_local/lib/python3.5/site-packages/tenacity/__init__.py", line 194, in iter
return fut.result()
File "/usr/lib/python3.5/concurrent/futures/_base.py", line 398, in result
return self.__get_result()
File "/usr/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
raise self._exception
File "/home/pi/teamaker/grpc/env_local/lib/python3.5/site-packages/tenacity/__init__.py", line 238, in call
result = fn(*args, **kwargs)
File "/home/pi/teamaker/grpc/pushtotalk_back.py", line 145, in converse
self.conversation_stream.stop_playback()
File "/home/pi/teamaker/grpc/audio_helpers.py", line 288, in stop_playback
self._source.stop()
File "/home/pi/teamaker/grpc/audio_helpers.py", line 222, in stop
self._audio_stream.stop()
File "/home/pi/teamaker/grpc/env_local/lib/python3.5/site-packages/sounddevice.py", line 1235, in stop
_check(err, 'Error stopping stream')
File "/home/pi/teamaker/grpc/env_local/lib/python3.5/site-packages/sounddevice.py", line 2671, in _check
raise PortAudioError(msg)
sounddevice.PortAudioError: Error stopping stream: Unanticipated host API 0 error -77: 'File descriptor in bad state'
I am trying to use Google Assistant SDK for the Raspberry Pi 3. I managed to install everything correctly, and the date is perfectly correct. However, when I try to Authorize the Google Assistant SDK sample, I get the error described in the title. It can't verify the certificate.
When I use date, the result is Thu Jun 29 17:16:42 CST 2017, which is very much correct at the time I use it. I am located in Costa Rica.
This is the complete error output.
Traceback (most recent call last):
File "/home/pi/env/lib/python3.4/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/home/pi/env/lib/python3.4/site-packages/urllib3/connectionpool.py", line 345, in _make_request
self._validate_conn(conn)
File "/home/pi/env/lib/python3.4/site-packages/urllib3/connectionpool.py", line 844, in _validate_conn
conn.connect()
File "/home/pi/env/lib/python3.4/site-packages/urllib3/connection.py", line 326, in connect
ssl_context=context)
File "/home/pi/env/lib/python3.4/site-packages/urllib3/util/ssl_.py", line 325, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib/python3.4/ssl.py", line 364, in wrap_socket
_context=self)
File "/usr/lib/python3.4/ssl.py", line 577, in __init__
self.do_handshake()
File "/usr/lib/python3.4/ssl.py", line 804, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/env/lib/python3.4/site-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/home/pi/env/lib/python3.4/site-packages/urllib3/connectionpool.py", line 630, in urlopen
raise SSLError(e)
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/env/bin/google-oauthlib-tool", line 11, in <module>
sys.exit(main())
File "/home/pi/env/lib/python3.4/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/home/pi/env/lib/python3.4/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/home/pi/env/lib/python3.4/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/pi/env/lib/python3.4/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/pi/env/lib/python3.4/site-packages/google_auth_oauthlib/tool/__main__.py", line 106, in main
creds = flow.run_console()
File "/home/pi/env/lib/python3.4/site-packages/google_auth_oauthlib/flow.py", line 358, in run_console
self.fetch_token(code=code)
File "/home/pi/env/lib/python3.4/site-packages/google_auth_oauthlib/flow.py", line 235, in fetch_token
**kwargs)
File "/home/pi/env/lib/python3.4/site-packages/requests_oauthlib/oauth2_session.py", line 221, in fetch_token
verify=verify, proxies=proxies)
File "/home/pi/env/lib/python3.4/site-packages/requests/sessions.py", line 549, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/home/pi/env/lib/python3.4/site-packages/requests_oauthlib/oauth2_session.py", line 360, in request
headers=headers, data=data, **kwargs)
File "/home/pi/env/lib/python3.4/site-packages/requests/sessions.py", line 502, in request
resp = self.send(prep, **send_kwargs)
File "/home/pi/env/lib/python3.4/site-packages/requests/sessions.py", line 612, in send
r = adapter.send(request, **kwargs)
File "/home/pi/env/lib/python3.4/site-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
I had the same problem. I found a guide saying the following dependencies are required. This fixed it for me.
sudo apt-get install portaudio19-dev libffi-dev libssl-dev
When trying to authorize access to the Google Assistant API from my Raspberry Pi, I get an error of “SSLError” type, stating that the certificate verification has failed.
When I run:
python -m googlesamples.assistant.auth_helpers --client-secrets <path-to-secrets-file>
I get the following trace:
Traceback (most recent call last):
File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/pi/env/lib/python3.4/site-packages/googlesamples/assistant/auth_helpers/__main__.py", line 54, in <module>
main()
File "/home/pi/env/lib/python3.4/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/home/pi/env/lib/python3.4/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/home/pi/env/lib/python3.4/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/pi/env/lib/python3.4/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/pi/env/lib/python3.4/site-packages/googlesamples/assistant/auth_helpers/__main__.py", line 48, in main
creds = credentials_flow_interactive(client_secrets, scope)
File "/home/pi/env/lib/python3.4/site-packages/googlesamples/assistant/auth_helpers/__init__.py", line 47, in credentials_flow_interactive
flow.run_console()
File "/home/pi/env/lib/python3.4/site-packages/google_auth_oauthlib/flow.py", line 358, in run_console
self.fetch_token(code=code)
File "/home/pi/env/lib/python3.4/site-packages/google_auth_oauthlib/flow.py", line 235, in fetch_token
**kwargs)
File "/home/pi/env/lib/python3.4/site-packages/requests_oauthlib/oauth2_session.py", line 221, in fetch_token
verify=verify, proxies=proxies)
File "/home/pi/env/lib/python3.4/site-packages/requests/sessions.py", line 535, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/home/pi/env/lib/python3.4/site-packages/requests_oauthlib/oauth2_session.py", line 360, in request
headers=headers, data=data, **kwargs)
File "/home/pi/env/lib/python3.4/site-packages/requests/sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "/home/pi/env/lib/python3.4/site-packages/requests/sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "/home/pi/env/lib/python3.4/site-packages/requests/adapters.py", line 497, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
How can I fix this?
One of the more likely issues for this to happen is your date and time being wrong. If your time/date is wrong, then try:
First change the date manually with the command date (see man page). For example:
sudo date -s "Mon Apr 24 13:30:00 PDT 2017"
If that works, but your time keeps desynchronizing with time, check out these instructions with several alternative solutions to ensure your time synchronizes properly.
Currently have made a flask application which crashes when I do a postgres database restart, because the cursor which was opened is stale ...
How do I handle this situation. Currently connecting the flask app to postgres via psycopg2....
I am not a database expert...
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/var/www/flaskapps/capp/override.py", line 15, in __call__
return self.app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1356, in full_dispatch_request
rv = self.preprocess_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1539, in preprocess_request
rv = func()
File "/usr/local/lib/python2.7/dist-packages/flask_login.py", line 321, in _load_user
self.reload_user()
File "/usr/local/lib/python2.7/dist-packages/flask_login.py", line 350, in reload_user
user = self.user_callback(user_id)
File "/var/www/flaskapps/capp/login_setup.py", line 163, in load_user
cursor.execute(qstr)
File "/usr/share/pyshared/psycopg2/extras.py", line 123, in execute
return _cursor.execute(self, query, vars)
InterfaceError: cursor already closed
This is one of the many cases where your code needs to detect a transient failure and re-try the transaction, re-opening the connection if necessary.
Other cases include deadlocks and serialization failures.
The sqlstate on the exception will let you determine which error cases to retry and how. See the PostgreSQL documentation on error codes for guidance on the meaning of the sqlstate codes.
Sometimes your database interface will through a typed exception that tells you enough just by its data type, too. This doesn't look like one of those cases.