11 #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;
48 explicit CNNNetworkIterator(ICNNNetwork * network) {
50 network->getInputsInfo(inputs);
51 if (!inputs.empty()) {
52 auto & nextLayers = inputs.begin()->second->getInputData()->getInputTo();
53 if (!nextLayers.empty()) {
54 currentLayer = nextLayers.begin()->second;
55 nextLayersTovisit.push_back(currentLayer);
56 visited.insert(currentLayer.get());
65 CNNNetworkIterator &operator++() {
66 currentLayer = next();
74 void operator++(
int) {
75 currentLayer = next();
83 bool operator!=(
const CNNNetworkIterator &that)
const {
84 return !operator==(that);
91 if (
nullptr == currentLayer) {
101 if (
nullptr == currentLayer) {
111 bool operator==(
const CNNNetworkIterator &that)
const {
112 return network == that.network && currentLayer == that.currentLayer;
120 if (nextLayersTovisit.empty()) {
124 auto nextLayer = nextLayersTovisit.front();
125 nextLayersTovisit.pop_front();
128 for (
auto && output : nextLayer->outData) {
129 for (
auto && child : output->getInputTo()) {
130 if (visited.find(child.second.get()) == visited.end()) {
131 nextLayersTovisit.push_back(child.second);
132 visited.insert(child.second.get());
138 for (
auto && parent : nextLayer->insData) {
139 auto parentLayer = parent.lock()->getCreatorLayer().lock();
140 if (parentLayer && visited.find(parentLayer.get()) == visited.end()) {
141 nextLayersTovisit.push_back(parentLayer);
142 visited.insert(parentLayer.get());
146 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:22
Definition: ie_argmax_layer.hpp:11
std::shared_ptr< CNNLayer > CNNLayerPtr
A smart pointer to the CNNLayer.
Definition: ie_common.h:36
This is a header file for the ICNNNetwork class.
A header file for generic LockedMemory<> and different variations of locks.