12 #include <unordered_set>
24 class CNNNetworkIterator {
25 std::unordered_set<CNNLayer*> visited;
26 std::list<CNNLayerPtr> nextLayersTovisit;
28 ICNNNetwork* network =
nullptr;
34 typedef std::forward_iterator_tag iterator_category;
36 typedef int difference_type;
43 CNNNetworkIterator() =
default;
49 explicit CNNNetworkIterator(ICNNNetwork* network) {
51 network->getInputsInfo(inputs);
52 if (!inputs.empty()) {
53 auto& nextLayers = inputs.begin()->second->getInputData()->getInputTo();
54 if (!nextLayers.empty()) {
55 currentLayer = nextLayers.begin()->second;
56 nextLayersTovisit.push_back(currentLayer);
57 visited.insert(currentLayer.get());
66 CNNNetworkIterator& operator++() {
67 currentLayer = next();
75 void operator++(
int) {
76 currentLayer = next();
84 bool operator!=(
const CNNNetworkIterator& that)
const {
85 return !operator==(that);
92 if (
nullptr == currentLayer) {
102 if (
nullptr == currentLayer) {
112 bool operator==(
const CNNNetworkIterator& that)
const {
113 return network == that.network && currentLayer == that.currentLayer;
121 if (nextLayersTovisit.empty()) {
125 auto nextLayer = nextLayersTovisit.front();
126 nextLayersTovisit.pop_front();
129 for (
auto&& output : nextLayer->outData) {
130 for (
auto&& child : output->getInputTo()) {
131 if (visited.find(child.second.get()) == visited.end()) {
132 nextLayersTovisit.push_back(child.second);
133 visited.insert(child.second.get());
139 for (
auto&& parent : nextLayer->insData) {
140 auto parentLayer = parent.lock()->getCreatorLayer().lock();
141 if (parentLayer && visited.find(parentLayer.get()) == visited.end()) {
142 nextLayersTovisit.push_back(parentLayer);
143 visited.insert(parentLayer.get());
147 return nextLayersTovisit.empty() ?
nullptr : nextLayersTovisit.front();
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:24
Inference Engine API.
Definition: ie_argmax_layer.hpp:11
This is a header file for the ICNNNetwork class.
A header file for generic LockedMemory<> and different variations of locks.
std::shared_ptr< CNNLayer > CNNLayerPtr
A smart pointer to the CNNLayer.
Definition: ie_common.h:37
std::map< std::string, InputInfo::Ptr > InputsDataMap
A collection that contains string as key, and InputInfo smart pointer as value.
Definition: ie_input_info.hpp:156