I am new to deep learning, I was wondering if there is a way to extract parts of images containing the different label and then feed those parts to different model for further processing?
For example,consider the dog vs cat classification.
Suppose the image contains both cat and dog.
We successfully classify that the image contains both, but how can we classify the breed of the dog and cat present?
The approach I thought of was,extracting/cutting out the parts of the image containing dog and cat.And then feed those parts to the respective dog breed classification model and cat breed classification model separately.
But I have no clue on how to do this.
Your thinking is correct, you can have multiple pipelines based on the number of classes.
Training:
Main model will be an object detection and localization model like Faster RCNN, YOLO, SSD etc trained to classify at a high level like cat and dog. This pipeline provides you bounding box details (left, bottom, right, top) along with the labels.
Sub models will be multiple models trained on a lover level. For example a model that is trained to classify breed. This can be done by using models like vgg, resnet, inception etc. You can utilize transfer learning here.
Inference: Pass the image through Main model, crop out the detection objects using bounding box details (left, bottom, right, top) and based on the label information, feed it appropriate sub model and extract the results.
Related
I made a simple CNN that classifies dogs and cats and I want this CNN to detect images that aren't cats or dogs and this must be a third different class. How to implement this? should I use R-CNN or something else?
P.S I use Keras for CNN
What you want to do is called "transfer learning" using the learned weights of a net to solve a new problem.
Please note that this is very hard and acts under many constraints i.e. using a CNN that can detect cars to detect trucks is simpler than using a CNN trained to detect people to also detect cats.
In any case you would use your pre-trained model, load the weights and continue to train it with new data and examples.
Whether this is faster or indeed even better than simply training a new model on all desired classes depends on the actual implementation and problem.
Tl:Dr
Transfer learning is hard! Unless you know what you are doing or have a specific reason, just train a new model on all classes.
You can train that almost with the same architecture (of course it depends on this architecture, if it is already bad then it will not be useful on more classes too. I would suggest to use the state of the art model architecture for dogs and cats classification) but you will also need the dogs and cats dataset in addition to this third class dataset. Unfortunately, it is not possible to use pre-trained for making predictions between all 3 classes by only training on the third class later.
So, cut to short, you will need to have all three datasets and train the model from scratch if you want to make predictions between these three classes otherwise use the pre-trained and after training it on third class it can predict if some image belongs to this third class of not.
You should train with new_category by add one more category, it contains images that are not in 2 category before. I mean
--cat_dir
-*.jpg
--dog_dir
-*.jpg
--not_at_all_dir
-*.jpg
so.. total categories you will train are 3 categories.
(categories or classes whatever it is)
then add the output of final dense fullyconnected (3 categories)
i want to classify two classes with CNN.
first class are objects(car, building, and so go an)
secound class are NoObjects(for example Background without objects)
So, the question is, how can I realize this? I want to have many objects images for the CNN. I saw a example with Cat and Dog.. But I have only images for one class. The other class are the background. It is possible to create a background class??
I´m very new in CNN..
It seems that you're talking about semantic segmentation, where you have a variable N number of classes to localize (in this case N=1) plus the background class. There's a lot of literature and baseline models out there that can help you out. I recommend these two since they're the most popular ones:
Pretrained models: Tensorflow's model zoo
Datasets: Specifically COCO
I'm building CNN that will tell me if a person has brain damage. I'm planning to use tf inception v3 model, and build_image_data.py script to build TFRecord.
Dataset is composed of brain scans. Every scan has about 100 images(different head poses, angles). On some images, damage is visible, but on some is not. I can't label all images from the scan as a damage positive(or negative), because some of them would be labeled wrong(if scan is positive on damage, but that is not visible on specific image).
Is there a way to label the whole scan as positive/negative and in that way train the network?
And after training is done, pass scan as input to network(not single image) and classify it.
It looks like multiple instance learning might be your approach. Check out these two papers:
Multiple Instance Learning Convolutional Neural
Networks for Object Recognition
Classifying and segmenting microscopy images
with deep multiple instance learning
The last one is implemented by #dancsalo (not sure if he has a stack overflow account) here.
I looks like the second paper deals with very large images and breaks them into sub images, but labels the entire image. So, it is like labeling a bag of images with a label instead of having to make a label for each sub-image. In your case, you might be able to construct a matrix of images, i.e. a 10 image x 10 image master image for each of the scans...
Let us know if you do this and if it works well on your data set!
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
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