tree: bef75536603027522678cda4d116a4a950d83ed3 [path history] [tgz]
  1. CMakeLists.txt
  2. operator_attaching_net_observer.h
  3. profile_observer.h
  4. profile_observer_gpu.cc
  5. README.md
  6. runcnt_observer.cc
  7. runcnt_observer.h
  8. time_observer.cc
  9. time_observer.h
  10. time_observer_test.cc
caffe2/observers/README.md

Observers

Usage

Observers are a small framework that allow users to attach code to the execution of SimpleNets and Operators.

An example of an Observer is the TimeObserver, used as follows:

C++

unique_ptr<TimeObserver<NetBase>> net_ob =
    make_unique<TimeObserver<NetBase>>(net.get());
auto* ob = net->AttachObserver(std::move(net_ob));
net->Run();
LOG(INFO) << "av time children: " << ob->average_time_children();
LOG(INFO) << "av time: " << ob->average_time();

Python

model.net.AttachTimeObserver()
ws.RunNet(model.net)
ob = model.net.GetObserver()

print("av time children:", ob.average_time_children())
print("av time:", ob.average_time())

Implementing An Observer

To implement an observer you must inherit from ObserverBase and implement the Start and Stop functions.

Observers are instantiated with a subject of a generic type, such as a Net or Operator. The observer framework is built to be generic enough to “observe” various other types, however.