зеркало из https://github.com/microsoft/caffe.git
270 строки
28 KiB
Plaintext
270 строки
28 KiB
Plaintext
{
|
|
"metadata": {
|
|
"name": ""
|
|
},
|
|
"nbformat": 3,
|
|
"nbformat_minor": 0,
|
|
"worksheets": [
|
|
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Running Pretrained ImageNet: the Easy way\n",
|
|
"=========================================\n",
|
|
"\n",
|
|
"For easier use of pretrained models, we provide a wrapper specifically written for the case of ImageNet, so one can take an image and directly compute features or predictions from them. Both Python and Matlab wrappers are provided. We will describe the use of the Python wrapper here, and the Matlab wrapper usage is very similar.\n",
|
|
"\n",
|
|
"We assume that you have successfully compiled Caffe and set the correct `PYTHONPATH`. If not, please refer to the [installation instructions](installation.html). You will use our pre-trained imagenet model, which you can download (232.57MB) by running `examples/imagenet/get_caffe_reference_imagenet_model.sh`. Note that this pre-trained model is licensed for academic research / non-commercial use only.\n",
|
|
"\n",
|
|
"Ready? Let's start."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"from caffe import imagenet\n",
|
|
"from matplotlib import pyplot\n",
|
|
"\n",
|
|
"# Set the right path to your model file, pretrained model,\n",
|
|
"# and the image you would like to classify.\n",
|
|
"MODEL_FILE = 'imagenet/imagenet_deploy.prototxt'\n",
|
|
"PRETRAINED = 'imagenet/caffe_reference_imagenet_model'\n",
|
|
"IMAGE_FILE = 'images/lena.png'"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"prompt_number": 1
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Loading a network is easy. imagenet.ImagenetClassifier wraps everything. In default, the classifier will crop the center and corners of an image, as well as their mirrored versions, thus creating a batch of 10 images. If you look at the provided MODEL_FILE you can actually see that we are defining the input batch size to be 10.\n",
|
|
"\n",
|
|
"If you would like to just do the center, you need to specify center_only=1, and also change the batch size from 10 to 1 in the prototxt."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"net = imagenet.ImageNetClassifier(\n",
|
|
" MODEL_FILE, PRETRAINED)"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"prompt_number": 2
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"We will set the phase to test since we are doing testing, and will first use CPU for the computation."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"net.caffenet.set_phase_test()\n",
|
|
"net.caffenet.set_mode_cpu()"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"prompt_number": 3
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"So now, we can do a prediction. Let's show some output as well:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"prediction = net.predict(IMAGE_FILE)\n",
|
|
"print 'prediction shape:', prediction.shape\n",
|
|
"pyplot.plot(prediction)"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"stream": "stdout",
|
|
"text": [
|
|
"prediction shape: (1000,)\n"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"output_type": "pyout",
|
|
"prompt_number": 4,
|
|
"text": [
|
|
"[<matplotlib.lines.Line2D at 0x8faf4d0>]"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"output_type": "display_data",
|
|
"png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEACAYAAAC+gnFaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHPFJREFUeJzt3W1wE+eBB/D/UuvKnUMhUMfYknvGtrDEix0ns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wxhtvhJdRFI8DHBPV3Nws5s+fL/Lz88WWLVu0rErCHT58WEiSJIqLi8Xdd98t7r77\nbrF//35x8eJF8fDDDwur1SrKy8vF5cuXw8v87Gc/E/n5+aKwsFB4PB4Na584Xq83fNaQUdviww8/\nFA6HQxQVFYnVq1eLvr4+w7ZFbW2tWLBggVi0aJF4+umnxcDAgGHaoqqqSmRlZQmTySQsFovYvXv3\nhLb9+PHjYtGiRSI/P18899xzql6bF5QRERkc/1UlEZHBMQiIiAyOQUBEZHAMAiIig2MQEBEZHIOA\niMjgGARERAbHICAiMrj/BwQijf8bq9cnAAAAAElFTkSuQmCC\n",
|
|
"text": [
|
|
"<matplotlib.figure.Figure at 0x4739050>"
|
|
]
|
|
}
|
|
],
|
|
"prompt_number": 4
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"You can see that the prediction is 1000-dimensional, and is pretty sparse. Our pretrained model uses the alphabetical order for the synsets, and if you look at the index that maximizes the prediction score, it is \"sombrero\". Reasonable prediction, right?\n",
|
|
"\n",
|
|
"Now, why don't we see how long it takes to perform the classification end to end? This result is run from an Intel i5 CPU, so you may observe some performance differences."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"%timeit net.predict(IMAGE_FILE)"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"stream": "stdout",
|
|
"text": [
|
|
"1 loops, best of 3: 194 ms per loop\n"
|
|
]
|
|
}
|
|
],
|
|
"prompt_number": 5
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"It may look a little slow, but note that it also includes image loading, cropping, and python interfacing time, and it is running 10 images. As a performance notice, if you really want to make prediction fast, you can optionally write things in C and also pipeline the image loading part. But for most applications, the current speed might be fine I guess?\n",
|
|
"\n",
|
|
"OK, so how about GPU? it is actually pretty easy:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"net.caffenet.set_mode_gpu()"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"prompt_number": 6
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Voila! Now we are in GPU mode. Let's see if the code gives the same result:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"prediction = net.predict(IMAGE_FILE)\n",
|
|
"print 'prediction shape:', prediction.shape\n",
|
|
"pyplot.plot(prediction)"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"stream": "stdout",
|
|
"text": [
|
|
"prediction shape: (1000,)\n"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"output_type": "pyout",
|
|
"prompt_number": 7,
|
|
"text": [
|
|
"[<matplotlib.lines.Line2D at 0xee00e90>]"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"output_type": "display_data",
|
|
"png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEACAYAAAC+gnFaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHPFJREFUeJzt3X1wE+eBBvBnqXWl51AIlBhbcs/YFpb4sONENqEZMkqC\ncc0FJZA044YjmdZHNGSctJk26R+9HpCZAp4OcyXxzJ3LQZqG1Lh3nca0Y1TiEBVCMCqBnHMxudjU\nLrLAhAAuYALG4r0/NpItf6xWtuSVdp/fjMfa1burd1/J76N3vywJIQSIiMiwpmhdASIi0haDgIjI\n4BgEREQGxyAgIjI4BgERkcExCIiIDC5qEHg8HthsNlitVtTU1Ix4vrGxEUVFRSguLsbdd9+NAwcO\nqF6WiIi0JyldRxAMBlFQUIDm5maYzWaUlJSgvr4edrs9XKavrw/p6ekAgA8//BCrVq1CR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IVfA6K19nn/+efzsZz/DlCmDH0EjtkVnZydmz56N73znO7jrrruwbt069PX1GbItZs6c\niR/84Af4+te/jqysLMyYMQNlZWWGbIuQWLd9+Hyz2ayqTTQLArUXq+nN1atX8eijj2L79u2YNm1a\nxHOSJCm2i17a7A9/+APuuOMOFBcXj3kxolHaYmBgAMePH8czzzyD48ePIz09HVu3bo0oY5S2OHXq\nFH7+85+jq6sLZ86cwdWrV7F79+6IMkZpi9FE2/aJ0CwIzGYz/EMu/fP7/RFJpkc3b97Eo48+irVr\n1+KRRx4BIKd8T08PAODs2bO44447AIxsn+7ubpjN5smvdAK899572Lt3L+bOnYtvf/vbOHDgANau\nXWvItrBYLLBYLCgpKQEAPPbYYzh+/DjmzJljuLY4duwYvvGNb2DWrFlIS0vD6tWrceTIEUO2RUgs\nfxMWiwVmsxndofuLQH2baBYEQy9W6+/vR0NDA1wul1bVSTghBKqqqjB//nx8//vfD893uVx47bXX\nAACvvfZaOCBcLhf27NmD/v5+dHZ2or29HaWlpZrUPd42b94Mv9+Pzs5O7NmzBw888ABef/11Q7bF\nnDlzkJ2djU++uHlRc3MzFixYgJUrVxquLWw2G1paWvD5559DCIHm5mbMnz/fkG0REuvfxJw5c/DV\nr34VR48ehRACr7/+engZRfE4wDFeTU1NYt68eSIvL09s3rxZy6ok3KFDh4QkSaKoqEjceeed4s47\n7xT79u0TFy5cEA8++KCwWq2irKxMXLp0KbzMT3/6U5GXlycKCgqEx+PRsPaJ4/V6w2cNGbUtPvjg\nA+FwOERhYaFYtWqV6O3tNWxb1NTUiPnz54uFCxeKJ598UvT39xumLSorK0VmZqYwmUzCYrGIXbt2\njWvbjx07JhYuXCjy8vLEs88+q+q1eUEZEZHB8V9VEhEZHIOAiMjgGARERAbHICAiMjgGARGRwTEI\niIgMjkFARGRwDAIiIoP7f/gBjf8BGVc/AAAAAElFTkSuQmCC\n",
|
|
"text": [
|
|
"<matplotlib.figure.Figure at 0x4745bd0>"
|
|
]
|
|
}
|
|
],
|
|
"prompt_number": 7
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Good, everything is the same. And how about time consumption? The following benchmark is obtained on the same machine with a K20 GPU:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"collapsed": false,
|
|
"input": [
|
|
"%timeit net.predict(IMAGE_FILE)"
|
|
],
|
|
"language": "python",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"stream": "stdout",
|
|
"text": [
|
|
"10 loops, best of 3: 50 ms per loop\n"
|
|
]
|
|
}
|
|
],
|
|
"prompt_number": 8
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Pretty fast right? Not as fast as you expected? Indeed, in this python demo you are seeing only 4 times speedup. But remember - the GPU code is actually very fast, and the data loading, transformation and interfacing actually start to take **more** time than the actual convnet computation itself!\n",
|
|
"\n",
|
|
"To fully utilize the power of GPUs, you really want to use one of these ideas:\n",
|
|
"* Use larger batches, and minimize python call and data transfer overheads.\n",
|
|
"* Pipeline data load operations, like using a subprocess.\n",
|
|
"* Code in C++. A little inconvenient, but maybe worth it if your dataset is really, really large."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Parting Words\n",
|
|
"-------------\n",
|
|
"\n",
|
|
"So this is python! We hope the interface is easy enough for one to use. The python wrapper is interfaced with boost::python, and source code can be found at `python/caffe/imagenet`. If you would like to achieve some custom functions, you are more than welcome to look at them!"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {}
|
|
}
|
|
]
|
|
} |