Making an unsupervised CNN model

Hi, I want to make a CNN model to work as a preprocessing model for images to do a task which is extracting linear features from images with CNN, here is an example below:

I downloaded a pretrained model then I fine tuned it (changed weights and some layers), the model worked with train and test data (I visualized feature maps of each convolutional layer). My questions are:

  • How to convert/use a supervised CNN model to an unsupervised CNN or at least how to pass my image directly without splitting data ?
  • Is it possible to drop the fully connected layer in a CNN model because I saw an architecture like that in an article ?

if anyone could help it would be appreciated.

Ok I don’t think I can help you with the first problem but for the second one you should be able to just get the outputs of the cnn layers not the linear layers. It depends on the model though. What model were you thinking?

@Dwight_Foster actually I was thinking of Alexnet since it’s simple yet effective for my task I guess

Ok to get just the convolutional layers for alexnet you could do something like this

model = torchvision.models.alexnet()
model.features

the model.features line will get only the convolutional layers and you can define that as a new model or just pass the input directly into it.

@Dwight_Foster thank you sir for your answer, just one more think is it possible to pass just one input without doing the train/test split method because I may need it for my task later ?

yes you can pass just one input. You will still have to add the batch size dimension.

@Dwight_Foster could you sir provide me with an example if possible and thank you for your help

ya no problem. Here you go:

model = torchvision.models.alexnet()
picture = #PICTURE YOU LOAD, must be in shape (batch_size, 3, size, size)
#you should have a batch size of one for one image. You can use .unsqueeze(0) to get  a batch dimension
output = model.features(picture)