Tutorial #5310
Open
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f456f7a
Update brewing LogReg notebook to include creating solvers in notebook
jeffdonahue 18e857c
groom tutorial examples
shelhamer 2a0eb2d
[tutorial] update to 00-classification notebook
longjon b8641e0
[data] get_mnist.sh rewrite; prevents prompt in tutorial notebooks
longjon 99b8b31
[tutorial] updates to 01-learning-lenet
longjon 415e37b
add simple intro for notebook sanity check
shelhamer 223a198
Comment out downloading MNIST data
jeffdonahue 38239d6
update finetuning notebook format (to v4)
jeffdonahue f3d3a7b
improve finetuning notebook:
jeffdonahue 7df0c77
rearrange notebooks: drop logreg, surgery from sequence
shelhamer 36f6436
notebook: first sip runs CaffeNet (only simpler choice is lenet)
shelhamer babf74b
reorganized and added section headers to finetuning notebook
jeffdonahue cdaa49c
lenet notebook: no chdir for idempotency
shelhamer 01fc99c
lenet notebook: title accuracy plot, ip -> fc, name output
shelhamer f9f313b
lenet notebook: lmdb workaround
shelhamer d911573
lenet notebook: add experimentation section
shelhamer d2475b0
finetuning notebook -- fix memory use issues due to lingering solvers
jeffdonahue 445a197
fine-tuning: clear output
shelhamer 3439ce8
fine-tuning notebook: no chdir for idempotency
shelhamer 8673d53
update completed notebooks
shelhamer 364e7d8
classification notebook: drop some layers from visualization
shelhamer 868d425
classification notebook: choose your own for the default
shelhamer 4e8ea99
intro notebook: classify coffee image + include completed
shelhamer 2a6ecfb
rm lib{crypto,ssl} version warnings
jeffdonahue cff1b8f
more FT notebook tweaks
jeffdonahue a354a37
FT notebook: fix deprecated solver type specification
jeffdonahue 44b4b28
fine-tuning notebook: comment out data download -- bundled with lab
shelhamer db69fa3
fix fine-tuning notebook: overeagerly commented out earlier
shelhamer
Jump to file or symbol
Failed to load files and symbols.
| @@ -0,0 +1,242 @@ | ||
| +{ | ||
| + "cells": [ | ||
| + { | ||
| + "cell_type": "markdown", | ||
| + "metadata": {}, | ||
| + "source": [ | ||
| + "# First Sip of Caffe\n", | ||
| + "\n", | ||
| + "This is a quick check to make sure we can brew." | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "markdown", | ||
| + "metadata": {}, | ||
| + "source": [ | ||
| + "---\n", | ||
| + "Before we begin, let's verify [WebSockets](http://en.wikipedia.org/wiki/WebSocket) are working on your system. To do this, execute the cell block below by giving it focus (clicking on it with your mouse), and hitting Ctrl-Enter, or pressing the play button in the toolbar above. If all goes well, you should see some output returned below the grey cell. If not, please consult the [Self-paced Lab Troubleshooting FAQ](https://developer.nvidia.com/self-paced-labs-faq#Troubleshooting) to debug the issue. *This section courtesy the NVIDIA Caffe introduction.*" | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "code", | ||
| + "execution_count": null, | ||
| + "metadata": { | ||
| + "collapsed": false | ||
| + }, | ||
| + "outputs": [], | ||
| + "source": [ | ||
| + "print \"The answer should be three: \" + str(1+2)" | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "markdown", | ||
| + "metadata": {}, | ||
| + "source": [ | ||
| + "Let's execute the cell below to display information about the GPUs running on the server." | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "code", | ||
| + "execution_count": null, | ||
| + "metadata": { | ||
| + "collapsed": false | ||
| + }, | ||
| + "outputs": [], | ||
| + "source": [ | ||
| + "!nvidia-smi" | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "markdown", | ||
| + "metadata": {}, | ||
| + "source": [ | ||
| + "Now load the `caffe` Python module and switch to GPU mode for computation." | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "code", | ||
| + "execution_count": null, | ||
| + "metadata": { | ||
| + "collapsed": false | ||
| + }, | ||
| + "outputs": [], | ||
| + "source": [ | ||
| + "caffe_root = '../' # this file should be run from {caffe_root}/examples (otherwise change this line)\n", | ||
| + "\n", | ||
| + "# make sure that caffe is in our import path\n", | ||
| + "import sys\n", | ||
| + "sys.path.insert(0, caffe_root + 'python')\n", | ||
| + "\n", | ||
| + "# load caffe and switch to the GPU\n", | ||
| + "import caffe\n", | ||
| + "caffe.set_mode_gpu()\n", | ||
| + "caffe.set_device(0)\n", | ||
| + "\n", | ||
| + "# import standard array and plotting toolkit\n", | ||
| + "import numpy as np\n", | ||
| + "import matplotlib.pyplot as plt\n", | ||
| + "%matplotlib inline" | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "markdown", | ||
| + "metadata": {}, | ||
| + "source": [ | ||
| + "The next step is to collect the materials we'll need for our first sip:\n", | ||
| + "\n", | ||
| + "1. a pre-trained network for off-the-shelf use\n", | ||
| + "2. the category names to understand the output" | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "code", | ||
| + "execution_count": null, | ||
| + "metadata": { | ||
| + "collapsed": false | ||
| + }, | ||
| + "outputs": [], | ||
| + "source": [ | ||
| + "# make sure we have the CaffeNet model weights\n", | ||
| + "import os\n", | ||
| + "if os.path.isfile(caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'):\n", | ||
| + " print 'CaffeNet found.'\n", | ||
| + "else:\n", | ||
| + " print 'Downloading pre-trained CaffeNet model...'\n", | ||
| + " !../scripts/download_model_binary.py ../models/bvlc_reference_caffenet\n", | ||
| + "\n", | ||
| + "# load ImageNet labels (for understanding the output)\n", | ||
| + "labels_file = caffe_root + 'data/ilsvrc12/synset_words.txt'\n", | ||
| + "if not os.path.exists(labels_file):\n", | ||
| + " !../data/ilsvrc12/get_ilsvrc_aux.sh\n", | ||
| + "labels = np.loadtxt(labels_file, str, delimiter='\\t')" | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "markdown", | ||
| + "metadata": {}, | ||
| + "source": [ | ||
| + "With `caffe` ready, let's load our pre-trained CaffeNet (a variant of the ILSVRC2012-winning AlexNet by Krizhevsky et al.)." | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "code", | ||
| + "execution_count": null, | ||
| + "metadata": { | ||
| + "collapsed": false | ||
| + }, | ||
| + "outputs": [], | ||
| + "source": [ | ||
| + "# load and run the net\n", | ||
| + "model_def = caffe_root + 'models/bvlc_reference_caffenet/deploy.prototxt'\n", | ||
| + "model_weights = caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'\n", | ||
| + "\n", | ||
| + "net = caffe.Net(model_def, # defines the structure of the model\n", | ||
| + " model_weights, # contains the trained weights\n", | ||
| + " caffe.TEST) # for deployment (in contrast to caffe.TRAIN)\n", | ||
| + "\n", | ||
| + "print 'Loaded net.'" | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "markdown", | ||
| + "metadata": {}, | ||
| + "source": [ | ||
| + "Before checking the net let's define an input pre-processor, `transformer`, to help feed an image into the net." | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "code", | ||
| + "execution_count": null, | ||
| + "metadata": { | ||
| + "collapsed": false | ||
| + }, | ||
| + "outputs": [], | ||
| + "source": [ | ||
| + "# configure input pre-processing\n", | ||
| + "mu = np.load(caffe_root + 'python/caffe/imagenet/ilsvrc_2012_mean.npy')\n", | ||
| + "mu = mu.mean(1).mean(1) # average over pixels to obtain the mean (BGR) pixel values\n", | ||
| + "transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})\n", | ||
| + "transformer.set_transpose('data', (2,0,1)) # move image channels to outermost dimension\n", | ||
| + "transformer.set_mean('data', mu) # subtract the dataset-mean value in each channel\n", | ||
| + "transformer.set_raw_scale('data', 255) # rescale from [0, 1] to [0, 255]\n", | ||
| + "transformer.set_channel_swap('data', (2,1,0)) # swap channels from RGB to BGR\n", | ||
| + "print 'Configured input.'" | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "markdown", | ||
| + "metadata": {}, | ||
| + "source": [ | ||
| + "Time for an image:" | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "code", | ||
| + "execution_count": null, | ||
| + "metadata": { | ||
| + "collapsed": false | ||
| + }, | ||
| + "outputs": [], | ||
| + "source": [ | ||
| + "# download an image\n", | ||
| + "image = caffe.io.load_image(caffe_root + 'examples/images/coffee.jpg')\n", | ||
| + "transformed_image = transformer.preprocess('data', image)\n", | ||
| + "plt.imshow(image)" | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "markdown", | ||
| + "metadata": {}, | ||
| + "source": [ | ||
| + "What a fine cup of coffee. Let's classify!" | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "code", | ||
| + "execution_count": null, | ||
| + "metadata": { | ||
| + "collapsed": false | ||
| + }, | ||
| + "outputs": [], | ||
| + "source": [ | ||
| + "net.blobs['data'].data[...] = transformed_image\n", | ||
| + "net.forward()\n", | ||
| + "output_prob = net.blobs['prob'].data[0]\n", | ||
| + "\n", | ||
| + "print 'What does the net say?\\n', labels[output_prob.argmax()]" | ||
| + ] | ||
| + }, | ||
| + { | ||
| + "cell_type": "markdown", | ||
| + "metadata": {}, | ||
| + "source": [ | ||
| + "Happy brewing!" | ||
| + ] | ||
| + } | ||
| + ], | ||
| + "metadata": { | ||
| + "description": "Use the pre-trained ImageNet model to classify images with the Python interface.", | ||
| + "example_name": "ImageNet classification", | ||
| + "include_in_docs": true, | ||
| + "kernelspec": { | ||
| + "display_name": "Python 2", | ||
| + "language": "python", | ||
| + "name": "python2" | ||
| + }, | ||
| + "language_info": { | ||
| + "codemirror_mode": { | ||
| + "name": "ipython", | ||
| + "version": 2 | ||
| + }, | ||
| + "file_extension": ".py", | ||
| + "mimetype": "text/x-python", | ||
| + "name": "python", | ||
| + "nbconvert_exporter": "python", | ||
| + "pygments_lexer": "ipython2", | ||
| + "version": "2.7.10" | ||
| + }, | ||
| + "priority": 1 | ||
| + }, | ||
| + "nbformat": 4, | ||
| + "nbformat_minor": 0 | ||
| +} |
Oops, something went wrong.