Skip to content

Commit

Permalink
Merge pull request #3 from BVLC/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
yjxiong committed Aug 14, 2014
2 parents fb887c1 + d2566dd commit 288412e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 28 deletions.
7 changes: 4 additions & 3 deletions examples/classification.ipynb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"metadata": {
"name": "ImageNet classification",
"description": "Use the pre-trained ImageNet model to classify images with the Python interface.",
"include_in_docs": true
"example_name": "ImageNet classification",
"include_in_docs": true,
"signature": "sha256:4f8d4c079c30d20ef4b6818e9672b1741fd1377354e5b83e291710736cecd24f"
},
"nbformat": 3,
"nbformat_minor": 0,
Expand Down Expand Up @@ -403,4 +404,4 @@
"metadata": {}
}
]
}
}
28 changes: 16 additions & 12 deletions examples/detection.ipynb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"metadata": {
"name": "ImageNet detection",
"description": "Run a pretrained model as a detector in Python.",
"include_in_docs": true
"example_name": "R-CNN detection",
"include_in_docs": true,
"signature": "sha256:8a744fbbb9ed80acab471247eaf50c27dcbd652105404df9feca599939f0c0ee"
},
"nbformat": 3,
"nbformat_minor": 0,
Expand Down Expand Up @@ -414,7 +415,10 @@
"cell_type": "code",
"collapsed": false,
"input": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n",
"df = pd.read_hdf('_temp/det_output.h5', 'df')\n",
"print(df.shape)\n",
Expand Down Expand Up @@ -525,10 +529,10 @@
"cell_type": "code",
"collapsed": false,
"input": [
"gray()\n",
"matshow(predictions_df.values)\n",
"xlabel('Classes')\n",
"ylabel('Windows')"
"plt.gray()\n",
"plt.matshow(predictions_df.values)\n",
"plt.xlabel('Classes')\n",
"plt.ylabel('Windows')"
],
"language": "python",
"metadata": {},
Expand Down Expand Up @@ -626,17 +630,17 @@
"print(f.order(ascending=False)[:5])\n",
"\n",
"# Show top detection in red, second-best top detection in blue.\n",
"im = imread('images/fish-bike.jpg')\n",
"imshow(im)\n",
"im = plt.imread('images/fish-bike.jpg')\n",
"plt.imshow(im)\n",
"currentAxis = plt.gca()\n",
"\n",
"det = df.iloc[i]\n",
"coords = (det['xmin'], det['ymin']), det['xmax'] - det['xmin'], det['ymax'] - det['ymin']\n",
"currentAxis.add_patch(Rectangle(*coords, fill=False, edgecolor='r', linewidth=5))\n",
"currentAxis.add_patch(plt.Rectangle(*coords, fill=False, edgecolor='r', linewidth=5))\n",
"\n",
"det = df.iloc[j]\n",
"coords = (det['xmin'], det['ymin']), det['xmax'] - det['xmin'], det['ymax'] - det['ymin']\n",
"currentAxis.add_patch(Rectangle(*coords, fill=False, edgecolor='b', linewidth=5))"
"currentAxis.add_patch(plt.Rectangle(*coords, fill=False, edgecolor='b', linewidth=5))"
],
"language": "python",
"metadata": {},
Expand Down Expand Up @@ -776,12 +780,12 @@
"cell_type": "code",
"collapsed": false,
"input": [
"imshow(im)\n",
"plt.imshow(im)\n",
"currentAxis = plt.gca()\n",
"colors = ['r', 'b', 'y']\n",
"for c, det in zip(colors, nms_dets[:3]):\n",
" currentAxis.add_patch(\n",
" Rectangle((det[0], det[1]), det[2]-det[0], det[3]-det[1],\n",
" plt.Rectangle((det[0], det[1]), det[2]-det[0], det[3]-det[1],\n",
" fill=False, edgecolor=c, linewidth=5)\n",
" )\n",
"print 'scores:', nms_dets[:3, 4]"
Expand Down
11 changes: 6 additions & 5 deletions examples/filter_visualization.ipynb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"metadata": {
"name": "Filter visualization",
"description": "Extracting features and visualizing trained filters with an example image, viewed layer-by-layer.",
"include_in_docs": true
"example_name": "Filter visualization",
"include_in_docs": true,
"signature": "sha256:b1b0457e2b10110aca847a718a3fe631ebcfce63a61cbc33653244f52b1ff4af"
},
"nbformat": 3,
"nbformat_minor": 0,
Expand Down Expand Up @@ -193,7 +194,7 @@
" data = data.reshape((n, n) + data.shape[1:]).transpose((0, 2, 1, 3) + tuple(range(4, data.ndim + 1)))\n",
" data = data.reshape((n * data.shape[1], n * data.shape[3]) + data.shape[4:])\n",
" \n",
" imshow(data)"
" plt.imshow(data)"
],
"language": "python",
"metadata": {},
Expand All @@ -212,7 +213,7 @@
"collapsed": false,
"input": [
"# index four is the center crop\n",
"imshow(net.deprocess('data', net.blobs['data'].data[4]))"
"plt.imshow(net.deprocess('data', net.blobs['data'].data[4]))"
],
"language": "python",
"metadata": {},
Expand Down Expand Up @@ -597,4 +598,4 @@
"metadata": {}
}
]
}
}
13 changes: 9 additions & 4 deletions examples/imagenet/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,22 @@ which will make `data/ilsvrc12/imagenet_mean.binaryproto`.
Network Definition
------------------

