I have 5 folders (each contain about 200 RGB images), I want to use "Principal Component Analysis" for image classification - components

I have 5 folders (which represent 5 classes, and each contain about 200 colored images), I want to use "Principal Component Analysis" for image classification.
previously I used Resnet to predict to which class each image belong. but now I want to use the PCA.
I am trying to apply that with code, any help please?
previously I used Resnet to predict to which class each image belong. but now I want to use the PCA.

PCA is not a method for classification. It is a dimensional reduction method that is sometimes used as a processing step.
Take a look at this CrossValidated post for some more explanation. It has an example.
(FYI, saw this because you pinged me via the MATLAB Answers forum.)

Related

Keras Multi-Class Image Segmentation - number of classes?

Apologies if this is a stupid question but I have a dataset with two classes I wish to attempt to classify using a U-Net.
When creating the label matrices, do I need to explicitly define the null / base class (everything which isn't a class) or will Keras calculate this automatically?
For example, if I have a set of images where I'd like to classify the regions where there is a dog or where this is a cat, do I need to create a third label matrix which labels everything which is not a dog or cat (and thus, have three classes)?
Furthermore, the null class dominates the images I'm wishing to segment; if I were to use a class_weight, it seems to only accept a dictionary as input whereas I swear before I good specify a list and that would suffice.
If I treat my problem as a two-class problem, I'm assuming I need to specify the weight of the null class too, i.e. class_weight = [nullweight, dogweight, catweight].
Thank you
edit: Attached example
Is this above image a two class or three class problem?
You must specify the other class since the network needs to differentiate between the dog, the cat and the background.
As for the class_weights parameter, the discussion is a little bit more complicated, you cannot assign like you would do in a simple classification problem.
Indeed, in many problems the background constitutes a big part of the image so you need to be careful when approaching such an imbalanced problem.
You need to inspect the parameter sample_weights, not class_weights, you can have a look at these threads:
https://datascience.stackexchange.com/questions/31129/sample-importance-training-weights-in-keras
https://github.com/keras-team/keras/issues/3653
Weighting samples in multiclass image segmentation using keras
image-segmentation-using-keras

How should I do the classification of images with different orientation?

I have been working on a dataset in which the goal is to determine that which type of orientation is it. It is a classification problem in which for each record(for most of them) I am having 4 images - front facing, left facing, right facing and back facing product images.
I want to classify these images in the above 4 categories.
The dataset looks like this :
I have downloaded the images and put them in different folders according to their classes.
Methods I have applied:
Till now I have applied two methods to classify these images.
1) I have tried vgg16 directly to classify the images but it did not give me even 50% accuracy.
2) I converted those images into edge images with black background as:
This is done using canny edge detection. It was done because in the result I was getting images with similar color dresses, similar design dresses, etc.
On top of these I again applied vgg16, resnet50, inception models but nothing seemed to work.
Can you suggest some ideas that can work in my case and classify the images in a better way.
first of all yor data set has to be equally splited. For instance 80% train and 20% test. After that you have to balance these sets (train set 60% of class A images, 40% of class B images) the exact same for test set.

Making mask files for Tensorflow segmentation/object detection API

In the article for creating a dataaset for the TF object detection API [link], users are asked to store an object mask as:
a repeated list of single-channel encoded PNG strings, or a single dense 3D binary tensor where masks corresponding to each object are stacked along the first dimension
Since the article strongly suggests using a repeated list of single-channel encoded PNG strings, I would particularly be interested in knowing how to encode this. My annotations are typically from csv files, which I have no problem in generating the TFRecords file. Are there any instructions somewhere on how to make this conversion?
i make it works with pet dataset , on tensorflow you have 2 way with coco dataset tf record and with pet_tfrecord.
the first took JSON file
the second take XML and PNG
there is one application VGG could make annotations in PNG or in JSON, then you use the directory tree needed, i used the pet dataset example. but finally mask is not displayed, even with the example dataset...
Rather than the array of png, I ended up using a dense tensor, where each pixel value represents a class.
Note,, I’ve seen many other people who didn’t use sequential numbers and ended up having problems later. The idea makes sense, if I have 2 classes, label 1 as 0 and the other as 255. The rationale is that when you see this in grayscale it is obvious what gets labeled 1 or 255. This is impossible when you use 0,1,2,... However, this violates a lot of assumptions in downstream code (e.g. deeplab)

How to visualize filters after the 1st layer trained by CNNs?

The filters at the 1st stage of the CNN can be easily visualized since they are of depth 3 (RGB). How do I visualize the later ones ? Like in http://cs231n.stanford.edu/slides/winter1516_lecture7.pdf
If the 2nd stage filter has depth more than 3, how can i visualize it like in the figure above ? Is it still in RGB or ?
I believe, those pictures can be generated with a method from zeilerECCV2014 paper, given a pre-trained network and an image dataset. It is done in two steps:
pick images from a dataset that give strongest response.
using backpropagation, generate minimal input images that would give that same response. Those minimal images are those in your picture.
Here are the code examples for Tensorflow that I've seen to work.
TF-Visualize-CNN implements only step (1)
tf_cnnvis implements both steps.

SVM: Adding Clinical Features To Feature Vector Extracted From Image

I'm using SVM to classify clinical images of patients belonging to two different groups (patients vs. controls). I use PCA to extract a vector of features from each image, but I'd like to add other clinical information (for example, the output value of a clinical exam) in order to include it in the classification process.
Is there a way to do this?
I didn't find exhaustive suggestions in literature.
Thanks in advance.
You could just append the new information at the end of each sample. Other approach that you could try is having two additional classifiers, one that you could train with the additional information and a third classifier that would take the output of the other two classifiers as input to product a final prediction.
The question is pretty old, I' post my answer though.
If you have to scale your values, make sure that the new values are scaled to the similar range of your values in PCA-vector.
If your PCA vectors of features have constant length, you just start enumerating your features from length+1 e.g. for SVM input (libsvm):
1 1:<PCAval1> ... N:<PCAvalN> N+1:<Clinical exam value 1> ...
I've made a test adding such general features for cell recognition and the accuracy raised.
This Guide describes how to use enumerator-features.
P.S.:
In my test I've isolated, and squeezed cells from microscope image to a matrix 16x16. Each pixel in this matrix was a feature - 256 features. Additionally I've added some features as original size, moments, etc.

Resources