Caffe2 - C++ API
A deep learning, cross platform ML framework
operator_attaching_net_observer.h
1 
17 #pragma once
18 
19 #include "caffe2/core/net.h"
20 #include "caffe2/core/observer.h"
21 #include "caffe2/core/operator.h"
22 
23 namespace caffe2 {
24 
25 // Thin class that attaches the observer to all operators in the net
26 template <typename TOpObserver, typename TNetObserver>
27 class OperatorAttachingNetObserver : public ObserverBase<NetBase> {
28  public:
30  NetBase* subject_,
31  TNetObserver* netObserver)
32  : ObserverBase<NetBase>(subject_) {
33  const auto& operators = subject_->GetOperators();
34  for (auto* op : operators) {
35  auto observer = caffe2::make_unique<TOpObserver>(op, netObserver);
36  const auto* ob = observer.get();
37  op->AttachObserver(std::move(observer));
38  operator_observers_.push_back(ob);
39  }
40  }
41  virtual ~OperatorAttachingNetObserver(){};
42 
43  protected:
44  std::vector<const TOpObserver*> operator_observers_;
45 };
46 
47 } // namespace caffe2
Use this to implement a Observer using the Observer Pattern template.
Definition: observer.h:30
Copyright (c) 2016-present, Facebook, Inc.