Skip to content

Instantly share code, notes, and snippets.

@HBadertscher
Created January 15, 2017 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HBadertscher/9c38dfebc91186887f11a4c2c80ead52 to your computer and use it in GitHub Desktop.
Save HBadertscher/9c38dfebc91186887f11a4c2c80ead52 to your computer and use it in GitHub Desktop.
This is a simple example of how to add callbacks to any Caffe solver
name: "DemoNet"
layer {
name: "data"
type: "Input"
top: "data"
input_param { shape: { dim: 1 dim: 1 dim: 1 dim: 1 } }
}
layer {
name: "labels"
type: "Input"
top: "labels"
input_param { shape: { dim: 1 dim: 1 dim: 1 dim: 1 } }
}
layer {
name: "multiply"
type: "InnerProduct"
bottom: "data"
top: "output"
inner_product_param {
num_output: 1
}
}
layer {
name: "loss"
type: "EuclideanLoss"
bottom: "output"
bottom: "labels"
top: "loss"
}
net: "net.prototxt"
max_iter: 10
lr_policy: "fixed"
base_lr: 1
momentum: 0
weight_decay: 0
solver_mode: CPU
"""
This simple example shows, how to add callback functions to
any Caffe solver, using the Python `add_callback` function.
The `net.prototxt` and `solver.prototxt` are simply to make
this a runnable example.
>> python test_callbacks.py
[...]
Hello World!
Bye Bye!
Hello World!
Bye Bye!
[...]
This is to illustrate my stackoverflow answer to the following question:
http://stackoverflow.com/q/41490526/4221706
01/15/2017 - Hannes Badertscher
License: CC0
"""
import caffe
def hello():
print "Hello World!"
def bye():
print "Bye Bye!"
solver = caffe.SGDSolver('solver.prototxt')
solver.add_callback(hello, bye)
solver.solve()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment