With minimal effort, DarkHelp can be used from within shell scripts to analyze images and return predictions.
-j
flag to generate the JSON output.When you run the DarkHelp CLI Tool with the -j
or –json
command line switch, three things will happen:
STDOUT
once DarkHelp has finished running.output.json
once DarkHelp has finished running.STDOUT
and STDERR
while it runs. For this reason, it is normally easier to use the file output.json
than to parse the output.If you need to parse the Darknet and DarkHelp output to get the JSON, you'll need to do the following:
STDOUT
and STDERR
into a single output stream.sed
to find where the JSON output starts, and only keep the JSON portion of the output.The solution you'll want to use when scripting with DarkHelp would be similar to this one:
The JSON output will be similar to this:
The JSON structure contains an array with an entry for every image that was processed.
Let's look at a full example, followed by an explanation of each line:
Name | Example | Meaning |
---|---|---|
["file"][#] | ... | Array of images and videos that were processed. |
["file"][#]["count"] | "count" : 1 | The number of predictions that were made for this image. |
["file"][#]["duration"] | "duration": "178 milliseconds" | How long it took for Darknet to analyze this image. |
["file"][#]["filename"] | "filename": "other_dog.jpg" | The filename which was analyzed. |
["file"][#]["original_height"] | "original_height": 293 | The height of the image prior to it being resized (in case -b is used). |
["file"][#]["original_width"] | "original_width": 269 | The width of the image prior to it being resized (in case -b is used). |
["file"][#]["prediction"][#][...] | ... | The same fields as what is documented in DarkHelp::PredictionResult. For example, see DarkHelp::PredictionResult::rect and DarkHelp::PredictionResult::all_probabilities. |
["file"][#]["resized_height"] | "resized_height": 293 | The height of the image after it has been resized (in case -b is used). |
["file"][#]["resized_width"] | "resized_width": 269 | The width of the image after it has been resized (in case -b is used). |
["file"][#]["type"] | "image/jpeg" | The mimetype for the given file. Should be image/ ... or video/ ... |
["network"]["cfg"] | "cfg": "driving.cfg" | The name of the neural network's .cfg file. |
["network"]["loading"] | "loading": "229 milliseconds" | How long it took for the entire neural network to finish loading. |
["network"]["names"] | "names": "driving.names" | The filename that contains a text string for each class in the neural network. |
["network"]["weights"] | "weights": "driving_best.weights" | The filename that contains the neural network's binary data. |
["settings"]["force_greyscale"] | "force_greyscale": false | Whether images are forced to greyscale prior to calling darknet. |
["settings"]["hierarchy"] | "hierarchy": 0.5 | Hierarchy threshold to use. See DarkHelp::Config::hierarchy_threshold. |
["settings"]["include_percentage"] | "include_percentage": true | Whether the name given to each prediction includes the percentage. See DarkHelp::Config::names_include_percentage. |
["settings"]["nms"] | "nms": 0.44999998807907104 | Non-maximal suppression threshold. See DarkHelp::Config::non_maximal_suppression_threshold. |
["settings"]["resize"] | "resize": "640x480" | Images are resized to this prior to calling DarkHelp::NN::predict(). See DarkHelp::resize_keeping_aspect_ratio(). |
["settings"]["threshold"] | "threshold": 0.5 | Prediction threshold. See DarkHelp::Config::threshold. |
-j
to see the JSON output for details.The DarkHelp CLI tool always returns zero. When using -j
, you'll need to parse the JSON structure to find out if something didn't work correctly.
For example, this is part of what you'd see if an image does not exist: