0
votes

I want to train a classifier to classify between "person with weapon" and "person without weapon". weapon can contain any weapon like revolver or assault riffle.
I have images with bounding boxes of weapons in the images. Images are of different sizes.
What I want to do?
I want to train SVM classifier using the raw image patches obtained using bounding box coordinates of weapons. For "person without weapon" i want to pass whole raw image as feature vector to SVM.
Limitations:
Each bounding box is of different size, that means a weapon of different size. I cant use PCA for these bounding boxes because i think it may result into loss of information because there are 3 different types of weapons with different sizes in images.Some bounding boxes cover almost whole image. So first i have to downscale image and bounding box because otherwise my memory runs out if i take whole image for PCA.
Question:
How can i train SVM using variable sized feature vector? To put in another way, How can I make all feature vectors of same size without losing information?

1
This question is so broad as to be off-topic. You could write a book on the answer and that book would probably still be "primarily opinion based". Flagging for close. - BadZen
StackOverflow is mainly for questions asking how to do sth., while you are asking about what to implement. You might be able to get better answers on e.g. DataScience.SE, SignalProcessing.SE or CrossValidated.SE - I am not sure which site would be best for such a question, please check their help pages and try to find similar questions before asking there. - hbaderts
Hope my answered helped. BTW, it's possible to make the feature vector into your SVM constant by accommodating for the variable size of patches but you cannot use the raw pixels. You must take each patch and convert it into a different feature space that will be constant before doing so. Something like a k-means dictionary is possible, combined with L1 normalization. - rayryeng

1 Answers

3
votes

Because you have variable-sized patches, there are a couple of ways you can handle the classification of these patches using a SVM. These have their advantages and disadvantages so you will have to decide what you think is best. Given that you have decided to choose a patch of size M x N for your images to be submitted into your SVM for classification, you can try one of the two following approaches:

Resize the input image patches

For each of your images at test time, resize them so that they all match the size of M x N, then run through the SVM classification pipeline to determine which class that image belongs to. The advantages of this are that the only information you are losing is due to the information lost when subsampling the images. However, the disadvantage is that if the image is smaller than the target patch size of M x N you will introduce bogus information when upsampling to match the target patch size. This kind of thing has been seen before especially in Deep Learning. Specifically, Region Proposal Networks by Ren et al. first take a look at what patches in a larger image are candidates to have an object or something worth taking a look at in the image, they then resize the patches to match the input layer into their neural network (convolutional btw) then proceed with the classification.

Search for patches over multiple scales

Another way is to keep the image size intact but using patch sizes of M x N, do a sliding window scheme where you extract overlapping patches of size M x N, submit these to your SVM then for each centre of each overlapping patch, determine what the class of that patch would be. You would do this over multiple scales then have a voting procedure where the most occurring class over the entire image is the class of interest. Something similar to this was seen in Semenet et al. for their Overfeat classification engine - also using convolutional neural networks. The advantage of this is that you don't lose any information in that you are using all (if not most) of the image information when classifying an object. The disadvantage is the amount of computation time required - specifically, the number of scales, the amount of overlap between windows and the patch size itself are all hyperparameters that you need to determine for the most optimal performance. This approach also assumes that the patch size is smaller than the image in question when scanning. You will have to be cognizant and choose patch sizes that are smaller than the largest image you have in your training dataset.

If I can recommend....

Because you are doing image classification, the algorithms that have the best performance in classification and for the sheer speed at test time would be convolutional neural networks. I would consider looking at those rather than using SVMs for performance. As a start, take a look at the AlexNet pipeline by Krizhevsky et al. as a start. This was the seminal work and how convolutional neural networks was placed on the map for computer vision tasks, such as classification, detection and so on.