Does this exist? What algorithm or combinations of algorithms would be able to classify images without supervision?

For example if you have many pictures of cats and dogs, then without being trained to distinguish them first, it would go through the images and realize there are two distinctive groups of images (either cat or dog)

Or if you have many random pictures but a good portion of them have trees, then going through the images, the algorithm realizes there is one consistent pattern within some of the images (trees)

  • $\begingroup$ Interesting! Would be great if you share some code here in case you come up with some well working solution... $\endgroup$ – Peter Nov 20 '19 at 9:14
  • $\begingroup$ maybe could shuffle a large dataset of different images and combine multiple images together so each big image would hopefully include all different groups of individual images, then using some type of nn to learn the essential features that reoccur in most of these big images, finally going back to individual images, check what images have what features, and run a clustering algo using that result $\endgroup$ – new coding Nov 23 '19 at 16:11

As a starting point, you can think about unsuvervized image classification as a type of image clustering. You can - for instance - use VGG16 weights, extract image pseudo-features, and run some clustering on this feature set.

Here is some "starter code" (Python):

# Imports
from keras.preprocessing import image
from keras.applications.vgg16 import VGG16
from keras.applications.vgg16 import preprocess_input
import numpy as np
from sklearn.cluster import KMeans
import os, shutil, glob, os.path
from PIL import Image as pil_image
model = VGG16(weights='imagenet', include_top=False)

# Variables
imdir = 'C:/indir/' # DIR containing images
targetdir = "C:/outdir/" # DIR to copy clustered images to
number_clusters = 10

# Loop over files and get features
filelist = glob.glob(os.path.join(imdir, '*.jpg'))
featurelist = []
for i, imagepath in enumerate(filelist):
        print("    Status: %s / %s" %(i, len(filelist)), end="\r")
        img = image.load_img(imagepath, target_size=(224, 224))
        img_data = image.img_to_array(img)
        img_data = np.expand_dims(img_data, axis=0)
        img_data = preprocess_input(img_data)
        features = np.array(model.predict(img_data))

# Clustering
kmeans = KMeans(n_clusters=number_clusters, random_state=0).fit(np.array(featurelist))

# Copy images renamed by cluster 
# Check if target dir exists
except OSError:
# Copy with cluster name
for i, m in enumerate(kmeans.labels_):
        print("    Copy: %s / %s" %(i, len(kmeans.labels_)), end="\r")
        shutil.copy(filelist[i], targetdir + str(m) + "_" + str(i) + ".jpg")
| improve this answer | |

Check this paper. They achieved seminal scores on popular data sets using 1kkk unlabeled images from Instagram.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.