0
$\begingroup$

I'm wondering if there exists a network for simple image classification. What I mean by this is if I have two image datasets, one of horses and one of zebras, I want to train off the horses and classify an image as either a horse or not a horse, so if I test it on an image of a horse, it says it is a horse, but if I use a zebra, it says it is not a horse. Does any library/project for this exist?

$\endgroup$
0
$\begingroup$

Using neural networks

If it is as simple as that, probably a neural network consisting of just a simple convolutional network with a few filters, a fully connected layer with 2 neurons, and a softmax layer, might do it.

To develop that, you can use Keras wrapper over tensorflow or theano, but I think scikit-learn also provides some basic neural network functionalities.

Depending on the simplicity of the images on your dataset, you might do it even with no convolutional layer if there are not many non-linearities, or you might need more complexity (eg. adding convolutional and max pooling layers).

I made personally for teaching a workshop a very simple example of image classification, with 3 groups (trees, people, vehicles), after building a dataset collecting and selectioning images from the CIFAR-100 dataset. You can see this ultra simple example here. However, it is in spanish. Let me translate the most important piece of code from it:

model = Sequential()

# CONVOLUTION. Final size: 29x29x32
model.add(Conv2D(   32,
                    (4, 4),
                    padding='same',
                    input_shape=data_x_train.shape[1:]
        ))

model.add(Activation('relu'))


# CONVOLUTION. Final size: 26x26x32
model.add(Conv2D(   32,
                    (4, 4),
                    padding='same',
                    input_shape=data_x_train.shape[1:]
        ))

model.add(Activation('relu'))


# MAX POOLING. Final size: 13x13x32
model.add(MaxPooling2D(pool_size=(2,2)))

# Dropout to prevent overfitting
model.add(Dropout(0.25))


# CONVOLUTION. Final size: 10x10x64
model.add(Conv2D(   64,
                    (4, 4),
                    padding='same',
                    input_shape=data_x_train.shape[1:]
        ))

model.add(Activation('relu'))

# MAX POOLING. Final size: 5x5x64
model.add(MaxPooling2D(pool_size=(2,2)))

# Dropout to prevent overfitting
model.add(Dropout(0.25))

# Fully connected layer. Neuron number: 1600
model.add(Flatten())

# Output layer: 3 neurons
model.add(Dense(3))
model.add(Activation('softmax'))

So the input for this model is an array of shape [num_rows, 32, 32]. 32x32 is the image size, and I assume 1 color channel. As I say, this is ultra simple. The output, some kind of probability for each of the 3 classes.

Using other aproaches

However, there are many other supervised learning models that you can use for that, most of them supported by scikit-learn, such as kNN, random forests decision trees, RBF SVM, or even just a kernelized multiclass logistic regression. See here.

$\endgroup$

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.