13 #include <unordered_set> 25 class CNNNetworkIterator {
26 std::unordered_set<CNNLayer*> visited;
27 std::list<CNNLayerPtr> nextLayersTovisit;
29 ICNNNetwork* network =
nullptr;
35 typedef std::forward_iterator_tag iterator_category;
37 typedef int difference_type;
44 CNNNetworkIterator() =
default;
50 explicit CNNNetworkIterator(ICNNNetwork* network) {
52 network->getInputsInfo(inputs);
53 if (!inputs.empty()) {
54 auto& nextLayers = inputs.begin()->second->getInputData()->getInputTo();
55 if (!nextLayers.empty()) {
56 currentLayer = nextLayers.begin()->second;
57 nextLayersTovisit.push_back(currentLayer);
58 visited.insert(currentLayer.get());
67 CNNNetworkIterator& operator++() {
68 currentLayer = next();
76 void operator++(
int) {
77 currentLayer = next();
85 bool operator!=(
const CNNNetworkIterator& that)
const {
86 return !operator==(that);
93 if (
nullptr == currentLayer) {
103 if (
nullptr == currentLayer) {
113 bool operator==(
const CNNNetworkIterator& that)
const {
114 return network == that.network && currentLayer == that.currentLayer;
122 if (nextLayersTovisit.empty()) {
126 auto nextLayer = nextLayersTovisit.front();
127 nextLayersTovisit.pop_front();
130 for (
auto&& output : nextLayer->outData) {
131 for (
auto&& child : output->getInputTo()) {
132 if (visited.find(child.second.get()) == visited.end()) {
133 nextLayersTovisit.push_back(child.second);
134 visited.insert(child.second.get());
140 for (
auto&& parent : nextLayer->insData) {
141 auto parentLayer = parent.lock()->getCreatorLayer().lock();
142 if (parentLayer && visited.find(parentLayer.get()) == visited.end()) {
143 nextLayersTovisit.push_back(parentLayer);
144 visited.insert(parentLayer.get());
148 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:25
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
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:39
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:164