Image classification using SVM Python - python

I am currently working on a projet to perform image recognition. There is a big set of images and I have to predict whether or not an image contains given characteristics.
For example, the output could be whether or not there is a banana in the picture.
I would like to implement a classifier using SVM with output yes or no the image contains the given characteristics. What is the simplest way to train a SVM classifier on images with 2 outputs? Is there any template to use in Python? Thanks a lot.

With SVM you can classify set of images.For example You can train svm with set of car and plane images.Once you trained it can predict the class of an unknown images as whether it is car or plane.There is also multiclass SVM.
In your case,Make two sets of images for training SVM
Set of images that contain given characteristics(banana)
Set of images that doesn't contain that characteristics
Once your training phase completed it will output to which class the given image belong.If its in banana class you can output as Yes otherwise No.
Usefull links
Hand written Digit Recognition using python opencv
Squirrel and Bird Classifier using java
Edit
Fruit classifier using python

Related

How to feed a series of dicom images into neural network?

Im new to DL and currently learning to develop classification model using PET-CT scans. Apparently there is a series of dcm images per patient. Might be dumb question but those who have developed DL classification models using pydicom, how do you feed those images into the neural network? I am familiar with normal classification, where the input would be something like:
Fruit Classification:
train folder
apples
apple1.jpg
apple2.jpg
apple3.jpg
other fruits...
For classification using PET-CT images:
train folder
class 1
patient1
first check up
dcm1
dcm2
dcmn
second check up
dcm1
dcm2
dcmn
patient2
first check up
dcm1
dcm2
dcmn ...
class others...
In tensorflow/pytorch, would normal loading work, even if there are many subfolders and files for each patient?

How to do classification based on different types of input

I want to know if there is any way to do a classification based on different input types.
Basically, I have the image dog vs cat dataset from Kaggle and also the sound dog vs cat dataset and I want to show that by combining models from audio alone and image alone we could get a better accuracy.
I read things on ensemble learning where we can combine different models with average precision to get a higher accuracy but these are doing the classification on same types of inputs whereas here I want to do classification by using image and audio as inputs. I also read things from Keras using mixed input but this work only for combining tabular data with images but not sound with images...
I did not find any labelled dataset of dog vs cat videos from which I could extract frames and audio and then apply a CNN on both to do the classification.
Do you have any idea on how to tackle this problem ?

Training SVM in Python with pictures

I have basic knowledge of SVM, but now I am working with images. I have images in 5 folders, each folder, for example, has images for letters a, b, c, d, e. The folder 'a' has images of handwriting letters for 'a, folder 'b' has images of handwriting letters for 'b' and so on.
Now how can I use the images as my training data in SVM in Python.
as far i understood you want to train your svm to classify these images into the classes named a,b,c,d . For that you can use any of the good image processing techniques to extract features (such as HOG which is nicely implemented in opencv) from your image and then use these features , and the label as the input to your SVM training (the corresponding label for those would be the name of the folders i.e a,b,c,d) you can train your SVM using the features only and during the inference time , you can simply calculate the HOG feature of the image and feed it to your SVM and it will give you the desired output.

Probability for correct Image Classification in Tensorflow

I am using Tensorflow retraining model for Image Classification. I am doing single label classification.
I want to set a threshold for correct classification.
In other words, if the highest probability is less than a given threshold, I can say that the image is "unknown" i.e. if np.max(results) < 0.5 -> set label as "unknown".
So, is there any industry standard to set this threshold. I can set a random value say 60%, but is there any literature to back this threshold ?
Any links or references will be very helpful.
Thanks a lot.
Single label classification is not something Neural Networks can do "off-the-shelf".
How do you train it ? With only data relevant to your target domain ? Your model will only learn to output one.
You have two strategies:
you use the same strategy as in the "HotDog or Not HotDog app", you put the whole imagenet in two different folders, one with the class you want, the other one containing everything else.
You use the convnet as feature extractor and then use a second model like a One-Class SVM.
You have to understand that doing one class classification is not a simple and direct problem like binary classification could be.

What it mean by Training SVM

I am new to image processing.As my project i am doing "image classifier using SVM".I have the idea of my final software "I select some image and give it as input to my software and it will classify that image .if i give the image of an animal it will classify it to cat or snake suitably"
When I google about it.it says "First you need to train SVM"
What it mean by Training SVM?
What is the actual input to SVM in my case(image classification)?
SVM is just a classifier how it classify images.Is it necessary for me to covert image to any particular format?.please help.
Support Vector Machine (SVM) is a machine learning model for supervised data classification. SVMs essentially learn a hyper-plane which separates the data space into 2 regions (in 2 class case). In your case, suppose you have images of snakes and cats and you need to classify them. The steps you'll need to follow are
Extract 'features' from the images.
These 'features' may be functions of appearance of snake/cat in your case e.g colour of the animal, shape of the animal etc. By concatenating these features you can get a multi-dimensional feature vector.
Train an SVM classifier
Training essentially learns a separating hyper-plane between the feature vectors of snake class and cat class . For example, if your feature vector is 2-dimensional, training an SVM classifier would amount to 'learning' a line which best separates your labeled-data/training-data.
You could use any of the multitude of freely available libraries of machine learning. In case you speak python, you could use sklearn for the task.
This task of learning (hyper-plane in linear SVM) is referred to training.
Classify the images.
Once you have trained your model, you could then use it classify images whose class is not known.
Note: I am simplifying a lot of details/issues involved in this answer. I suggest you should read-up about SVM

Categories