The network definition follows strictly the one in Krizhevsky et al. You can find the detailed definition at `examples/imagenet/imagenet_train.prototxt`. Note the paths in the data layer - if you have not followed the exact paths in this guide you will need to change the following lines:
The network definition follows strictly the one in Krizhevsky et al. You can find the detailed definition at `examples/imagenet/imagenet_train_val.prototxt`. Note the paths in the data layer --- if you have not followed the exact paths in this guide you will need to change the following lines:

source: "ilvsrc12_train_leveldb"
mean_file: "../../data/ilsvrc12/imagenet_mean.binaryproto"

to point to your own leveldb and image mean. Likewise, do the same for `examples/imagenet/imagenet_val.prototxt`.
to point to your own leveldb and image mean.

If you look carefully at `imagenet_train.prototxt` and `imagenet_val.prototxt`, you will notice that they are largely the same, with the only difference being the data layer sources, and the last layer: in training, we will be using a `softmax_loss` layer to compute the loss function and to initialize the backpropagation, while in validation we will be using an `accuracy` layer to inspect how well we do in terms of accuracy.
If you look carefully at `imagenet_train_val.prototxt`, you will notice several `include` sections specifying either `phase: TRAIN` or `phase: TEST`. These sections allow us to define two closely related networks in one file: the network used for training and the network used for testing. These two networks are almost identical, sharing all layers except for those marked with `include { phase: TRAIN }` or `include { phase: TEST }`. In this case, only the input layers and one output layer are different.

**Input layer differences:** The training network's `data` input layer draws its data from `ilsvrc12_train_leveldb` and randomly mirrors the input image. The testing network's `data` layer takes data from `ilsvrc12_val_leveldb` and does not perform random mirroring.

**Output layer differences:** Both networks output the `softmax_loss` layer, which in training is used to compute the loss function and to initialize the backpropagation, while in validation this loss is simply reported. The testing network also has a second output layer, `accuracy`, which is used to report the accuracy on the test set. In the process of training, the test network will occasionally be instantiated and tested on the test set, producing lines like `Test score #0: xxx` and `Test score #1: xxx`. In this case score 0 is the accuracy (which will start around 1/1000 = 0.001 for an untrained network) and score 1 is the loss (which will start around 7 for an untrained network).

We will also lay out a protocol buffer for running the solver. Let's make a few plans:
* We will run in batches of 256, and run a total of 4,500,000 iterations (about 90 epochs).

* We will run in batches of 256, and run a total of 450,000 iterations (about 90 epochs).
* For every 1,000 iterations, we test the learned net on the validation data.
* We set the initial learning rate to 0.01, and decrease it every 100,000 iterations (about 20 epochs).
* Information will be displayed every 20 epochs.
Expand Down
7 changes: 4 additions & 3 deletions examples/net_surgery.ipynb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"metadata": {
"name": "Editing model parameters",
"description": "How to do net surgery and manually change model parameters, making a fully-convolutional classifier for dense feature extraction.",
"include_in_docs": true
"example_name": "Editing model parameters",
"include_in_docs": true,
"signature": "sha256:0b2ad61622122fa34a40c250be2c0799a85fb65c149b802ce844c46eceba066e"
},
"nbformat": 3,
"nbformat_minor": 0,
Expand Down Expand Up @@ -331,4 +332,4 @@
"metadata": {}
}
]
}
}
2 changes: 1 addition & 1 deletion scripts/copy_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
if 'include_in_docs' in content['metadata'] and content['metadata']['include_in_docs']:
yaml_frontmatter = ['---']
for key, val in content['metadata'].iteritems():
if key == 'name':
if key == 'example_name':
key = 'title'
if val == '':
val = os.path.basename(filename)
Expand Down
3 changes: 3 additions & 0 deletions src/caffe/layers/euclidean_loss_layer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Dtype EuclideanLossLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
Dtype dot;
caffe_gpu_dot(count, diff_.gpu_data(), diff_.gpu_data(), &dot);
Dtype loss = dot / bottom[0]->num() / Dtype(2);
if (top->size() == 1) {
(*top)[0]->mutable_cpu_data()[0] = loss;
}
return loss;
}

Expand Down

0 comments on commit 288412e

Please sign in to comment.