I met this problem when I tested my SSD model trained by object detection API.The model preforms well until it meets some images that contain the objects very simillar to the objective classfications.
I don't want to add another class to these wrong detected objects ,so I decide to include these images in my training datasets.
Refered to https://github.com/tensorflow/models/issues/2544,
''
You need to set min_negatives_per_image to a non zero number in the config for the model to sample boxes from purely negative images:
''
After reviewed the code https://github.com/tensorflow/models/blob/master/research/object_detection/core/losses.py#L433,
it tells me setting 'min_negatives_per_image ' to a positive number allows sampling negatives in an image without any positive anchors ,
@marcoromelli,sure!
First you can set min_negatives_per_image to a non zero number in the config.
Then when you generate xmls , for purely negative images you can label their xmls only to contain the path,filename, width or height informations (for example ,if you generate the xml with labelImg,you don't have to draw a bbox on it)
then when creating tf records , take a 'if' judgement on it like this:
if data.has_key('object'):
for obj in data['object']:
... ...
That's all ~~~~
All 17 comments
closed this issue ,I think I have found the solution
@liangxiao05 can you share the solution you've found?
@marcoromelli,sure!
First you can set min_negatives_per_image to a non zero number in the config.
Then when you generate xmls , for purely negative images you can label their xmls only to contain the path,filename, width or height informations (for example ,if you generate the xml with labelImg,you don't have to draw a bbox on it)
then when creating tf records , take a 'if' judgement on it like this:
if data.has_key('object'):
for obj in data['object']:
... ...
That's all ~~~~
Do you need to change the other config variables in hard_example_miner ?
I am sorry but i have same problem.. But i could not add negative picture because i could use algorithm for any picture or video,
I am trying to find only one object.. Then i test my detection on similar object, for example trained model with samsung gear s3 and detect in appel watch.. It says to me apple watch is a samsung watch...
This is really annoying
There is no simple way to only detect object when is it found and not trying to detect object everywhere ? Even if not present at all ?
Hi,
Can you please help us resolve the issue we are facing, pls find the link below
We are attempting to detect people without helmet while riding motor bikes
We have added 1000 positive images and 2000 negative images with out annotations(but xml created using the verify feature in LabelImg) and changed the min_negatives_per_image to 2. But still we did not get the desired result.
Please let me know, where we are missing out the issue.
Hi @liangxiao05 May I see your config file?
Hi everyone.
I have the same Issue and I Notice that one file have no bounding box.
i. e, looks like:
The solution was to eliminate that file with its respective .jpg file and ejecute again the
create_tf_record.py script.
I hope this will helpful
@marcoromelli,sure!
First you can set min_negatives_per_image to a non zero number in the config.
Then when you generate xmls , for purely negative images you can label their xmls only to contain the path,filename, width or height informations (for example ,if you generate the xml with labelImg,you don't have to draw a bbox on it)
then when creating tf records , take a 'if' judgement on it like this:
if data.has_key('object'):
for obj in data['object']:
... ...
That's all ~~~~
Can you explain which part of generate_tfrecord we have to modify with this?
Hi everyone.
I have the same Issue and I Notice that one file have no bounding box.
i. e, looks like:
The solution was to eliminate that file with its respective .jpg file and ejecute again the
create_tf_record.py script.
I hope this will helpful
This excludes the negative example which is the opposite of what OP wants.
@marcoromelli,sure!
First you can set min_negatives_per_image to a non zero number in the config.
Then when you generate xmls , for purely negative images you can label their xmls only to contain the path,filename, width or height informations (for example ,if you generate the xml with labelImg,you don't have to draw a bbox on it)
then when creating tf records , take a 'if' judgement on it like this:
if data.has_key('object'):
for obj in data['object']:
... ...
That's all ~~~~
Can you explain which part of generate_tfrecord we have to modify with this?
I made a github repo (tfrecord-view) with an example of how to create a tfrecord file, including hard negatives as above, for Python 3 (so no has_key method). It also includes an example of how to consume a tfrecord file and display the images/bounding boxes with labels: https://github.com/EricThomson/tfrecord-view
@marcoromelli,sure!
First you can set min_negatives_per_image to a non zero number in the config.
Then when you generate xmls , for purely negative images you can label their xmls only to contain the path,filename, width or height informations (for example ,if you generate the xml with labelImg,you don't have to draw a bbox on it)
then when creating tf records , take a 'if' judgement on it like this:
if data.has_key('object'):
for obj in data['object']:
... ...
That's all ~~~~
I think this works fine because it excludes all hard negatives (i.e. it doesn't create TFexamples for all XML files that doesn't contain any labeled objects which are the XMLs of the hard negatives)
so this actually terminates the error while creating the record files but it still doesn't solve the original issue (adding purely negative images to training records)
@marcoromelli,sure!
First you can set min_negatives_per_image to a non zero number in the config.
Then when you generate xmls , for purely negative images you can label their xmls only to contain the path,filename, width or height informations (for example ,if you generate the xml with labelImg,you don't have to draw a bbox on it)
then when creating tf records , take a 'if' judgement on it like this:
if data.has_key('object'):
for obj in data['object']:
... ...
That's all ~~~~
Can you explain which part of generate_tfrecord we have to modify with this?
I made a github repo (tfrecord-view) with an example of how to create a tfrecord file, including hard negatives as above, for Python 3 (so no has_key method). It also includes an example of how to consume a tfrecord file and display the images/bounding boxes with labels: https://github.com/EricThomson/tfrecord-view
can you please tell me how you created TFExample for negative samples -by negative here i mean an XML file with image info only(width,height and name) with no labeled objects
@EricThomson can you explain this part for me please?
@marcoromelli,sure!
First you can set min_negatives_per_image to a non zero number in the config.
Then when you generate xmls , for purely negative images you can label their xmls only to contain the path,filename, width or height informations (for example ,if you generate the xml with labelImg,you don't have to draw a bbox on it)
then when creating tf records , take a 'if' judgement on it like this:
if data.has_key('object'):
for obj in data['object']:
... ...
That's all ~~~~
Can you explain which part of generate_tfrecord we have to modify with this?
I made a github repo (tfrecord-view) with an example of how to create a tfrecord file, including hard negatives as above, for Python 3 (so no has_key method). It also includes an example of how to consume a tfrecord file and display the images/bounding boxes with labels: https://github.com/EricThomson/tfrecord-view
can you please tell me how you created TFExample for negative samples -by negative here i mean an XML file with image info only(width,height and name) with no labeled objects
I used the labelimg annotator: go to the image and click 'verify image' and save it (with no bounding box). It saves the xml file with no bounding box information but the rest of the metadata is there.
@EricThomson can you explain this part for me please?
That is formatted such as to make it unreadable to me. I would recommend going to the repo and opening an issue, this is probably not the place to discuss my repo. :)
Hi, I am facing similar issue. When i set min_negatives_per_image to 0 and not set any negative images, i get prediction correct for positive images but getting a lot of false positives. When i add a bunch of negative images say 50% positive and 50% negative and set min_negatives_per_image to 10, the results are not good. I am getting more false negatives as well as false positives. Anyone could help me on this issue... I am using ssd mobilenet v2 or finetuning
Most helpful comment
@marcoromelli,sure!
First you can set min_negatives_per_image to a non zero number in the config.
Then when you generate xmls , for purely negative images you can label their xmls only to contain the path,filename, width or height informations (for example ,if you generate the xml with labelImg,you don't have to draw a bbox on it)
then when creating tf records , take a 'if' judgement on it like this:
That's all ~~~~