#########################################################
#
# DO NOT EDIT THIS FILE. IT IS GENERATED AUTOMATICALLY. #
# PLEASE LOOK INTO THE README FOR MORE INFORMATION.     #
#
#########################################################


# coding: utf-8

# # Model Quickload
# 
# This short notebook will show you how you can very quickly load and test SqueezeNet, which is a very small and fast model based on AlexNet and is useful for identifying objects. The range of objects groups is only 1,000.
# 
# Before this script will work, you need to download the model and install it. You can do this by running:
# 
# ```
# sudo python -m caffe2.python.models.download -i squeezenet
# ```
# 
# Or make a squeezenet folder, download each file listed below to it, and place it in `/caffe2/python/models/`:
# * [predict_net.pb](https://download.caffe2.ai/models/squeezenet/predict_net.pb)
# * [init_net.pb](https://download.caffe2.ai/models/squeezenet/init_net.pb)
# 
# The helper functions will look up the top object detection result for you by searching through this [inference codes file](inference_codes.txt). If you want to see how well the model detects samples different than provided here, take a look at the codes, and find an image url to an image of an object in the list of codes.

# In[1]:


# load up the caffe2 workspace
from caffe2.python import workspace
# choose your model here (use the downloader first)
from caffe2.python.models import squeezenet as mynet
# helper image processing functions
import helpers

# load the pre-trained model
init_net = mynet.init_net
predict_net = mynet.predict_net
# you must name it something
predict_net.name = "squeezenet_predict"
workspace.RunNetOnce(init_net)
workspace.CreateNet(predict_net)
p = workspace.Predictor(init_net.SerializeToString(), predict_net.SerializeToString())

# use whatever image you want (urls work too)
# img = "https://upload.wikimedia.org/wikipedia/commons/a/ac/Pretzel.jpg"
# img = "images/cat.jpg"
# img = "images/cowboy-hat.jpg"
# img = "images/cell-tower.jpg"
# img = "images/Ducreux.jpg"
# img = "images/pretzel.jpg"
# img = "images/orangutan.jpg"
# img = "images/aircraft-carrier.jpg"
img = "images/flower.jpg"
# average mean to subtract from the image
mean = 128
# the size of images that the model was trained with
input_size = 227

# use the image helper to load the image and convert it to NCHW
img = helpers.loadToNCHW(img, mean, input_size)

# submit the image to net and get a tensor of results
results = p.run({'data': img})   
response = helpers.parseResults(results)
# and lookup our result from the inference list
print response


