forked from BVLC/caffe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request BVLC#2667 from BVLC/tutorial
bundle CVPR15 tutorial notebooks
- Loading branch information
Showing
22 changed files
with
25,367 additions
and
22,875 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
layer { | ||
name: "data" | ||
type: "HDF5Data" | ||
top: "data" | ||
top: "label" | ||
hdf5_data_param { | ||
source: "examples/hdf5_classification/data/test.txt" | ||
batch_size: 10 | ||
} | ||
} | ||
layer { | ||
name: "ip1" | ||
type: "InnerProduct" | ||
bottom: "data" | ||
top: "ip1" | ||
inner_product_param { | ||
num_output: 40 | ||
weight_filler { | ||
type: "xavier" | ||
} | ||
} | ||
} | ||
layer { | ||
name: "relu1" | ||
type: "ReLU" | ||
bottom: "ip1" | ||
top: "ip1" | ||
} | ||
layer { | ||
name: "ip2" | ||
type: "InnerProduct" | ||
bottom: "ip1" | ||
top: "ip2" | ||
inner_product_param { | ||
num_output: 2 | ||
weight_filler { | ||
type: "xavier" | ||
} | ||
} | ||
} | ||
layer { | ||
name: "accuracy" | ||
type: "Accuracy" | ||
bottom: "ip2" | ||
bottom: "label" | ||
top: "accuracy" | ||
} | ||
layer { | ||
name: "loss" | ||
type: "SoftmaxWithLoss" | ||
bottom: "ip2" | ||
bottom: "label" | ||
top: "loss" | ||
} |
54 changes: 54 additions & 0 deletions
54
examples/hdf5_classification/nonlinear_auto_train.prototxt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
layer { | ||
name: "data" | ||
type: "HDF5Data" | ||
top: "data" | ||
top: "label" | ||
hdf5_data_param { | ||
source: "examples/hdf5_classification/data/train.txt" | ||
batch_size: 10 | ||
} | ||
} | ||
layer { | ||
name: "ip1" | ||
type: "InnerProduct" | ||
bottom: "data" | ||
top: "ip1" | ||
inner_product_param { | ||
num_output: 40 | ||
weight_filler { | ||
type: "xavier" | ||
} | ||
} | ||
} | ||
layer { | ||
name: "relu1" | ||
type: "ReLU" | ||
bottom: "ip1" | ||
top: "ip1" | ||
} | ||
layer { | ||
name: "ip2" | ||
type: "InnerProduct" | ||
bottom: "ip1" | ||
top: "ip2" | ||
inner_product_param { | ||
num_output: 2 | ||
weight_filler { | ||
type: "xavier" | ||
} | ||
} | ||
} | ||
layer { | ||
name: "accuracy" | ||
type: "Accuracy" | ||
bottom: "ip2" | ||
bottom: "label" | ||
top: "accuracy" | ||
} | ||
layer { | ||
name: "loss" | ||
type: "SoftmaxWithLoss" | ||
bottom: "ip2" | ||
bottom: "label" | ||
top: "loss" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
train_net: "examples/hdf5_classification/nonlinear_auto_train.prototxt" | ||
test_net: "examples/hdf5_classification/nonlinear_auto_test.prototxt" | ||
test_iter: 250 | ||
test_interval: 1000 | ||
base_lr: 0.01 | ||
lr_policy: "step" | ||
gamma: 0.1 | ||
stepsize: 5000 | ||
display: 1000 | ||
max_iter: 10000 | ||
momentum: 0.9 | ||
weight_decay: 0.0005 | ||
snapshot: 10000 | ||
snapshot_prefix: "examples/hdf5_classification/data/train" | ||
solver_mode: CPU |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# The train/test net protocol buffer definition | ||
train_net: "examples/mnist/lenet_auto_train.prototxt" | ||
test_net: "examples/mnist/lenet_auto_test.prototxt" | ||
# test_iter specifies how many forward passes the test should carry out. | ||
# In the case of MNIST, we have test batch size 100 and 100 test iterations, | ||
# covering the full 10,000 testing images. | ||
test_iter: 100 | ||
# Carry out testing every 500 training iterations. | ||
test_interval: 500 | ||
# The base learning rate, momentum and the weight decay of the network. | ||
base_lr: 0.01 | ||
momentum: 0.9 | ||
weight_decay: 0.0005 | ||
# The learning rate policy | ||
lr_policy: "inv" | ||
gamma: 0.0001 | ||
power: 0.75 | ||
# Display every 100 iterations | ||
display: 100 | ||
# The maximum number of iterations | ||
max_iter: 10000 | ||
# snapshot intermediate results | ||
snapshot: 5000 | ||
snapshot_prefix: "examples/mnist/lenet" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import caffe | ||
import numpy as np | ||
|
||
|
||
class EuclideanLossLayer(caffe.Layer): | ||
""" | ||
Compute the Euclidean Loss in the same manner as the C++ EuclideanLossLayer | ||
to demonstrate the class interface for developing layers in Python. | ||
""" | ||
|
||
def setup(self, bottom, top): | ||
# check input pair | ||
if len(bottom) != 2: | ||
raise Exception("Need two inputs to compute distance.") | ||
|
||
def reshape(self, bottom, top): | ||
# check input dimensions match | ||
if bottom[0].count != bottom[1].count: | ||
raise Exception("Inputs must have the same dimension.") | ||
# difference is shape of inputs | ||
self.diff = np.zeros_like(bottom[0].data, dtype=np.float32) | ||
# loss output is scalar | ||
top[0].reshape(1) | ||
|
||
def forward(self, bottom, top): | ||
self.diff[...] = bottom[0].data - bottom[1].data | ||
top[0].data[...] = np.sum(self.diff**2) / bottom[0].num / 2. | ||
|
||
def backward(self, top, propagate_down, bottom): | ||
for i in range(2): | ||
if not propagate_down[i]: | ||
continue | ||
if i == 0: | ||
sign = 1 | ||
else: | ||
sign = -1 | ||
bottom[i].diff[...] = sign * self.diff / bottom[i].num |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: 'LinearRegressionExample' | ||
# define a simple network for linear regression on dummy data | ||
# that computes the loss by a PythonLayer. | ||
layer { | ||
type: 'DummyData' | ||
name: 'x' | ||
top: 'x' | ||
dummy_data_param { | ||
shape: { dim: 10 dim: 3 dim: 2 } | ||
data_filler: { type: 'gaussian' } | ||
} | ||
} | ||
layer { | ||
type: 'DummyData' | ||
name: 'y' | ||
top: 'y' | ||
dummy_data_param { | ||
shape: { dim: 10 dim: 3 dim: 2 } | ||
data_filler: { type: 'gaussian' } | ||
} | ||
} | ||
# include InnerProduct layers for parameters | ||
# so the net will need backward | ||
layer { | ||
type: 'InnerProduct' | ||
name: 'ipx' | ||
top: 'ipx' | ||
bottom: 'x' | ||
inner_product_param { | ||
num_output: 10 | ||
weight_filler { type: 'xavier' } | ||
} | ||
} | ||
layer { | ||
type: 'InnerProduct' | ||
name: 'ipy' | ||
top: 'ipy' | ||
bottom: 'y' | ||
inner_product_param { | ||
num_output: 10 | ||
weight_filler { type: 'xavier' } | ||
} | ||
} | ||
layer { | ||
type: 'Python' | ||
name: 'loss' | ||
top: 'loss' | ||
bottom: 'ipx' | ||
bottom: 'ipy' | ||
python_param { | ||
# the module name -- usually the filename -- that needs to be in $PYTHONPATH | ||
module: 'pyloss' | ||
# the layer name -- the class name in the module | ||
layer: 'EuclideanLossLayer' | ||
} | ||
# set loss weight so Caffe knows this is a loss layer. | ||
# since PythonLayer inherits directly from Layer, this isn't automatically | ||
# known to Caffe | ||
loss_weight: 1 | ||
} |
Oops, something went wrong.