In [20]:
import graphlab
In [3]:
image_train = graphlab.SFrame('image_train_data/')
image_test = graphlab.SFrame('image_test_data/')
In [4]:
graphlab.canvas.set_target('ipynb')
In [30]:
image_train['image'].show()
In [6]:
raw_pixel_model = graphlab.logistic_classifier.create(image_train,target='label',
features=['image_array'])
In [7]:
image_test[0:3]['image'].show()
In [8]:
image_test[0:3]['label']
Out[8]:
In [9]:
raw_pixel_model.predict(image_test[0:3])
Out[9]:
The model makes wrong predictions for all three images.
In [10]:
raw_pixel_model.evaluate(image_test)
Out[10]:
The accuracy of this model is poor, getting only about 46% accuracy.
We only have 2005 data points, so it is not possible to train a deep neural network effectively with so little data. Instead, we will use transfer learning: using deep features trained on the full ImageNet dataset, we will train a simple model on this small dataset.
In [11]:
len(image_train)
Out[11]:
The two lines below allow us to compute deep features. This computation takes a little while, so we have already computed them and saved the results as a column in the data you loaded.
(Note that if you would like to compute such deep features and have a GPU on your machine, you should use the GPU enabled GraphLab Create, which will be significantly faster for this task.)
In [11]:
#deep_learning_model = graphlab.load_model('http://s3.amazonaws.com/GraphLab-Datasets/deeplearning/imagenet_model_iter45')
#image_train['deep_features'] = deep_learning_model.extract_features(image_train)
As we can see, the column deep_features already contains the pre-computed deep features for this data.
In [13]:
image_train.head()
Out[13]:
In [14]:
deep_features_model = graphlab.logistic_classifier.create(image_train,
features=['deep_features'],
target='label')
In [15]:
image_test[0:3]['image'].show()
In [16]:
deep_features_model.predict(image_test[0:3])
Out[16]:
The classifier with deep features gets all of these images right!
In [17]:
deep_features_model.evaluate(image_test)
Out[17]:
In [21]:
image_train['label'].sketch_summary()
Out[21]:
In [36]:
auto_data = image_train[image_train['label'] == 'automobile']
cat_data = image_train[image_train['label'] == 'cat']
dog_data = image_train[image_train['label'] == 'dog']
bird_data = image_train[image_train['label'] == 'bird']
In [37]:
len(auto_data)
Out[37]:
In [ ]: