In [1]:
import graphlab
graphlab.canvas.set_target('ipynb')
Today we'll walk through building a deep learning network for image recognition CIFAR-10 dataset. The CIFAR data-set represents real-world data that is already formatted and labeled, so we can focus on building our network today instead of cleaning the data.
We're going to walk through 4 steps today:
We've download a subset of the CIFAR-10 data set for you. We load the data into an SFame, which is a powerful and scalable data structure that is used by many of the models in GraphLab Create.
In [2]:
image_train = graphlab.SFrame('https://static.turi.com/datasets/coursera/deep_learning/image_train_data')
image_test = graphlab.SFrame('https://static.turi.com/datasets/coursera/deep_learning/image_test_data')
In [3]:
image_train
Out[3]:
In [4]:
graphlab.image_analysis.resize(image_train['image'], 128, 128, 3).show()
We now use the neuralnet_classifier provided by GraphLab Create to create a neural network for our data set. The create method picks a default network architecture for you based on the dataset.
In [5]:
raw_pixel_model = graphlab.logistic_classifier.create(image_train, features=['image_array'], target='label')
In [6]:
graphlab.image_analysis.resize(image_test[0:1]['image'], 128, 128, 3).show()
In [7]:
image_test[0:1]['label']
Out[7]:
In [8]:
raw_pixel_model.predict(image_test[0:1])
Out[8]:
In [31]:
raw_pixel_model.evaluate(image_test)
Out[31]:
In [10]:
# if you wanted to do this on your own
# step 1: deep_learning_model = graphlab.load_model('imagenet_model/')
# step 2: image_train['deep_features'] = deep_learning_model.extract_features(image_train)
In [11]:
deep_model = graphlab.neuralnet_classifier.create(image_train, features=['image'], target='label')
In [17]:
graphlab.image_analysis.resize(image_test[0:1]['image'], 128, 128, 3).show()
In [18]:
image_test[0:1]['label']
Out[18]:
In [19]:
deep_model.predict(image_test[0:1])
Out[19]:
In [32]:
deep_model.evaluate(image_test)
Out[32]:
In [21]:
deep_features_model = graphlab.logistic_classifier.create(image_train, features=['deep_features'], target='label')
In [33]:
deep_features_model.evaluate(image_test)
Out[33]:
In [23]:
nearest_neighbors_model = graphlab.nearest_neighbors.create(image_train, features=['deep_features'],
label='id')
In [24]:
def get_nearest_neighbors(image):
ans = nearest_neighbors_model.query(image)
return image_train.filter_by(ans['reference_label'],'id')
In [26]:
cat = image_train[18:19]
graphlab.image_analysis.resize(cat['image'],128,128,3).show()
In [28]:
graphlab.image_analysis.resize(get_nearest_neighbors(cat)['image'],128,128,3).show()
In [29]:
car = image_train[8:9]
graphlab.image_analysis.resize(car['image'], 128, 128, 3).show()
In [30]:
graphlab.image_analysis.resize(get_nearest_neighbors(car)['image'],256,256,3).show()
In [ ]: