From 4279cd09cc7b2c0b3ce8378a761472e2074ac5c8 Mon Sep 17 00:00:00 2001 From: szabi-luxonis Date: Thu, 30 Apr 2020 03:12:53 +0300 Subject: [PATCH 1/4] discard tensorentry if it's nan or infinity --- host/core/nnet/tensor_entry.hpp | 14 ++++++++++++++ host/core/nnet/tensor_entry_container.hpp | 22 ++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/host/core/nnet/tensor_entry.hpp b/host/core/nnet/tensor_entry.hpp index 0b4a53581..b18ef26c1 100644 --- a/host/core/nnet/tensor_entry.hpp +++ b/host/core/nnet/tensor_entry.hpp @@ -45,4 +45,18 @@ struct TensorEntry return getFloatByIndex(arr_index); } + bool checkValidTensorEntry() const + { + for(int idx = 0; idx < getPropertiesNumber(); idx++) + { + float tensorValue = getFloatByIndex(idx); + if(isnan(tensorValue) || isinf(tensorValue)) + { + printf("invalid tensor packet, discarding \n"); + return false; + } + } + return true; + } + }; diff --git a/host/core/nnet/tensor_entry_container.hpp b/host/core/nnet/tensor_entry_container.hpp index 7f9739804..c8ab27c3d 100644 --- a/host/core/nnet/tensor_entry_container.hpp +++ b/host/core/nnet/tensor_entry_container.hpp @@ -80,8 +80,10 @@ class TensorEntryContainer // &ti.output_property_value_string_to_index[ti.output_properties_dimensions[0]]; // } } - - entry.push_back(te); + if(te.checkValidTensorEntry() == true) + { + entry.push_back(te); + } } return entry; @@ -112,12 +114,20 @@ struct PyTensorEntryContainerIterator std::vector next() { - if (index == seq.size()) + while(true) { - throw py::stop_iteration(); + if (index == seq.size()) + { + throw py::stop_iteration(); + } + std::vector next_entry = seq.getByIndex(index++); + if(next_entry.empty()) + { + continue; + } + + return next_entry; } - - return seq.getByIndex(index++); } TensorEntryContainer &seq; From 0443ed3ce93ed12929daa7b6a8687652810b2a7f Mon Sep 17 00:00:00 2001 From: szabi-luxonis Date: Thu, 30 Apr 2020 03:17:12 +0300 Subject: [PATCH 2/4] reduce queue size from 100 to 30 --- host/core/nnet/tensor_info.hpp | 1 + host/core/pipeline/host_pipeline.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/host/core/nnet/tensor_info.hpp b/host/core/nnet/tensor_info.hpp index 3213d9122..f1ae6bd47 100644 --- a/host/core/nnet/tensor_info.hpp +++ b/host/core/nnet/tensor_info.hpp @@ -67,6 +67,7 @@ struct TensorInfo { assert(output_entry_iteration_index < output_dimensions.size()); //assert(false); // TODO: correct ? + assert(output_dimensions[output_entry_iteration_index] != 0); return getTensorSize() / output_dimensions[output_entry_iteration_index]; } } diff --git a/host/core/pipeline/host_pipeline.hpp b/host/core/pipeline/host_pipeline.hpp index 777fffc59..b8e5ad63b 100644 --- a/host/core/pipeline/host_pipeline.hpp +++ b/host/core/pipeline/host_pipeline.hpp @@ -20,7 +20,7 @@ class HostPipeline : public DataObserver { protected: - const unsigned c_data_queue_size = 100; + const unsigned c_data_queue_size = 30; boost::lockfree::spsc_queue> _data_queue_lf; std::list> _consumed_packets; // TODO: temporary solution From 43ae1b114c45a1dbd228a3bf07f712fd3e954ba9 Mon Sep 17 00:00:00 2001 From: szabi-luxonis Date: Thu, 7 May 2020 17:54:19 +0300 Subject: [PATCH 3/4] return Null object on failure --- host/core/host_data_packet.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/host/core/host_data_packet.hpp b/host/core/host_data_packet.hpp index 4666a11cc..7f1f2c5ed 100644 --- a/host/core/host_data_packet.hpp +++ b/host/core/host_data_packet.hpp @@ -125,9 +125,9 @@ struct HostDataPacket } catch (const std::exception& e) { std::cerr << e.what() << std::endl; - result = new py::array(py::dtype("f"), {1}, {}); + result = nullptr; } - + //py::gil_scoped_release release; // REUIRED ??? // std::cout << "===> c++ getPythonNumpyArray " << t.ellapsed_us() << " us\n"; From dbb699672a966b29dd45bb582b6918dc25dc6879 Mon Sep 17 00:00:00 2001 From: szabi-luxonis Date: Sat, 9 May 2020 00:17:31 +0300 Subject: [PATCH 4/4] implement LRU policy for frame queue --- host/core/pipeline/host_pipeline.cpp | 10 +++++++++- host/core/pipeline/host_pipeline.hpp | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/host/core/pipeline/host_pipeline.cpp b/host/core/pipeline/host_pipeline.cpp index 05f396ae1..e37bb135c 100644 --- a/host/core/pipeline/host_pipeline.cpp +++ b/host/core/pipeline/host_pipeline.cpp @@ -49,7 +49,13 @@ void HostPipeline::onNewData( if (!_data_queue_lf.push(host_data)) { - std::cout << "Data queue is full " << info.name << ":\n"; + std::unique_lock guard(q_lock); + _data_queue_lf.pop(); + guard.unlock(); + if (!_data_queue_lf.push(host_data)) + { + std::cerr << "Data queue is full " << info.name << ":\n"; + } } // std::cout << "===> onNewData " << t.ellapsed_us() << " us\n"; @@ -80,6 +86,7 @@ void HostPipeline::consumePackets() Timer consume_dur; _consumed_packets.clear(); + std::unique_lock guard(q_lock); _data_queue_lf.consume_all( [this] (std::shared_ptr& data) @@ -88,6 +95,7 @@ void HostPipeline::consumePackets() this->_consumed_packets.push_back(data); } ); + guard.unlock(); if (!this->_consumed_packets.empty()) { diff --git a/host/core/pipeline/host_pipeline.hpp b/host/core/pipeline/host_pipeline.hpp index b8e5ad63b..d5a5e98d5 100644 --- a/host/core/pipeline/host_pipeline.hpp +++ b/host/core/pipeline/host_pipeline.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -44,6 +45,7 @@ class HostPipeline std::list> getConsumedDataPackets(); private: + std::mutex q_lock; // from DataObserver virtual void onNewData(const StreamInfo& info, const StreamData& data) final; // from DataObserver