Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize NN output (NaN, Infinite); handle corrupted frames #18

Merged
merged 6 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions host/core/nnet/tensor_entry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

};
22 changes: 16 additions & 6 deletions host/core/nnet/tensor_entry_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -112,12 +114,20 @@ struct PyTensorEntryContainerIterator

std::vector<TensorEntry> next()
{
if (index == seq.size())
while(true)
{
throw py::stop_iteration();
if (index == seq.size())
{
throw py::stop_iteration();
}
std::vector<TensorEntry> next_entry = seq.getByIndex(index++);
if(next_entry.empty())
{
continue;
}

return next_entry;
}

return seq.getByIndex(index++);
}

TensorEntryContainer &seq;
Expand Down
1 change: 1 addition & 0 deletions host/core/nnet/tensor_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down
2 changes: 1 addition & 1 deletion host/core/pipeline/host_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class HostPipeline
: public DataObserver<StreamInfo, StreamData>
{
protected:
const unsigned c_data_queue_size = 100;
const unsigned c_data_queue_size = 30;

boost::lockfree::spsc_queue<std::shared_ptr<HostDataPacket>> _data_queue_lf;
std::list<std::shared_ptr<HostDataPacket>> _consumed_packets; // TODO: temporary solution
Expand Down