33 classes::freeze(doit);
39 if (val.empty()) { itsLabels.clear();
return; }
46 if (outs.size() != 1 && itsFirstTime)
49 LERROR(
"Expected 1 output tensor, got " << outs.size() <<
" - USING FIRST ONE");
52 cv::Mat
const & out = outs[0]; uint32_t
const sz = out.total();
53 if (out.type() != CV_32F)
LFATAL(
"Need FLOAT32 tensor");
54 uint32_t topk = top::get();
if (topk > sz) topk = sz;
55 uint32_t
const fudge = classoffset::get();
58 uint32_t MaxClass[topk];
float fMaxProb[topk];
61 float sm[out.total()];
68 float const t = cthresh::get();
float const fac = 100.0F * scorescale::get();
bool namonly = namedonly::get();
70 for (uint32_t i = 0; i < topk; ++i)
72 if (fMaxProb[i] * fac < t)
break;
74 if (namonly ==
false || label.empty() ==
false)
77 itsObjRec.emplace_back(
o);
86 uint32_t
const topk = top::get();
89 if (outimg && overlay)
108 if (idle ==
false && ImGui::CollapsingHeader(
"Classification results", ImGuiTreeNodeFlags_DefaultOpen))
110 ImGui::Text(
"Top-%u classes above threshold %.2f", topk, cthresh::get());
113 for (
jevois::ObjReco const &
o : itsObjRec) { ImGui::Text(
"%s: %.2F",
o.category.c_str(),
o.score); ++done; }
114 while (done++ < topk) ImGui::TextUnformatted(
"-");
122 while (done++ < topk) helper->
itext(
"-");
126 (void)idle; (void)helper;
#define JEVOIS_SHARE_PATH
Base path for shared files (e.g., neural network weights, etc)
Helper class to assist modules in creating graphical and GUI elements.
void itext(char const *txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
Draw some overlay text on top of an image.
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Base class for a module that supports standardized serial messages.
void sendSerialObjReco(std::vector< ObjReco > const &res)
Send a standardized object recognition message.
void onParamChange(postprocessor::classes const ¶m, std::string const &val) override
std::vector< ObjReco > const & latestRecognitions() const
Get the latest recognition results, use with caution, not thread-safe.
void freeze(bool doit) override
Freeze/unfreeze parameters that users should not change while running.
void process(std::vector< cv::Mat > const &outs, PreProcessor *preproc) override
Process outputs and draw/send some results.
virtual ~PostProcessorClassify()
Destructor.
void report(jevois::StdModule *mod, jevois::RawImage *outimg=nullptr, jevois::OptGUIhelper *helper=nullptr, bool overlay=true, bool idle=false) override
Report what happened in last process() to console/output video/GUI.
Pre-Processor for neural network pipeline.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
#define LERROR(msg)
Convenience macro for users to print out console or syslog messages, ERROR level.
size_t softmax(float const *input, size_t const n, size_t const stride, float const fac, float *output, bool maxonly)
Apply softmax to a float vector.
std::string getLabel(std::map< int, std::string > const &labels, int id, bool namedonly=false)
Get a label from an id.
std::map< int, std::string > readLabelsFile(std::string const &fname)
Read a label file.
void topK(float const *pfProb, float *pfMaxProb, uint32_t *pMaxClass, uint32_t outputCount, uint32_t topNum)
Get top-k entries and their indices.
void writeText(RawImage &img, std::string const &txt, int x, int y, unsigned int col, Font font=Font6x10)
Write some text in an image.
std::string sformat(char const *fmt,...) __attribute__((format(__printf__
Create a string using printf style arguments.
std::filesystem::path absolutePath(std::filesystem::path const &root, std::filesystem::path const &path)
Compute an absolute path from two paths.
unsigned short constexpr White
YUYV color value.
A trivial struct to store object recognition results.