the image size from significantly altering the bag feature magnitude, the histogram should be normalized.   Code:    from sklearn import svm ##########--WRITE YOUR CODE HERE--########## # The following steps are just for your reference # You can write in your own way

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

IN PYTH0N JUPYT3R N0TEB00K 

In order to represent our training and testing images as a bag of feature histograms, we must first create a visual language. By selecting a large number of local features (10s or 100s of thousands) from our training set and clustering them with k-means, we will create this vocabulary. The size of our vocabulary and the size of our features are measured by the number of k-means clusters. As an illustration, you might begin by grouping numerous SIFT descriptors into k=50 clusters. This divides the 128-dimensional continuous SIFT feature space into 50 regions. As long as we keep the centroids of our initial clusters, we can determine which region any new SIFT feature we find belongs to. These centroids represent our visual word wide range.

We display training and testing images as visual word histograms. Many SIFT descriptors will be densely sampled across each image. We simply count how many SIFT descriptors fit into each cluster in our visual word vocabulary rather than storing hundreds of SIFT descriptors. For each SIFT feature, the closest neighbor k-means centroid is located. Therefore, if we recognize 200 different SIFT features in an image and have a vocabulary of 50 visual words, our bag of SIFT representation will be a histogram with 50 dimensions, where each bin counts how many times a SIFT descriptor was to that cluster. There are 200 bin-counts in total. In order to prevent the image size from significantly altering the bag feature magnitude, the histogram should be normalized.

 

Code: 

 

from sklearn import svm

##########--WRITE YOUR CODE HERE--##########
# The following steps are just for your reference
# You can write in your own way
#
# def train_SVM(X, Y):
# return clf
#
# def predict_SVM(clf, X):
# return predict
#
# clf = train_SVM(train_feat, train_label)
#
# # make predictions on test data
# prediction = [-1]*len(test_feat)
# for i in range(len(test_feat)):
# prediction[i] = predict_SVM(clf, np.reshape(test_feat[i],(1,-1)))
#
# test_label_pred = np.reshape(np.array(predictions),(-1,))


#

def train_SVM(X, Y):
return clf

def predict_SVM(clf, X):
return predict
clf = train_SVM(train_feat, train_label)

prediction = [-1]*len(test_feat)
for i inrange(len(test_feat)):
prediction[i] = predict_SVM(clf, np.reshape(test_feat[i],(1,-1)))

test_label_pred = np.reshape(np.array(predictions),(-1,))



test_label_pred =

##########-------END OF CODE-------##########
accuracy = sum(np.array(test_label_pred) == test_label) / float(len(test_label))
print("The accuracy of Bag of SIFT Representation + one-vs-all SVMs model is {:.2f}%".format(accuracy*100))

 

 

 

Expert Solution
Step 1

from sklearn import svm

 

##########--WRITE YOUR CODE HERE--##########

# The following steps are just for your reference

# You can write in your own way

#

# def train_SVM(X, Y):

# return clf

#

# def predict_SVM(clf, X):

# return predict

#

# clf = train_SVM(train_feat, train_label)

#

# # make predictions on test data

# prediction = [-1]*len(test_feat)

# for i in range(len(test_feat)):

# prediction[i] = predict_SVM(clf, np.reshape(test_feat[i],(1,-1)))

#

# test_label_pred = np.reshape(np.array(predictions),(-1,))

 

 

#

 

def train_SVM(X, Y):

return clf

 

def predict_SVM(clf, X):

return predict

clf = train_SVM(train_feat, train_label)

 

prediction = [-1]*len(test_feat)

for i inrange(len(test_feat)):

prediction[i] = predict_SVM(clf, np.reshape(test_feat[i],(1,-1)))

 

test_label_pred = np.reshape(np.array(predictions),(-1,))

 

 

 

test_label_pred =

 

##########-------END OF CODE-------##########

accuracy = sum(np.array(test_label_pred) == test_label) / float(len(test_label))

print("The accuracy of Bag of SIFT Representation + one-vs-all SVMs model is {:.2f}%".format(accuracy*100))

 

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Designing Webpage
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education