It gets it from the following struct NvDsInferFrameOutput in the sources\includes\nvdsinfer_context.h file.
sources\gst-plugins\gst-nvinfer\gstnvinfer.cpp
attach_metadata_detector (nvinfer, GST_MINI_OBJECT (tensor_out_object.get()),
frame, frame_output.detectionOutput, init_params->segmentationThreshold);
And the batch_output is from the OutputBatch queue.
batch_output = &tensor_out_object->batch_output;
/* Dequeue inferencing output from NvDsInferContext */
status = nvdsinfer_ctx->dequeueOutputBatch (*batch_output);
Since it’s open source, you can add some log yourself to check the process.