TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10 icon indicating copy to clipboard operation
TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10 copied to clipboard

Model detects only 1 class

Open bassmaamn opened this issue 7 years ago • 23 comments
trafficstars

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

bassmaamn avatar Mar 19 '18 07:03 bassmaamn

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 !!!

KingsonSingh avatar Apr 22 '18 04:04 KingsonSingh

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.

skvravi108 avatar May 28 '18 06:05 skvravi108

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.

noelcodes avatar May 28 '18 14:05 noelcodes

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

leccyril avatar Jun 28 '18 07:06 leccyril

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?

JayLee15 avatar Aug 26 '18 07:08 JayLee15

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

leccyril avatar Aug 27 '18 07:08 leccyril

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

JayLee15 avatar Aug 27 '18 07:08 JayLee15

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 ?

leccyril avatar Aug 27 '18 07:08 leccyril

@JayLee15 @bassmaamn @leccyril

Did you solve this problem?

Could you check the file I modified?

Desktop.zip

mking1011 avatar Sep 20 '18 00:09 mking1011

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).

simonegrazioso avatar Jan 29 '19 09:01 simonegrazioso

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

leccyril avatar Jan 29 '19 09:01 leccyril

@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 ?

leccyril avatar Jan 29 '19 09:01 leccyril

@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.

simonegrazioso avatar Jan 29 '19 09:01 simonegrazioso

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

Chloejay avatar Jun 11 '19 14:06 Chloejay

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

niyanthh87 avatar Aug 07 '19 04:08 niyanthh87

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

keertika-j avatar Nov 06 '19 09:11 keertika-j

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.

djalusic avatar Dec 18 '19 13:12 djalusic

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

Sangharsh-kamble avatar Jan 29 '20 12:01 Sangharsh-kamble

@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?

mehmetsoylu avatar Apr 18 '20 23:04 mehmetsoylu

@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.

JayLee15 avatar May 25 '20 10:05 JayLee15

@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' ?

mehmetsoylu avatar May 25 '20 11:05 mehmetsoylu

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

SOTASHE avatar Jan 11 '21 19:01 SOTASHE

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

devil1209 avatar Oct 13 '22 09:10 devil1209