Created
January 15, 2017 22:20
-
-
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
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
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" | |
} |
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
net: "net.prototxt" | |
max_iter: 10 | |
lr_policy: "fixed" | |
base_lr: 1 | |
momentum: 0 | |
weight_decay: 0 | |
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 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