21#include <opencv2/core/core.hpp>
34 namespace postprocessor
42 "your model uses a background class but your class file does not (use -1), or if your "
43 "model does not use a background class but your class file has one (use 1). If unsure, "
44 "use 0 and check whether reported class names are off.",
53 "threshold to report",
58 "this is the max for each scale)",
63 "predictions will be reported",
68 "predictions will be reported. Not all networks use a separate box threshold, "
69 "many only use one threshold confidence threshold (cthresh parameter). The YOLO "
70 "family is an example that uses both box and classification confidences",
79 "for debugging if your scores seem too high or too low. If too high, usually "
80 "that means that you should turn on parameter softmax instead.",
88 DetectType::YOLO, DetectType_Values, ParamCateg);
96 "list of anchors. Should be formatted as: w1, h1, w2, h2, ... ; ww1, hh1, ww2, hh2, "
97 "... ; ... where individual entries for a given YOLO layer are separated by commas, "
98 "and successive YOLO layers (from large to small, e.g., first the anchors for 52x52, "
99 "then for 26x26, then for 13x13) are separated by semicolons. Leave empty "
109 "semantic segmentation overlays",
117 "for C classes and we get one score per class; we will show "
118 "the top scoring class for each pixel (e.g., UNet-MobileNet on TPU). ClassesCHW: "
119 "output is 1xCxHxW and the rest is as for ClassesHWC (e.g., DeepLabV3 OpenCV). ArgMax: "
120 "output is HxW, 1xHxW, or 1xHxWx1 and contains the class ID for each pixel "
121 "(e.g., DeepLabV3 on TPU).",
122 SegType::ClassesHWC, SegType_Values, ParamCateg);
126 "post-processor file. Name of class defined in the file must match "
127 "the file name without the trailing '.py'",
132 "the scale_xy factor for new-style YOLO coordinates (YOLOv5/v7; value is usually 2.0 "
133 "but check the yolo layer in the model's .cfg file)",
138 "just before yolo/detection/region layers have linear activation (most "
139 "YOLOv2/v3/v4 models, but not YOLOv5/v7 which have logistic activation on their "
#define JEVOIS_SHARE_PATH
Base path for shared files (e.g., neural network weights, etc)
A component of a model hierarchy.
Helper class to assist modules in creating graphical and GUI elements.
friend class Component
Allow Component and DynamicParameter to access our registry data, everyone else is locked out.
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.
JEVOIS_DECLARE_PARAMETER(classoffset, int, "Offset added to model output when looking up class name. Useful if " "your model uses a background class but your class file does not (use -1), or if your " "model does not use a background class but your class file has one (use 1). If unsure, " "use 0 and check whether reported class names are off.", 0, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(softmax, bool, "Apply a softmax to classification outputs", false, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(classes, std::string, "Path to text file with names of object classes", "", ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(scorescale, float, "Scaling factors applied to recognition scores. Mainly " "for debugging if your scores seem too high or too low. If too high, usually " "that means that you should turn on parameter softmax instead.", 1.0F, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(cthresh, float, "Classification threshold (in percent confidence) above which " "predictions will be reported", 20.0F, jevois::Range< float >(0.0F, 100.0F), ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(top, unsigned int, "Max number of top-scoring predictions that score above " "threshold to report", 5, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(scalexy, float, "If 0, use old-style YOLO boxes (YOLOv2/v3/v4) otherwise, this is " "the scale_xy factor for new-style YOLO coordinates (YOLOv5/v7 value is usually 2.0 " "but check the yolo layer in the model's .cfg file)", 0.0F, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(sigmoid, bool, "Apply sigmoid to raw YOLO outputs, use when the last conv layers " "just before yolo/detection/region layers have linear activation (most " "YOLOv2/v3/v4 models, but not YOLOv5/v7 which have logistic activation on their " "last conv)", true, ParamCateg)
Parameter.
JEVOIS_DEFINE_ENUM_CLASS(DetectType,(FasterRCNN)(YOLO)(SSD)(TPUSSD)(RAWYOLO)(YOLOv10)(YOLOv10pp))
Enum.
JEVOIS_DECLARE_PARAMETER(dthresh, float, "Detection box threshold (in percent confidence) above which " "predictions will be reported. Not all networks use a separate box threshold, " "many only use one threshold confidence threshold (cthresh parameter). The YOLO " "family is an example that uses both box and classification confidences", 15.0F, jevois::Range< float >(0.0F, 100.0F), ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(maxnbox, unsigned int, "Max number of top-scoring boxes to report (for YOLO flavors, " "this is the max for each scale)", 500, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(alpha, unsigned char, "Alpha channel value for drawn results", 64, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(anchors, std::string, "For YOLO-type detection models with raw outputs, " "list of anchors. Should be formatted as: w1, h1, w2, h2, ... ww1, hh1, ww2, hh2, " "... ... where individual entries for a given YOLO layer are separated by commas, " "and successive YOLO layers (from large to small, e.g., first the anchors for 52x52, " "then for 26x26, then for 13x13) are separated by semicolons. Leave empty " "for other models.", "", ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(detecttype, DetectType, "Type of detection output format", DetectType::YOLO, DetectType_Values, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(nms, float, "Non-maximum suppression intersection-over-union threshold in percent", 45.0F, jevois::Range< float >(0.0F, 100.0F), ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(pypost, std::string, "Path below " JEVOIS_SHARE_PATH "/ of the python " "post-processor file. Name of class defined in the file must match " "the file name without the trailing '.py'", "", ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(bgid, unsigned char, "Class ID for the background, will show as fully transparent in " "semantic segmentation overlays", 0, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(segtype, SegType, "Type of segmentation network output. ClassesHWC: output is 1xHxWxC " "for C classes and we get one score per class we will show " "the top scoring class for each pixel (e.g., UNet-MobileNet on TPU). ClassesCHW: " "output is 1xCxHxW and the rest is as for ClassesHWC (e.g., DeepLabV3 OpenCV). ArgMax: " "output is HxW, 1xHxW, or 1xHxWx1 and contains the class ID for each pixel " "(e.g., DeepLabV3 on TPU).", SegType::ClassesHWC, SegType_Values, ParamCateg)
Parameter.
JEVOIS_DEFINE_ENUM_CLASS(SegType,(ClassesHWC)(ClassesCHW)(ArgMax))
Enum.
Post-Processor for neural network pipeline.
virtual void process(std::vector< cv::Mat > const &outs, PreProcessor *preproc)=0
Process outputs.
virtual void freeze(bool doit)=0
Freeze/unfreeze parameters that users should not change while running.
virtual ~PostProcessor()
Destructor.
virtual void report(jevois::StdModule *mod, jevois::RawImage *outimg=nullptr, jevois::OptGUIhelper *helper=nullptr, bool overlay=true, bool idle=false)=0
Report what happened in last process() to console/output video/GUI.
Pre-Processor for neural network pipeline.
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.
Main namespace for all JeVois classes and functions.
A category to which multiple ParameterDef definitions can belong.