My System Configuration:
Windows 10,
Nvidia 940mx 2GB GDDR5 GPU, 8GB RAM, i5 8th generation.
Software installed:
CUDA toolkit 9.0
cuDNN 7.1.4
I have successfully installed dlib with GPU support after installing above requirements using commands below:
$ git clone https://github.com/davisking/dlib.git
$ python setup.py install --clean
As stated by dlib's creater #Davis King, on my jupyter notebook I executed :
import dlib
dlib.DLIB_USE_CUDA
[Out 17] :True
Which verifies that my 'dlib' is using GPU through CUDA, and all other libraries depend on dlib like #adma ageitgey's 'face_recognition' will also use cuda acceleration.
So I was running a code for training images so that I can recognize faces in a video, using the code below:
import face_recognition
img = face_recognition.load_image_file('./training images/John_Cena/Gifts-John-Cena-Fans.jpg')
locations = face_recognition.face_loactions(img,model='cnn')
It prints the error as stated below:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Tushar\Anaconda3\lib\site-packages\face_recognition\api.py", line 116, in face_locations
return [_trim_css_to_bounds(_rect_to_css(face.rect), img.shape) for face in _raw_face_locations(img, number_of_times_to_upsample, "cnn")]
File "C:\Users\Tushar\Anaconda3\lib\site-packages\face_recognition\api.py", line 100, in _raw_face_locations
return cnn_face_detector(img, number_of_times_to_upsample)
RuntimeError: Error while calling cudaMalloc(&data, n) in file C:\Users\Tushar\Desktop\face_recognition\dlib\dlib\cuda\cuda_data_ptr.cpp:28. code: 2, reason: out of memory
After trying again for another image :
img = face_recognition.load_image_file('./training images/John_Cena/Images.jpg')
locations = face_recognition.face_loactions(img,model='cnn')
It gave error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Tushar\Anaconda3\lib\site-packages\face_recognition\api.py", line 116, in face_locations
return [_trim_css_to_bounds(_rect_to_css(face.rect), img.shape) for face in _raw_face_locations(img, number_of_times_to_upsample, "cnn")]
File "C:\Users\Tushar\Anaconda3\lib\site-packages\face_recognition\api.py", line 100, in _raw_face_locations
return cnn_face_detector(img, number_of_times_to_upsample)
RuntimeError: Error while calling cudnnConvolutionForward( context(), &alpha, descriptor(data), data.device(), (const cudnnFilterDescriptor_t)filter_handle, filters.device(), (const cudnnConvolutionDescriptor_t)conv_handle, (cudnnConvolutionFwdAlgo_t)forward_algo, forward_workspace, forward_workspace_size_in_bytes, &beta, descriptor(output), output.device()) in file C:\Users\Tushar\Desktop\face_recognition\dlib\dlib\cuda\cudnn_dlibapi.cpp:1007. code: 3, reason: CUDNN_STATUS_BAD_PARAM
Then I restarted the jupyter's kernel and tried once again for different image :
face_recognition.face_locations(face_recognition.load_image_file('./training
images/John_Cena/images.jpg'),model='cnn')
[Out] : [(21, 136, 61, 97)]
This time it gave the coordinates of the location of the face in the image.
So this is happening again and again, for some images it just runs fine and for some, it gives one of the 2 errors(as stated above).
While using model='hog' it's running fine for all the similar images as used in model='cnn'.
So when I try to train the classifier on images in different folders using for loop:
from face_recognition.face_detection_cli import image_files_in_folder
import os
import os.path
import face_recognition
for class_dir in os.listdir('./training images/'):
count = 0
for img_path in image_files_in_folder(os.path.join('./training images/', class_dir)):
count += 1
image = face_recognition.load_image_file(img_path)
face_bounding_boxes = face_recognition.face_locations(image,model='cnn')
print(face_bounding_boxes, count)
It always stops after processing some images showing the same any of 2 errors(as stated above).
I tried every possible way to install dlib with GPU support, CUDA 9.0 toolkit and cuDNN 7.1.4. They all are working fine!
I don't know what's the real issue here, Is the memory (2 GB) of Graphic Card is less or something else.
I really want to use GPU's power to make recognition in video faster.
I found that face_encodings is given quick "Indexerror" if the face is slighty rotate and not straight. Despite It found the face locations with the coordinates and when supply the crop image with the coordinates to "face_encodings" it failed with the index error...
Related
I got a new m1 MacBook Pro and installed the TensorFlow 2 provided by Apple, and I decided to do some testing for the MacBook, so I installed the python3 package "AIBenchmark", and the process was successful without any error messages. However, when I imported it, the following error message appeared.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/andrew/tensorflow_macos_venv/lib/python3.8/site-packages/ai_benchmark/__init__.py",
line 5, in <module>
from ai_benchmark.utils import *
File "/Users/andrew/tensorflow_macos_venv/lib/python3.8/site-packages/ai_benchmark/utils.py",
line 10, in <module>
from PIL import Image
File "/Users/andrew/tensorflow_macos_venv/lib/python3.8/site-packages/PIL/Image.py",
line 94, in <module>
from . import _imaging as core ImportError: dlopen(/Users/andrew/tensorflow_macos_venv/lib/python3.8/site-packages/PIL/_imaging.cpython-38-darwin.so,
2): no suitable image found. Did find:
/Users/andrew/tensorflow_macos_venv/lib/python3.8/site-packages/PIL/_imaging.cpython-38-darwin.so:
mach-o, but wrong architecture
/Users/andrew/tensorflow_macos_venv/lib/python3.8/site-packages/PIL/_imaging.cpython-38-darwin.so:
mach-o, but wrong architecture
How do I solve this problem?
I'm guessing that since AI Benchmark has not been updated since Dec. 18, 2019, the library is an Intel architecture binary. I don't know the details of the python 3.8 installation via the Xcode Command Line Tools, but I imagine it's a universal binary (both Intel and Apple Arm64 architecture). My guess is that you'll have to run TensorFlow as an Intel binary, so I would try the following in the terminal: precede your command to startup your app with
arch -x86_64
Or, configure Terminal to run under Rosetta2.
Right-click on Terminal in Finder
Get Info
Open with Rosetta
More suggestions here (no, it's not python or TensorFlow related, but yes, it's relevant).
I am trying to run a python package that requires pytorch-gpu. I have change the runtime type of my Colab notebook to GPU. When I run the command, I am facing the following error. Not sure if I am able to build pytorch on colab myself?
Traceback (most recent call last):
File "inference_unet.py", line 9, in <module>
import torchvision.transforms as transforms
File "/usr/local/lib/python3.6/dist-packages/torchvision/__init__.py", line 10, in <module>
from .extension import _HAS_OPS
File "/usr/local/lib/python3.6/dist-packages/torchvision/extension.py", line 58, in <module>
_check_cuda_version()
File "/usr/local/lib/python3.6/dist-packages/torchvision/extension.py", line 54, in _check_cuda_version
.format(t_major, t_minor, tv_major, tv_minor))
RuntimeError: Detected that PyTorch and torchvision were compiled with different CUDA versions. PyTorch has CUDA Version=10.2 and torchvision has CUDA Version=10.1. Please reinstall the torchvision that matches your PyTorch install.
Now you can directly use pytorch-gpu on google colab, no need of installation.
Just change your runtime to gpu, import torch and torchvision and you are done.
I have attached screenshot doing just the same.
Hope the answer will find helpful.
But in case you want to install different version of pytorch or any other package then you can install using pip, just add ! before your pip command and run the cell.
for example,
As in title I have
CUDA 9.0.176
cuDNN v7.4.1
TF-GPU 1.12
Python 3.6.6
I can confirm that path both to bin/lib for CUDA is in a PATH and also there is a path to cuda folder (not sure why if same files were copieed to CUDA folder (nvidia not a custom one as per tutorials)).
import tensorflow
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\OtherCode\Teest1\test1\lib\site-
packages\tensorflow\__init__.py", line 22, in <module>
from tensorflow.python import pywrap_tensorflow # pylint:
disable=unused-import
File "D:\OtherCode\Teest1\test1\lib\site-
packages\tensorflow\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "D:\OtherCode\Teest1\test1\lib\site-
packages\tensorflow\core\framework\graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "D:\OtherCode\Teest1\test1\lib\site-
packages\google\protobuf\descriptor.py", line 47, in <module>
from google.protobuf.pyext import _message
ImportError: DLL load failed: The specified procedure could not be found.
I've tried pretty much many other different bundles after that (using Tensorflow table showing tested configurations), but none of them works.
I have all files in System32 that I've found info about, I have VS 2017 / 2019 + install the compile for 2015.
Nothing works.
Is there anything on Windows that I need to be aware of ?
Same bundle works fine on Ubuntu pretty much instantly, on Windows it fails terribly.
I would prefer use windows as there is number of issues with ubuntu (most of hardware is not supported on Ubuntu + I am using VS Studio for most of the projects).
I've tried CUDA 8.0, CUDA 9.0, CUDA 9.2, CUDA 10 (with different cuDNN for specific version + different tensorflows according to the table, however it looks like there is something else missing).
Unfortunately for some reason this combo won't work.
Other with CUDA 10 worked.
I try to set up the pyFMI on Anaconda (Python 3.6.8)
Installed all the required packages listed on the pyFMI site. The fmu is loaded without the issue but while I try to simulate the fmu I get an error:
Could not find cannot import name 'radau5'
Could not find cannot import name 'dopri5'
Could not find cannot import name 'rodas'
Could not find cannot import name 'odassl'
Could not find ODEPACK functions.
Could not find RADAR5
Could not find GLIMDA.
Traceback (most recent call last):
File "assimulo\solvers\../lib/sundials_callbacks_ida_cvode.pxi", line 240, in assimulo.solvers.sundials.cv_jac
File "C:\Users\d60378\AppData\Local\Continuum\anaconda3\lib\site-packages\pyfmi\simulation\assimulo_interface.py", line 733, in j
A = self._model._get_A(add_diag=True, output_matrix=self._A)
File "src\pyfmi\fmi.pyx", line 6041, in pyfmi.fmi.FMUModelBase2._get_A
File "src\pyfmi\fmi.pyx", line 7592, in pyfmi.fmi.FMUModelME2._get_directional_proxy
File "src\pyfmi\fmi.pyx", line 5989, in pyfmi.fmi.FMUModelBase2._get_directional_proxy
TypeError: Expected tuple, got dict_keys
Traceback (most recent call last):
File "<ipython-input-1-6c340902ef15>", line 28, in <module>
res = model.simulate(options=opts,start_time=tstart, final_time=tstart+172200)
File "src\pyfmi\fmi.pyx", line 7522, in pyfmi.fmi.FMUModelME2.simulate
File "src\pyfmi\fmi.pyx", line 304, in pyfmi.fmi.ModelBase._exec_simulate_algorithm
File "src\pyfmi\fmi.pyx", line 300, in pyfmi.fmi.ModelBase._exec_simulate_algorithm
File "C:\Users\d60378\AppData\Local\Continuum\anaconda3\lib\site-packages\pyfmi\fmi_algorithm_drivers.py", line 520, in solve
self.simulator.simulate(self.final_time, self.ncp)
File "assimulo\ode.pyx", line 168, in assimulo.ode.ODE.simulate
File "assimulo\ode.pyx", line 288, in assimulo.ode.ODE.simulate
File "assimulo\explicit_ode.pyx", line 101, in assimulo.explicit_ode.Explicit_ODE._simulate
File "assimulo\explicit_ode.pyx", line 187, in assimulo.explicit_ode.Explicit_ODE._simulate
File "assimulo\solvers\sundials.pyx", line 1894, in assimulo.solvers.sundials.CVode.integrate
File "assimulo\solvers\sundials.pyx", line 1926, in assimulo.solvers.sundials.CVode.integrate
CVodeError: {-1: 'The solver took max internal steps but could not reach tout.', -2: 'The solver could not satisfy the accuracy demanded by the user for some internal step.', -3: 'Error test failures occurred too many times during one internal time step or minimum step size was reached.', -4: 'Convergence test failures occurred too many times during one internal time step or minimum step size was reached.', -5: 'The linear solvers initialization function failed.', -6: 'The linear solvers setup function failed in an unrecoverable manner.', -7: 'The linear solvers solve function failed in an unrecoverable manner.', -8: 'The user-provided rhs function failed in an unrecoverable manner.', -9: 'The right-hand side function failed at the first call.', -10: 'The right-hand side function had repeated recoverable errors.', -11: 'The right-hand side function had a recoverable error, but no recovery is possible.', -12: 'The rootfinding function failed in an unrecoverable manner.', -20: 'A memory allocation failed.', -21: 'The cvode_mem argument was NULL.', -22: 'One of the function inputs is illegal.', -23: 'The CVode memory block was not allocated by a call to CVodeMalloc.', -24: 'The derivative order k is larger than the order used.', -25: 'The time t is outside the last step taken.', -26: 'The output derivative vector is NULL.', -27: 'The output and initial times are too close to each other.', -41: 'The sensitivity right-hand side function failed unrecoverable.'}
Would appreciate any hints where to look for the possible issue.
Kelamahim, how have you installed the PyFMI package? I have used
conda install -c chria pyfmi
and it works.
Only
Could not find RADAR5
Could not find GLIMDA are shown in the execution, but my models works. Hope this helps.
The solution is downgrading to Anaconda 3 Python 3.6.2 and installing with conda the pyfmi version 2.4.0
I have been using Anaconda2 (Conda 4.6.8/python 2.7.15). Here's the installation process:
FMIL is built from source code using CMake
pyfmi is installed via conda install -c chria pyfmi
assimulo is installed via conda install -c conda-forge assimulo
wxPython 2.8.12.1 (classic) is installed via the Windows installer available on sourceforge
Other dependencies can be installed from pip
I also saw the following warning messages after loading pyfmi in python, but my simulation doesn't seem to be affected:
Could not find cannot import name radau5
Could not find cannot import name dopri5
Could not find cannot import name rodas
Could not find cannot import name odassl
Could not find ODEPACK functions.
Could not find RADAR5
Could not find GLIMDA.
HTH
pyFMi is also available from the conda-forge channel:
https://anaconda.org/conda-forge/pyfmi
I permanentely added that channel, because it has reproducible builds and a huge number of packages, so usually dependencies can be resolved.
The following worked for me, in Anaconda3 with Python 3.6:
conda config --append channels conda-forge
conda install pyfmi
conda list
So i finally managed to get theano up and running on the GPU using this guide. (the test code runs fine, telling me it used the GPU, YAY!!)
I then wanted to try it out and followed this guide for training a CNN on digit recognition.
problem is: i get errors from the way lasagne calls theano (i guess there is a version mismatch here):
Using gpu device 0: GeForce GT 730M (CNMeM is disabled, cuDNN not available)
Traceback (most recent call last):
File "C:\Users\Soren Jensen\Desktop\CNN-test\CNNTest-one.py", line 7, in <module>
import lasagne
File "C:\Users\Soren Jensen\Anaconda3\lib\site-packages\lasagne\__init__.py", line 19, in <module>
from . import layers
File "C:\Users\Soren Jensen\Anaconda3\lib\site-packages\lasagne\layers\__init__.py", line 7, in <module>
from .pool import *
File "C:\Users\Soren Jensen\Anaconda3\lib\site-packages\lasagne\layers\pool.py", line 6, in <module>
from theano.tensor.signal import downsample
ImportError: cannot import name 'downsample'
Press any key to continue . . .
From reading about the error message, it seems that 'downsample' was changed, so why is my lasagne still calling it??
trying to update my lasagne version gives:
C:\WINDOWS\system32>pip3.5 install Lasagne==0.1
Collecting Lasagne==0.1
Requirement already satisfied: numpy in c:\users\soren jensen\anaconda3\lib\site-packages (from Lasagne==0.1)
and running the code sample
import theano
import os
print(theano.config.compiledir)
print("Theano version %s" % theano.__version__)
theano_dir = os.path.dirname(theano.__file__)
print("theano is installed in %s" % theano_dir)
reveals that python3.5 uses theano v 0.9
Using gpu device 0: GeForce GT 730M (CNMeM is disabled, cuDNN not available)
C:\theano_compiledir\compiledir_Windows-10-10.0.14393-SP0-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.2-64
Theano version 0.9.0.dev-e5bedc0de240eca42433c34c05fc00f4a5ef6cbe
theano is installed in C:\Users\Soren Jensen\Anaconda3\lib\site-packages\theano\theano
Press any key to continue . . .
Sorry for the long post, but i'm going a little crazy of this not working.. Maybe i am wrong in the version mismatch and the error is something else?
Try to reinstall Theano and Lasagne like this:
pip install --upgrade https://github.com/Theano/Theano/archive/master.zip
pip install --upgrade https://github.com/Lasagne/Lasagne/archive/master.zip
Because: "An even more recent version of Theano will often work as well, but at the time of writing, a simple pip install Theano will give you a version that is too old."
Read more: lasagne.readthedocs.io/en/latest/user/installation.html