Caffe2 - C++ API
A deep learning, cross platform ML framework
operator_attaching_net_observer.h
1 #pragma once
2 
3 #include "caffe2/core/net.h"
4 #include "caffe2/core/observer.h"
5 #include "caffe2/core/operator.h"
6 
7 namespace caffe2 {
8 
9 // Thin class that attaches the observer to all operators in the net
10 template <typename TOpObserver, typename TNetObserver>
11 class OperatorAttachingNetObserver : public ObserverBase<NetBase> {
12  public:
14  NetBase* subject_,
15  TNetObserver* netObserver)
16  : ObserverBase<NetBase>(subject_) {
17  const auto& operators = subject_->GetOperators();
18  for (auto* op : operators) {
19  auto observer = caffe2::make_unique<TOpObserver>(op, netObserver);
20  const auto* ob = observer.get();
21  op->AttachObserver(std::move(observer));
22  operator_observers_.push_back(ob);
23  }
24  }
25  virtual ~OperatorAttachingNetObserver(){};
26 
27  protected:
28  std::vector<const TOpObserver*> operator_observers_;
29 };
30 
31 } // namespace caffe2
Use this to implement a Observer using the Observer Pattern template.
Definition: observer.h:15
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13