Specify negatives in PyTorch-Object Detection

Hey folks,

I have a decent setup going using Dusty’s Jetson utils and have trained a great custom network on the pytorch object detection however while I am aware that any space outside of the label is labeled as background and counted as negatives in the network I am wondering if there is a way of feeding just negatives to update the model?

The reason being I have new environments I want it to detect in, but there is so much in these environments it has never seen before, so it is producing new false positives. I would like to be able to feed these new environments in without having to spend hours and hours doing vfx to composite my object in the footage and synthesize new data sets.

Any ideas?


Hi @TP2049, I haven’t tried this before, but have you tried adding these ‘negative’ images to your dataset without any annotated objects in their XML files?

Sorry for the late reply, I tried it just now and it ignores files without labels completely, however if I simply add a label in the xml as the size of full frame and label it BACKGROUND, it does take it in as label [0] so does this mean it counts it as negative and learns it? I would imagine so, pls correct me if I am wrong :)


I haven’t tried this myself so I’m not certain - does the labels.txt that it saves along with the model have BACKGROUND listed twice? Normally it automatically inserts this BACKGROUND class for you, so some modification might be needed if it added it twice.

Yeah I purposely edited the xml directly instead of adding a new BACKGROUND label. So when it processes it correctly marked it as index [0] in the labels :)) That is why I think it may just work because I have no BACKGROUND in labels.txt, yet if I type it into the xml as a box object and just set the resolution to full res and call it BACKGROUND, it then processes it as label[0]. (I know this because I uncommented your print snippet in the data prep py files so it prints them out as it pre processes them)

I have managed to record a control set of false positives I am getting. I will write a script to go through the xml files and insert the BACKGROUND object, then feed them in and train it. If it gets rid of the false positives when I test on the cameras I will let you know :)

OK gotcha, smart! :) Will have to remember that trick. Hope that it helps reduce false positives for you.

hey just to update you, it worked pretty well and reduced false positives by around 70%. But there is a limit I think. If you throw too many in then it may cause an imbalance. I added 4k negatives to a 15k data set and it did a nice job. I will be making a post sharing my scripts to automate the process so others can use it soon. Have a good holiday

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.