rykov8 / ssd_keras

Port of Single Shot MultiBox Detector to Keras
MIT License
1.1k stars 553 forks source link

How to train the model on a single class?(Changes required in get_data_from_XML.py) #114

Open ManjeeraJagiri opened 6 years ago

ManjeeraJagiri commented 6 years ago

These are the changes I have made: In SSD_training.py, I changed NUM_CLASSES = 2 to include my class +background In get_data_from_XML.py, I changed self.num_classes = 1 and _to_one_hot function as

    def _to_one_hot(self,name):
        one_hot_vector = [0] * self.num_classes
        if name == 'person':
            one_hot_vector[0] = 1
        else:
            print('unknown label: %s' %name)

        return one_hot_vector

Is it okay to encode labels, when there is only one class present? I am still training the model(No gpu, it will take time), so I am not sure if it will work. Any help is greatly appreciated!

nkoudounas commented 6 years ago

Theoretically is equivalent. But it is recommended to use sigmoid instead of softmax because you will reduce the computation time. Let p1 be the probability of success (class = '1') and p2=1-p1 the probability of class '0'. With sigmoid activation u need to compute only p1 (so u know p2=1-p1), but with softmax u will compute p1 and p2 together (p2 is redundant) . So imo if you want to be computationally efficient, u should use the sigmoid version.