bikz05 / bag-of-words Goto Github PK
View Code? Open in Web Editor NEWPython Implementation of Bag of Words for Image Recognition using OpenCV and sklearn
Python Implementation of Bag of Words for Image Recognition using OpenCV and sklearn
Can you please let us know how to evaluate the trained model? I mean the confusion matrix and classfication_report functions in scikit-learn.
Hi, bikz05
There is another problem in findFeatures.py
. The code:
# Stack all the descriptors vertically in a numpy array
descriptors = des_list[0][1]
for image_path, descriptor in des_list[0:]:
descriptors = np.vstack((descriptors, descriptor))
I think it's should be as follows:
# Stack all the descriptors vertically in a numpy array
descriptors = des_list[0][1]
for image_path, descriptor in des_list[1:]:
descriptors = np.vstack((descriptors, descriptor))
Hi,
I've got some error after ruuning the training with python findFeatures.py -t dataset/train/
which states
Traceback (most recent call last):
File "findFeatures.py", line 35, in
fea_det = cv2.FeatureDetector_create("SIFT")
AttributeError: module 'cv2' has no attribute 'FeatureDetector_create'
Could you publish the packages version you have used for this build so I'll check if I'm using the same opencv version?
Thanks,
Shahar
When i am excecuting
python findFeatures.py -t dataset/train/
it shows -
Segmentation fault (core dumped)
plz help.
I get this error when trying to run getClass.py
with the args -t dataset/test --visualize.
I think this is an issue with LinearSVC and not my end, but I wanted to make sure.
predictions = [classes_names[i] for i in clf.predict(test_features)] File "C:\Python27\lib\site-packages\sklearn\linear_model\base.py", line 228, in predict return self._classes_[indices] AttributeError: 'LinearSVC' object has no attribute 'classes_'
Anyone having this issue?
Hi, bikz05
It seems you don't make use of the computed idf
# Perform Tf-Idf vectorization
nbr_occurences = np.sum( (im_features > 0) * 1, axis = 0)
idf = np.array(np.log((1.0*len(image_paths)+1) / (1.0*nbr_occurences + 1)), 'float32')
# Scaling the words
stdSlr = StandardScaler().fit(im_features)
im_features = stdSlr.transform(im_features)
I think for each im_features[i] it should multiply the idf to make full use of it, that is:
im_features = im_features*idf
Don't you think so?
Traceback (most recent call last):
File "findFeatures.py", line 35, in
fea_det = cv2.FeatureDetector_create("SIFT")
AttributeError: module 'cv2' has no attribute 'FeatureDetector_create'
Hi,
First thanks the script seems quite nice.
I try to run it with 103 classes, so i basically replaced the folder in train directory by new folders, named after my classes, and containing 50 images each.
So, as guessed, it take 45/50min to run... but then i always get that error : "ValueError: all the input array dimensions except for the concatenation axis must match exactly" the error comes from ligne 50 when stacking the descriptors...
My folders are as the picture... any idea what is wrong??
ps : when using your code "out of the box" it runs perfectly
PS2 : solved it
Hello! You've done a wonderful job! I wanted to run these codes from another python scripts. How should I do it ? Please Help! :)
Hi.
I am using ORB features instead of SIFT features.
I am facing an issue while performing clustering on the images.
Please find the code snippet.
``
orb = cv2.ORB()
des_list = []
for image_path in image_paths:
im = cv2.imread(image_path)
is_cv3 = cv2.version.startswith("3.")
if(is_cv3):
detector = cv2.ORB_create()
else:
detector = cv2.ORB()
kpts = detector.detect(im)
kpts, des = detector.compute(im,kpts)
img_temp = np.zeros((1,1))
img_four = cv2.drawKeypoints(im,kpts,img_temp,color = (0,255,0), flags = 0)
des_list.append((image_path, des))
descriptors = des_list[0][1]
for image_path, descriptor in des_list[1:]:
descriptors = np.vstack((descriptors, descriptor))
k = 100
voc, variance = kmeans(descriptors, k, 1)
im_features = np.zeros((len(image_paths), k), "float32")
for i in xrange(len(image_paths)):
words, distance = vq(des_list[i][1],voc)
for w in words:
im_features[i][w] += 1
I am facing the following error:-
Traceback (most recent call last):
File "findFeatures.py", line 133, in
words, distance = vq(des_list[i][1],y_kmeans[:500,])
File "/usr/local/lib/python3.5/dist-packages/scipy/cluster/vq.py", line 211, in vq
return _vq.vq(c_obs, c_code_book)
File "_vq.pyx", line 211, in scipy.cluster._vq.vq
ValueError: observation and code should have same number of dimensions.
Please provide me with the solution to the problem.
I got this error while training the data, please help!!
File "findFeatures.py", line 50, in
descriptors = np.vstack((descriptors, descriptor))
File "/usr/lib/python2.7/dist-packages/numpy/core/shape_base.py", line 228, in vstack
return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
ValueError: all the input array dimensions except for the concatenation axis must match exactly
Thanks for your work. Really great job. I have modified the code by removing the arguments and to run the code from python idle. For a single image. Can i make it real time by using a webcam?
findFeatures.txt
getClass.txt
Regards
Rahul
from scipy.cluster.vq cannot import name 'xrange'
kmeans isn't defined anywhere in getFeatures.py
Please tell me how to find accuracy of the model.
i have this error:
Traceback (most recent call last):
File "findFeatures.py", line 35, in
fea_det = cv2.FeatureDetector_create("SIFT")
AttributeError: 'module' object has no attribute 'FeatureDetector_create'
Error appears while training:
Traceback (most recent call last):
File "findFeatures.py", line 56, in
for i in xrange(len(image_paths)):
NameError: name 'xrange' is not defined
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.