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

Model detects only 1 class #7

Open bassmaamn opened 6 years ago

bassmaamn commented 6 years ago

I want to train the model to detect 2 classes, but after training it recognize only 1 class

KingsonSingh commented 6 years ago

I trained two models with 14 classes and 6 classes, but after training both model it recognize only 1 class.

Did any one finds the solution? Please share !! Thank you !!!

skvravi108 commented 6 years ago

I trained on 7 classes, But after training the model it is able to recognize only 1 class.

Can any one suggest to detect multiple classes.

noelcodes commented 6 years ago

I had this problem before, then I found the solution is just the naming of the folders. Check your faster_rcnn_xxxxxx.config file, all path is pointing to the correct folder names.

Example : "C:/tensorflow1/models/research/object_detection/ Not : "C:/tensorflow1/models_new/research/object_detection/

If you have renamed your folders (for whatever reason), then you had to rename your codes pointing to the correct folder names. Else it will continue to point to Edie's old path which is only classifying 6x items or 1x class by coincidence your 1x class is one of Edje's cards.

Go check your paths.

leccyril commented 6 years ago

you have to modify label.pbtxt file and model training config file and generate_tf.py file

JayLee15 commented 6 years ago

I have modified label.pbtxt file and model training config file and generate_tf.py file. But it recognize only 1 class. Did any one finds the solution?

leccyril commented 6 years ago

@JayLee15 did you modify the pipeline.config too ? there is the number class to specify too

JayLee15 commented 6 years ago

@leccyril Yes, I have modified the number class in pipeline.config, but it recognizes only 1 class.

leccyril commented 6 years ago

what sample training did you use ? coco or pet detection ? maybe you can share your configuration files

generate tf record, label.pbtxt and the model configuration file

2 solutions, either you have somewhere 1 class configured or you have only few pictures for the second class

did you launch the train and eval and follow it on tensorboard ?

mking1011 commented 5 years ago

@JayLee15 @bassmaamn @leccyril

Did you solve this problem?

Could you check the file I modified?

Desktop.zip

simonegrazioso commented 5 years ago

Did anyone found a solution? It's like impossible to train multi-class object detection. With only one class I had no problem. If I want to train faster_rcnn to detect two different classes, e.g. car and person, it can detect only one of this with good accuracy, and which object can detect (of the two classes) changes randomly during the training steps (example: step 1000 it detect only cars, step 2000 only person, step 3000 cars, step 4000 cars, step 5000 person, etc..).

Obiously my dataset is balanced (1400 images for the first class, 1550 for the second one).

leccyril commented 5 years ago

there is no problem to train with multi classes just fill files i've mentionned before

leccyril commented 5 years ago

@mking1011

it seems to be OK , what's happening when you check the eval on tensorboard ?

@simonegrazioso

it is what you see on eval board ?

simonegrazioso commented 5 years ago

@leccyril

there is no problem to train with multi classes just fill files i've mentionned before

the files are all filled, otherwise there will be only one class detected and always the same one. Indeed, I detect both classes, rarely together, with very low accuracy when trained together. If i train the two classes separately, I have a good precision (50-55%).

@simonegrazioso

it is what you see on eval board ?

Exactly.

Can u send me a link to your working dataset + generate tf record + label.pbtxt + model configuration file? Maybe there's a small error, even if I didn't change anything on the faster rcnn config file.. only number of classes. Label.pbtxt and generate tf record are ok, i check the tfrecords.

Chloejay commented 5 years ago

I have the same problem, the output just return one class, can someone advised me is I shouldn't write this in the code with tf.Session() as sess: for _image, _image_name in zip(_images,_image_names): _image_expanded = np.expand_dims(_image, axis=0) image_tensor = tf.get_default_graph().get_tensor_by_name('image_tensor:0') scores= g1.get_tensor_by_name('detection_scores:0') classes= g1.get_tensor_by_name('detection_classes:0')
(scores, classes) = sess.run([scores, classes], feed_dict={image_tensor:_image_expanded}) for score, cls in zip(scores, classes): score = score[0] cls = cls[0] _results.append({"name":_image_name, "pred_prob":score, "class_name":cls}) print(score, cls)

return _results  

I take the last one as the model output

niyanthh87 commented 5 years ago

In my case it was in label_map.pbtxt the label name i had given was "Car" where in annotation it was "car" check the annotation label and write accordingly as label_map.pbtxt is case Sensitive

keertika-j commented 4 years ago

While converting the files from xml to csv , did you mention all the labels properly ?

djalusic commented 4 years ago

According to this link, the filenames have to be shuffled inside the generate_tfrecords.py in order to properly train the model to detect multiple classes.

Sangharsh-kamble commented 4 years ago

you have to check labelmap file ie. .pbtxt files. it has id number for each label. also while creating .record file need to be assign this labels in code

mehmetsoylu commented 4 years ago

@JayLee15 @bassmaamn @leccyril @bassmaamn i have the same problem with yours. Did you solved your problem? If you solved it, how did you solved it? Can you please explain to me?

JayLee15 commented 4 years ago

@JayLee15 @bassmaamn @leccyril @bassmaamn i have the same problem with yours. Did you solved your problem? If you solved it, how did you solved it? Can you please explain to me? In my case, all categories of images are very similar. I increase the parameter 'second_stage_classification_loss_weight' and retrain to solve this problem.

mehmetsoylu commented 4 years ago

@JayLee15 i am new on object detection so i dont know how to do that. How do i increase my 'second_stage_classification_loss_weight' ?

SOTASHE commented 3 years ago

@mehmetsoylu I'm facing the same problem.. I have 5 classes but my model only detect the first class

devil1209 commented 1 year ago

i trained the object detection model for 13 classes using ssd mobilenetv2 but it is always predicting one class which has the lowest number of images and i have also checked the label map and annnotations files. can anyone could suggest something here