EdjeElectronics / TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10

How to train a TensorFlow Object Detection Classifier for multiple object detection on Windows
Apache License 2.0
2.92k stars 1.3k forks source link

Labeling other objects e.g. car as King or queen etc #353

Open Master-HM opened 5 years ago

Master-HM commented 5 years ago

Thanks a lot Engineer! Your Contribution has helped me a lot. It gave me exactly what I wanted. But I'm having a swear issue now. I used all instruction you gave, to train a model to classify between cotton and weed plant. I gathered images, using labelImg labeled them, I used two labels Cotton and other (label other for weed). LabelImg tool created xml file for each image's bounding boxes axis, then I converted these files to .csv format, exactly as you instructed. Then I invoked generate_tfrecord.py, after modifying it to my requirements. It created tfrecord and testrecord files. Then I launched train.py. After 171,000 steps I terminated execution, and exported graph. Then started making predictions. It went well when I was feeding Cotton and weed pics, but for fun I tried it on cars and :( sadly, it labeled car as cotton, then I gave pic with many cars and it classified some of them as cotton and some of them as other. I inputted it your card pics and surprisingly it also labeled them as cotton and other randomly.

I consulted my supervisors, and they instructed me "instead of giving only two classes in labelmap.pbtxt and modifying faster_rcnn_inception_v2_pets.config with respect to 2 classes only, consider using original label file and modify all things accordingly".

So I used mscoco_label_map.pbtxt and get respected faster_rcnn_inception_v2_coco.config file and added all 90 classes in generate_tfrecord.py file while after adding my own 2 classes it was 92 in total.

All I want my model is to detect All object as it use to do before feeding my own dataset. Yes before feeding and training model inception for my own data, it classify all objects accurately, for example car to car, truck to truck, and person to person. It becomes dirty when I feed my custom input to it. And if i don't feed my custom input to it, it don't detect cotton or other. Edited : I want to detect my custom classes cotton_other and all other classes e.g. car_bike_person_card on which google has trained it. I've looked for many articles, tutorial and guide, way to perform custom object detection on pre-trained model is same. Even on inception guide it is same as I did.

NOTE : other mean Weed

I really need help to get out of this issue, I'm really having a bad time.

All necessary files are attached in this repository. Your help will be huge comeback for me. Thanks https://github.com/Master-HM/Retraining-Inception-labeling-my-custom-specified-labels-even-to-strange-objects

aidoshacks commented 5 years ago

What exactly are you trying to do. If you are only trying to detect cotton and weeds you only need those two classes. If your model will be exposed to other objects like cars, you need to include images of cars in your dataset WITHOUT labels so that the model will simply ignore them.

Master-HM commented 5 years ago

What exactly are you trying to do. If you are only trying to detect cotton and weeds you only need those two classes. If your model will be exposed to other objects like cars, you need to include images of cars in your dataset WITHOUT labels so that the model will simply ignore them.

Why it behave like that? After all it is a general Object Detection model, Ideally after giving my custom data set for transfer learning, it should detect both my data +previously learned classes. Obviously it accurately bound box other objects like car, bike etc, but just label them as cotton or other.

As you said, add cars in your image data, WITHOUT label, so model will ignore it.

Question What to do if I want my model to detect all objects, on which it has been trained by google as well as detect both of my custom classes cotton and other? Kindly guide me if this is my target.

If I had to retrain complete coco dataset + my custom dataset from scratch, then how I can get fruits of Transfer learning?

EdjeElectronics commented 5 years ago

Hi @Master-HM ! Unfortunately, performing transfer learning wipes out the existing detection functionality. As far as I know, there is no way to make it continue to detect your classes plus the previously learned classes.

The previous poster is correct:

If your model will be exposed to other objects like cars, you need to include images of cars in your dataset WITHOUT labels so that the model will simply ignore them.