In [1]:
import graphlab

Load image dataset


In [3]:
image_train = graphlab.SFrame('image_train_data/')
image_test = graphlab.SFrame('image_test_data/')

Explore the image data


In [9]:
graphlab.canvas.set_target('ipynb')

In [10]:
image_train['image'].show()


Train a classifier on raw pixels


In [12]:
raw_pixel_model = graphlab.logistic_classifier.create(image_train, target='label', 
                                                      features=['image_array'])


PROGRESS: Creating a validation set from 5 percent of training data. This may take a while.
          You can set ``validation_set=None`` to disable validation tracking.

PROGRESS: Logistic regression:
PROGRESS: --------------------------------------------------------
PROGRESS: Number of examples          : 1883
PROGRESS: Number of classes           : 4
PROGRESS: Number of feature columns   : 1
PROGRESS: Number of unpacked features : 3072
PROGRESS: Number of coefficients    : 9219
PROGRESS: Starting L-BFGS
PROGRESS: --------------------------------------------------------
PROGRESS: +-----------+----------+-----------+--------------+-------------------+---------------------+
PROGRESS: | Iteration | Passes   | Step size | Elapsed Time | Training-accuracy | Validation-accuracy |
PROGRESS: +-----------+----------+-----------+--------------+-------------------+---------------------+
PROGRESS: | 1         | 6        | 0.000013  | 3.657938     | 0.317047          | 0.319672            |
PROGRESS: | 2         | 8        | 1.000000  | 4.936910     | 0.376527          | 0.385246            |
PROGRESS: | 3         | 9        | 1.000000  | 5.600108     | 0.406267          | 0.401639            |
PROGRESS: | 4         | 10       | 1.000000  | 6.265189     | 0.446628          | 0.426230            |
PROGRESS: | 5         | 11       | 1.000000  | 6.921027     | 0.448752          | 0.450820            |
PROGRESS: | 6         | 12       | 1.000000  | 7.545150     | 0.457780          | 0.475410            |
PROGRESS: | 10        | 16       | 1.000000  | 9.981264     | 0.520446          | 0.532787            |
PROGRESS: +-----------+----------+-----------+--------------+-------------------+---------------------+

Prediction with raw pixel model


In [13]:
image_test[0:3]['image'].show()



In [14]:
image_test[0:3]['label']


Out[14]:
dtype: str
Rows: 3
['cat', 'automobile', 'cat']

In [15]:
raw_pixel_model.predict(image_test[0:3])


Out[15]:
dtype: str
Rows: 3
['bird', 'cat', 'bird']

Evaluate raw pixel model


In [16]:
raw_pixel_model.evaluate(image_test)


Out[16]:
{'accuracy': 0.4805, 'confusion_matrix': Columns:
 	target_label	str
 	predicted_label	str
 	count	int
 
 Rows: 16
 
 Data:
 +--------------+-----------------+-------+
 | target_label | predicted_label | count |
 +--------------+-----------------+-------+
 |     dog      |       dog       |  425  |
 |     cat      |       dog       |  289  |
 |     dog      |    automobile   |   96  |
 |     dog      |       cat       |  244  |
 |     cat      |       cat       |  348  |
 |  automobile  |       bird      |  113  |
 |     bird     |       bird      |  525  |
 |     bird     |       dog       |  182  |
 |     bird     |       cat       |  161  |
 |     cat      |    automobile   |  154  |
 +--------------+-----------------+-------+
 [16 rows x 3 columns]
 Note: Only the head of the SFrame is printed.
 You can use print_rows(num_rows=m, num_columns=n) to print more rows and columns.}

Can we improve using deep features


In [17]:
len(image_train)


Out[17]:
2005

In [ ]:
deep_learning_model = graphlab.load_model('http://s3.amazonaws.com/GraphLab-Datasets/deeplearning/imagenet_model_iter45')

In [ ]:
image_train['deep_features'] = deep_learning_model.extract_features(image_train)

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: