how to do hog pca svm in dlib c++ - svm

i found an example here in book for pca of dlib
https://books.google.com.tw/books?id=ozDnDwAAQBAJ&pg=PA187&lpg=PA187&dq=dlib::vector_normalizer_pca+train&source=bl&ots=4jnTiSl1Mj&sig=ACfU3U23Tm922fkpJNu49oBpjzgZvr6R7w&hl=zh-TW&sa=X&ved=2ahUKEwjUy7G9pd72AhWgsFYBHeNCAMIQ6AF6BAgSEAM#v=onepage&q=dlib%3A%3Avector_normalizer_pca%20train&f=false
and functions in dlib
fhog_ex.cpp
extract_fhog_features(img, hog, sbin);
svm_c_ex.cpp
svm_c_trainer<kernel_type> trainer;
vector_normalizer_pca
https://github.com/PacktPublishing/Hands-On-Machine-Learning-with-CPP/blob/master/Chapter06/dlib/dlib-dr.cc
finally I want to do the detector in dlib
Anyone have any idea how to do it?

Related

opencv doesn't use all GPU memory

I'm trying to use the cvlib package which use yolov3 model to recognize objects on images on windows 10.
Let's take an easy example:
import cvlib as cv
import time
from cvlib.object_detection import draw_bbox
inittimer=time.time()
bbox, label, conf = cv.detect_common_objects(img,confidence=0.5,model='yolov3-worker',enable_gpu=True)
print('The process tooks %.3f s'%(time.time()-inittimer)
output_image = draw_bbox(img, bbox, label, conf)
The results give ~60ms.
cvlib use opencv to compute this cnn part.
If now I try to see how much GPU tensorflow used, using subprocess, It tooks only 824MiB.
while the program runs, if I start nvidia-smi it gives me this result:
As u can see there is much more memory available here. My question is simple.. why Cvlib (and so tensorflow) doesn't use all of it to improve the time's detection?
EDIT:
As far as I understand, cvlib use tensorflow but it also use opencv detector. I installed opencv using cmake and Cuda 10.2
I don't understand why but in the nvidia-smi it's written CUDA Version : 11.0 which is not. Maybe that's the part of the problem?
You can verify if opencv is using CUDA or not. This can be done using the following
import cv2
print(cv2.cuda.getCudaEnabledDeviceCount())
This should get you the number of CUDA enabled devices in your machine. You should also check the build information by using the following
import cv2
print cv2.getBuildInformation()
The output for both the above cases can indicate whether your opencv can access GPU or not. In case it doesn't access GPU then you may consider reinstallation.
I got it! The problem come from the fact that I created a new Net object for each itteration.
Here is the related issue on github where you can follow it: https://github.com/opencv/opencv/issues/16348
With a custom function, it now works at ~60 fps. Be aware that cvlib is, maybe, not done for real time computation.
workon opencv_cuda
cd opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE
and share the result.
It should be something like this

keras with theano backend runs lstm much slower on cpu

since keras with tensorflow backend can not reproduce results, i switch to theano. However, when i run the exactly same lstm model with exactly the same data,with theano backend is almost three times slower than with tensorflow backend. any suggestions?
I solved this by running the command "conda install -y mkl"

module 'sklearn.metrics' has no attribute 'davies_bouldin_score'

I am trying to evaluate a clustering kmeans model using sklearn.metrics.davies_bouldin_score. I am using google colab with runtime Python 3 and GPU accelerator.
I got this error:
module 'sklearn.metrics' has no attribute 'davies_bouldin_score'.
I have tried to import metrics package in different ways as it was suggested by some people as from sklearn import metrics and import sklearn.metrics. It made no difference.
I have also updated sklearn package !pip install --upgrade sklearn and it did not solve the problem.
Is it google-colaboratory? How can I solve it?
You need to pip install scikit-learn, not sklearn, though the import sklearn.metrics is correct. It looks like it's also a recently added feature, so it may not be available in earlier versions of scikit-learn.
It is in version 0.20. Make sure you are using the right version of Sklearn.
"conda update sklearn"

KNearestNeighbour is not running in multithread in Scikit-Learn

I'm succesfully using scikit-learn on my machine. I'm experimenting with an anaconda implemnetation (that relies on MKL for multithreading) and an openblas implementation.
I'd really like to use a parallel version of k-nearest neighbour classifier, and according to https://github.com/scikit-learn/scikit-learn/pull/4009 , sklearn should have merged this changes 1 year ago, in version 0.17.
Multithreading works successfully for PCA, and all numpy operations. I can tell multithreading is working due to high number of threads I can see when I do dot products and PCA. When I lunch KNN is taking around 10 minutes.
I’m classifying a high dimensional dataset of MNIST (image digits). So I’m doing PCA to get vector of dimension 35-50, and then I’m doing a nonlinear expansion, so I’m getting vector of dimension 600-100. That’s why I need parallelism so badly.
My version of sklearn is:
print('The scikit-learn version is {}.'.format(sklearn.version))
The scikit-learn version is 0.18.1.
I'm using python3 and this is a sample of the code:
def classify_knn(train, test, train_labels):
clf = KNeighborsClassifier(algorithm='ball_tree')
clf = clf.fit(train, train_labels)
return clf.predict(test)
I've tried with and without 'ball_tree'. No one should using python 2.7 in 2017 and neither do I.
Just passing as a parameter
n_jobs = -1
solved the issue.

sklearn: Regression models on sparse data?

Does python's scikit-learn have any regression models that work well with sparse data?
I was poking around and found this "sparse linear regression" module, but it seems outdated. (It's so old that scikit-learn was called 'scikits-learn' at the time, I think.)
Most scikit-learn regression models (linear such as Ridge, Lasso, ElasticNet or non-linear, e.g. with RandomForestRegressor) support both dense and sparse input data recent versions of scikit-learn (0.16.0 is the latest stable version at the time of writing).
Edit: if you are unsure, check the docstring of the fit method of the class of interest.

Resources