Search code examples
pythonkerasconv-neural-networksvmpca

How to pass feature extracted from cnn dense layer to another cnn?


I implemented a cnn-1 for multi-label image classification. Then i extracted features from the dense layer and got a shape. [600,1024]

600 = total images

I used PCA on this and got shape [600,1].

Now i passed this to svm and accuracy is very low 20%.

I wanna pass this to a cnn and check accuracy. Kindly plz help me.


Solution

  • There are many things you may have to reconsider. First of all, PCA is supposed to come up with a single number that has to carry the burden of representing your 1024 numbers. That is astronomically difficult, you may have to reconsider projecting your data to such low dimensionality. CNNs will never work with a single number as input. To answer your comment, to pass cnn1 features to cnn2 you do not flatten your vectors (meaning you will not have an output of shape (600, 1024) rather a number like (600,3,32,32) where 3 represents the input filters (i.e. R G B in pictures with color and these 32s represent in 2D case --since you mentioned image classification I assume 2D convs-- the image size). Covolutional layers allow you to define the output filters. That is the second number in our example. The image size after the convolution depends on other parameters such as kernel size and stride, don't worry about it for now. The point being is that if you want your image to go through a second conv layer after your first, you need to make sure your second conv layer accepts as input filters the output filters of the first conv layer. That's all I can tell you based on the data I was provided. Once again, using PCA to go from dimensionality 1024 to dimensionality 1 is not recommended, at least not by me.