Let's suppose I would like to classify motorbikes by model.

  • There are couple of hundreds models of motorbikes I'm interested in.
  • I have hundreds of labelled pictures for each motorbike model.
    • There are also unlabelled set of motorbikes pictures, it's about 100x times bigger than the labelled set.

Can you please point me to the practical example that demonstrates how to train model on your data and then use it to classify images? It needs to be a deep learning model, not simple logistic regression.

I'm not sure about it, but it seems like I can't use pre-trained neural net because it has been trained on wide range of objects like cat, human, cars etc. They may be not too good at distinguishing the motorbike nuances I'm interested in.

I found couple of such examples (tensorflow has one), but sadly, all of them were using pre-trained model. None of it had example how to train it on your own dataset.

  • $\begingroup$ How many images do you have,. Are all of them labelled? $\endgroup$ Feb 28, 2017 at 11:46
  • $\begingroup$ Each motorbike model has hundreds labelled images. Total amount of images is about 10-100x times bigger than the labelled set. $\endgroup$ Feb 28, 2017 at 12:17
  • $\begingroup$ I think that ~100 labeled images per motorbike model will not be enough. My gut says you need more like 1000-5000 per bike. But who knows, perhaps each bike will be very easy for a conv net to classify. I would recommend a keras conv net. I think you will want many, many kernels because the bikes are going to have many, many similar features. One early hurdle: massaging the images into a form the net can handle -- will they all fit into your GPU? Probably not, so now you need to manually run batches, or use a generator function. $\endgroup$
    – photox
    Feb 28, 2017 at 13:13
  • $\begingroup$ @photox thanks. It will be possible to label more images, I'd like to try first with what we have and see how it goes. If it fails we can spent time and label 2000 images per motorbike model. Do you know Keras example I can use as a starting point? About fitting it all into memory, don't know..., I guess the only way to figure it out would be to try. $\endgroup$ Mar 1, 2017 at 13:11
  • 1
    $\begingroup$ Boiled down you have image classification problem, with 200 classes. It's similar to the classic mnist handwriten digit classification, the keras implementation is pretty simple (80 lines of code, that's a full conv net) github.com/fchollet/keras/blob/master/examples/mnist_cnn.py it also comes (line 33) with a easy load_data() function, which won't work with your data, and it also fits into memory, which I will tell you yours will not. How are your image data right now (are filenames the labels) folder structure, format, talk some about where you are with preprocessing. $\endgroup$
    – photox
    Mar 1, 2017 at 14:45

1 Answer 1


Here's one tutorial on training a deep convnet from scratch in Keras. There should be plenty of other examples on the web.

You could still use a pre-trained model for this, and just re-train some of the later layers with your dataset to improve its specificity for your task. This works because earlier layers usually contain more general feature extractors, edge-detectors, etc. See here for more info.

100 images per class is not very much training data, so I would say to get reasonable performance, transferring knowledge from a pre-trained model is probably going to be necessary. But given the nature of your problem there might be a lot of similar motorcycle-like features that could be shared between the classes. So perhaps the required number of images per class for decent performance is reduced in your case.

To take advantage of your unlabeled data as well, you can use a semi-supervised learning approach. I would recommend the recent Virtual Adversarial Training, which achieves great performance on a number of benchmarks. I have also seen it provide a performance boost in one real-world application. Plus it's fairly easy to add to an existing model, and the authors have provided a Tensorflow implementation.

It sounds like you might not have too much experience with deep learning. I might just warn that what you are proposing here is not really an easy problem to solve - 100 classes is a lot! You will need to understand the basics well to get anywhere. You will also need a solid GPU.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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