NvBufSurfTransform failed with error -3 while converting buffer

I’m running deepstream app in docker container, which i pulled as

docker pull nvcr.io/nvidia/deepstream:4.0.2-19.12-devel

My pipeline has 2 neural networks: the first network is for a face detection, and the second network is for a face verification (I get a vector from my second network and compare it with all vectors in some sort of a database). After running for some time (it is always different time interval) app stops with this output:

0:09:07.125719693  8312 0x56390fc84630 WARN                 nvinfer gstnvinfer.cpp:1149:convert_batch_and_push_to_input_thread:<secondary_gie_0> error: NvBufSurfTransform failed with error -3 while converting buffer
ERROR from secondary_gie_0: NvBufSurfTransform failed with error -3 while converting buffer
Debug info: gstnvinfer.cpp(1149): convert_batch_and_push_to_input_thread (): /GstPipeline:pipeline/GstBin:secondary_gie_bin/GstNvInfer:secondary_gie_0
Quitting
0:09:07.157566657  8312 0x56390fc59e80 WARN                 nvinfer gstnvinfer.cpp:1830:gst_nvinfer_output_loop:<primary_gie_classifier> error: Internal data stream error.
0:09:07.157588464  8312 0x56390fc59e80 WARN                 nvinfer gstnvinfer.cpp:1830:gst_nvinfer_output_loop:<primary_gie_classifier> error: streaming stopped, reason error (-5)
ERROR from primary_gie_classifier: Internal data stream error.
Debug info: gstnvinfer.cpp(1830): gst_nvinfer_output_loop (): /GstPipeline:pipeline/GstBin:primary_gie_bin/GstNvInfer:primary_gie_classifier:
streaming stopped, reason error (-5)
^C** ERROR: <_intr_handler:140>: User Interrupted..

I start deeplearning-app as

deeplearning-app -c main.txt

Here is my main.txt config:

[application]
enable-perf-measurement=1
perf-measurement-interval-sec=1

[source0]
enable=1
type=1
camera-width=1280
camera-height=720
camera-fps-n=30
camera-fps-d=1
camera-v4l2-dev-node=0
gpu-id=0
nvbuf-memory-type=2

[sink0]
enable=1
type=2
sync=0
source-id=0
gpu-id=0
nvbuf-memory-type=2

[osd]
enable=1
border-width=2
text-size=15
text-color=1;1;1;1;
text-bg-color=0.3;0.3;0.3;1
font=Serif
gpu-id=0
cuda-memory-type=2

[streammux]
batch-size=1
width=1280
height=720
gpu-id=0
nvbuf-memory-type=2

[primary-gie]
enable=1
gie-unique-id=1
nvbuf-memory-type=2
config-file=net1.txt

[secondary-gie0]
enable=1
gie-unique-id=2
operate-on-gie-id=1
nvbuf-memory-type=2
config-file=net2.txt

Here is my net1.txt config:

[property]
gpu-id=0
net-scale-factor=1
batch-size=1
num-detected-classes=1
is-classifier=0
model-engine-file=net1.engine
network-mode=2
interval=0
parse-bbox-func-name=NvDsInferParseNet1
custom-lib-path=libdeepstream_net1.so

[class-attrs-all]
threshold=0.2
group-threshold=0
minBoxes=0

Here is my net2.txt config:

[property]
gpu-id=0
net-scale-factor=1
batch-size=1
is-classifier=1
classifier-threshold=0.5
network-mode=1
process-mode=2
parse-classifier-func-name=NvDsInferParseNet2
model-engine-file=net2.engine
custom-lib-path=libdeepstream_net2.so

Here is my NvDsInferParseNet2 function code:

#include <cassert>
#include <cstring>
#include <iostream>
#include <fstream>

#include "nvdsinfer_custom_impl.h"
#include <faiss/Index.h>
#include <faiss/index_io.h>

/* C-linkage to prevent name-mangling */
extern "C"
bool NvDsInferParseNet2 (std::vector<NvDsInferLayerInfo> const &output_layers_info,
        NvDsInferNetworkInfo const &network_info, float classifier_threshold,
        std::vector<NvDsInferAttribute> &attr_list, std::string &desc_string)
{
    static faiss::Index* faiss_index = nullptr;
    static std::vector<std::string> labels;

    if (faiss_index == NULL){
        faiss_index = faiss::read_index("/root/faces.index");
        printf("index loaded!\n");

        printf("labels is:\n");
        auto labels_file = std::fstream("/root/labels.txt");
        std::string line;
        if (labels_file.is_open()){
            while (std::getline(labels_file, line)){
                labels.push_back(line);
                printf("\t%s\n", line.c_str());
            }
            printf("\n");

        } else {
            fprintf(stderr, "failed to load labels file\n");
        }
    }

    float *buffer = (float*) output_layers_info[0].buffer;
    long I = 0;
    float D = 0;

    faiss_index->search(1, buffer, 1, &D, &I);

    NvDsInferAttribute attr;
    attr.attributeConfidence = 1;
    attr.attributeLabel = labels[static_cast<std::size_t>(I)].c_str();
    attr_list.push_back(attr);

    desc_string.append(labels[static_cast<std::size_t>(I)].c_str()).append(" ");

    return true;
}

/* Check that the custom function has been defined correctly */
CHECK_CUSTOM_CLASSIFIER_PARSE_FUNC_PROTOTYPE(NvDsInferParseNet2);

Please help me out on this

So there was a problem with bounding boxes in Net1 postprocessing.

When coordinates of bbox were less then 0 or bigger then input tensor size, this error occures, and when I set limits to coordinates, error disappears