Exemple #1
0
 def basic_model_properties(self, cf, variable_input_size):
     # Define the input size, loss and metrics
     if cf.dataset.class_mode == 'categorical':
         if K.image_dim_ordering() == 'th':
             in_shape = (cf.dataset.n_channels, cf.target_size_train[0],
                         cf.target_size_train[1])
         else:
             in_shape = (cf.target_size_train[0], cf.target_size_train[1],
                         cf.dataset.n_channels)
         loss = 'categorical_crossentropy'
         metrics = ['accuracy']
     elif cf.dataset.class_mode == 'detection':
         if cf.model_name == 'ssd512':
             in_shape = (cf.target_size_train[0], cf.target_size_train[1],
                         cf.dataset.n_channels)
             #in_shape = (cf.dataset.n_channels, cf.target_size_train[0], cf.target_size_train[1])
             loss = MultiboxLoss(cf.dataset.n_classes)
             metrics = []
         else:
             in_shape = (cf.dataset.n_channels, cf.target_size_train[0],
                         cf.target_size_train[1])
             # TODO detection : check model, different detection nets may have different losses and metrics
             loss = YOLOLoss(in_shape, cf.dataset.n_classes,
                             cf.dataset.priors)
             metrics = [
                 YOLOMetrics(in_shape,
                             cf.dataset.n_classes,
                             cf.dataset.priors,
                             name='avg_recall'),
                 YOLOMetrics(in_shape,
                             cf.dataset.n_classes,
                             cf.dataset.priors,
                             name='avg_iou')
             ]
     elif cf.dataset.class_mode == 'segmentation':
         if K.image_dim_ordering() == 'th':
             if variable_input_size:
                 in_shape = (cf.dataset.n_channels, None, None)
             else:
                 in_shape = (cf.dataset.n_channels, cf.target_size_train[0],
                             cf.target_size_train[1])
         else:
             if variable_input_size:
                 in_shape = (None, None, cf.dataset.n_channels)
             else:
                 in_shape = (cf.target_size_train[0],
                             cf.target_size_train[1], cf.dataset.n_channels)
         #loss = cce_flatt(cf.dataset.void_class, cf.dataset.cb_weights)
         #metrics = [IoU(cf.dataset.n_classes, cf.dataset.void_class)]
         loss = 'categorical_crossentropy'
         metrics = ['accuracy', jaccard_coef]
     else:
         raise ValueError('Unknown problem type')
     return in_shape, loss, metrics
Exemple #2
0
    def basic_model_properties(self, cf, variable_input_size):
        # Define the input size, loss and metrics
        if cf.dataset.class_mode == 'categorical':
            if K.image_dim_ordering() == 'th':
                in_shape = (cf.dataset.n_channels,
                            cf.target_size_train[0],
                            cf.target_size_train[1])
            else:
                in_shape = (cf.target_size_train[0],
                            cf.target_size_train[1],
                            cf.dataset.n_channels)
            loss = 'categorical_crossentropy'
            metrics = ['accuracy']
        elif cf.dataset.class_mode == 'detection':

            # Check model, different detection nets may have different losses and metrics
            if cf.model_name in ['yolo', 'tiny-yolo']:
                in_shape = (cf.dataset.n_channels,
                            cf.target_size_train[0],
                            cf.target_size_train[1])
                loss = YOLOLoss(in_shape, cf.dataset.n_classes, cf.dataset.priors)
                metrics = [YOLOMetrics(in_shape, cf.dataset.n_classes, cf.dataset.priors)]
            elif cf.model_name == 'ssd300':
                in_shape = (cf.target_size_train[0],
                            cf.target_size_train[1], cf.dataset.n_channels)

                loss = MultiboxLoss(cf.dataset.n_classes, neg_pos_ratio=2.0).compute_loss
                metrics = None
                # TODO: Add metrics for SSD
                # priors = pickle.load(open('prior_boxes_ssd300.pkl', 'rb'))
                # metrics = [SSDMetrics(priors, cf.dataset.n_classes)]
            else:
                raise NotImplementedError

        elif cf.dataset.class_mode == 'segmentation':
            if K.image_dim_ordering() == 'th':
                if variable_input_size:
                    in_shape = (cf.dataset.n_channels,
                                None,
                                None)
                else:
                    in_shape = (cf.dataset.n_channels,
                                cf.target_size_train[0],
                                cf.target_size_train[1])
            else:
                if variable_input_size:
                    in_shape = (None,
                                None,
                                cf.dataset.n_channels)
                else:
                    in_shape = (cf.target_size_train[0],
                                cf.target_size_train[1],
                                cf.dataset.n_channels)
            loss = cce_flatt(cf.dataset.void_class, cf.dataset.cb_weights)
            metrics = [IoU(cf.dataset.n_classes, cf.dataset.void_class)]
        else:
            raise ValueError('Unknown problem type')
        return in_shape, loss, metrics
Exemple #3
0
    def basic_model_properties(self, cf, variable_input_size):
        # Define the input size, loss and metrics
        if cf.dataset.class_mode == 'categorical':
            if K.image_dim_ordering() == 'th':
                in_shape = (cf.dataset.n_channels, cf.target_size_train[0],
                            cf.target_size_train[1])
            else:
                in_shape = (cf.target_size_train[0], cf.target_size_train[1],
                            cf.dataset.n_channels)
            loss = 'categorical_crossentropy'
            metrics = ['accuracy']
        elif cf.dataset.class_mode == 'detection':

            if cf.model_name in ['yolo', 'tiny-yolo']:
                in_shape = (cf.dataset.n_channels, cf.target_size_train[0],
                            cf.target_size_train[1])
                loss = YOLOLoss(in_shape, cf.dataset.n_classes,
                                cf.dataset.priors)
                metrics = [
                    YOLOMetrics(in_shape, cf.dataset.n_classes,
                                cf.dataset.priors)
                ]
            elif cf.model_name in [
                    'ssd300', 'ssd300_pretrained', 'ssd_resnet50'
            ]:
                # TODO: in_shape ok for ssd?
                in_shape = (cf.target_size_train[0], cf.target_size_train[1],
                            cf.dataset.n_channels)

                # TODO: extract config parameters from MultiboxLoss
                mboxloss = MultiboxLoss(cf.dataset.n_classes + 1,
                                        alpha=1.0,
                                        neg_pos_ratio=2.0,
                                        background_label_id=0,
                                        negatives_for_hard=100.0)
                loss = mboxloss.compute_loss
                metrics = []  # TODO: add mAP metric

        elif cf.dataset.class_mode == 'segmentation':
            if K.image_dim_ordering() == 'th':
                if variable_input_size:
                    in_shape = (cf.dataset.n_channels, None, None)
                else:
                    in_shape = (cf.dataset.n_channels, cf.target_size_train[0],
                                cf.target_size_train[1])
            else:
                if variable_input_size:
                    in_shape = (None, None, cf.dataset.n_channels)
                else:
                    in_shape = (cf.target_size_train[0],
                                cf.target_size_train[1], cf.dataset.n_channels)
            loss = cce_flatt(cf.dataset.void_class, cf.dataset.cb_weights)
            metrics = [IoU(cf.dataset.n_classes, cf.dataset.void_class)]
        else:
            raise ValueError('Unknown problem type')
        return in_shape, loss, metrics
Exemple #4
0
 def basic_model_properties(self, cf, variable_input_size):
     # Define the input size, loss and metrics
     if cf.dataset.class_mode == 'categorical':
         if K.image_dim_ordering() == 'th':
             in_shape = (cf.dataset.n_channels, cf.target_size_train[0],
                         cf.target_size_train[1])
         else:
             in_shape = (cf.target_size_train[0], cf.target_size_train[1],
                         cf.dataset.n_channels)
         loss = 'categorical_crossentropy'
         metrics = ['accuracy']
     elif cf.dataset.class_mode == 'detection':
         if cf.model_name in ['yolo', 'tiny-yolo']:
             in_shape = (cf.dataset.n_channels, cf.target_size_train[0],
                         cf.target_size_train[1])
             loss = YOLOLoss(in_shape, cf.dataset.n_classes,
                             cf.dataset.priors)
             metrics = [
                 YOLOMetrics(in_shape, cf.dataset.n_classes,
                             cf.dataset.priors)
             ]
         elif cf.model_name == 'ssd':
             if K.image_dim_ordering() == 'th':
                 in_shape = (cf.dataset.n_channels, cf.target_size_train[0],
                             cf.target_size_train[1])
             else:
                 in_shape = (cf.target_size_train[0],
                             cf.target_size_train[1], cf.dataset.n_channels)
             loss = SSDLoss(in_shape, cf.dataset.n_classes + 1,
                            cf.dataset.priors)  #+1 to include background
             #metrics = [SSDMetrics(in_shape, cf.dataset.n_classes, cf.dataset.priors)]
             metrics = []
         else:
             raise ValueError('Unknown model')
     elif cf.dataset.class_mode == 'segmentation':
         if K.image_dim_ordering() == 'th':
             if variable_input_size:
                 in_shape = (cf.dataset.n_channels, None, None)
             else:
                 in_shape = (cf.dataset.n_channels, cf.target_size_train[0],
                             cf.target_size_train[1])
         else:
             if variable_input_size:
                 in_shape = (None, None, cf.dataset.n_channels)
             else:
                 in_shape = (cf.target_size_train[0],
                             cf.target_size_train[1], cf.dataset.n_channels)
         loss = cce_flatt(cf.dataset.void_class, cf.dataset.cb_weights)
         metrics = [IoU(cf.dataset.n_classes, cf.dataset.void_class)]
     else:
         raise ValueError('Unknown problem type')
     return in_shape, loss, metrics
    def basic_model_properties(self, cf, variable_input_size):
        # Define the input size, loss and metrics
        if cf.dataset.class_mode == 'categorical':
            if K.image_dim_ordering() == 'th':
                in_shape = (cf.dataset.n_channels,
                            cf.target_size_train[0],
                            cf.target_size_train[1])
            else:
                in_shape = (cf.target_size_train[0],
                            cf.target_size_train[1],
                            cf.dataset.n_channels)
            loss = 'categorical_crossentropy'
            metrics = ['accuracy']
    
        elif cf.dataset.class_mode == 'detection':
            in_shape = (cf.dataset.n_channels,
                        cf.target_size_train[0],
                        cf.target_size_train[1])
            # TODO detection : check model, different detection nets may have different losses and metrics
            loss = YOLOLoss(in_shape, cf.dataset.n_classes, cf.dataset.priors)
            metrics = [YOLOMetrics(in_shape, cf.dataset.n_classes, cf.dataset.priors)]

        elif cf.dataset.class_mode == 'segmentation':
            if K.image_dim_ordering() == 'th':
                if variable_input_size:
                    in_shape = (cf.dataset.n_channels, None, None)
                else:
                    in_shape = (cf.dataset.n_channels,
                                cf.target_size_train[0],
                                cf.target_size_train[1])
            else:
                if variable_input_size:
                    in_shape = (None, None, cf.dataset.n_channels)
                else:
                    in_shape = (cf.target_size_train[0],
                                cf.target_size_train[1],
                                cf.dataset.n_channels)
            #loss = cce_flatt(cf.dataset.void_class, cf.dataset.cb_weights)
            # metrics = [IoU(cf.dataset.n_classes, cf.dataset.void_class)]
            loss = 'binary_crossentropy' 
            metrics = ['accuracy']

            print '----in_shape----', in_shape
            print '-----loss ----- ', loss
            print '-----metrics****++++ ', metrics
        else:
            raise ValueError('Unknown problem type')

        return in_shape, loss, metrics
Exemple #6
0
 def basic_model_properties(self, cf, variable_input_size):
     # Define the input size, loss and metrics
     if cf.dataset.class_mode == 'categorical':
         if K.image_dim_ordering() == 'th':
             in_shape = (cf.dataset.n_channels,
                         cf.target_size_train[0],
                         cf.target_size_train[1])
         else:
             in_shape = (cf.target_size_train[0],
                         cf.target_size_train[1],
                         cf.dataset.n_channels)
         loss = 'categorical_crossentropy'
         metrics = ['accuracy']
     elif cf.dataset.class_mode == 'detection':
         if cf.model_name == 'ssd':
             in_shape = (cf.target_size_train[0],
                         cf.target_size_train[1],
                         cf.dataset.n_channels,)
             loss = MultiboxLoss(cf.dataset.n_classes, neg_pos_ratio=2.0).compute_loss
             metrics = None
         else: # YOLO
             in_shape = (cf.dataset.n_channels,
                         cf.target_size_train[0],
                         cf.target_size_train[1])
             loss = YOLOLoss(in_shape, cf.dataset.n_classes, cf.dataset.priors)
             metrics = [YOLOMetrics(in_shape, cf.dataset.n_classes, cf.dataset.priors)]
     elif cf.dataset.class_mode == 'segmentation':
         if K.image_dim_ordering() == 'th':
             if variable_input_size:
                 in_shape = (cf.dataset.n_channels, None, None)
             else:
                 in_shape = (cf.dataset.n_channels,
                             cf.target_size_train[0],
                             cf.target_size_train[1])
         else:
             if variable_input_size:
                 in_shape = (None, None, cf.dataset.n_channels)
             else:
                 in_shape = (cf.target_size_train[0],
                             cf.target_size_train[1],
                             cf.dataset.n_channels)
         loss = cce_flatt(cf.dataset.void_class, cf.dataset.cb_weights)
         metrics = [IoU(cf.dataset.n_classes, cf.dataset.void_class)]
     else:
         raise ValueError('Unknown problem type')
     return in_shape, loss, metrics
    def basic_model_properties(self, cf, variable_input_size):
        # Define the input size, loss and metrics
        if cf.dataset.class_mode == 'categorical':
            if K.image_dim_ordering() == 'th':
                in_shape = (cf.dataset.n_channels,
                            cf.target_size_train[0],
                            cf.target_size_train[1])

            else:
                in_shape = (cf.target_size_train[0],
                            cf.target_size_train[1],
                            cf.dataset.n_channels)

            loss = 'categorical_crossentropy'
            metrics = ['accuracy']

        elif cf.dataset.class_mode == 'detection':
            if 'yolo' in cf.model_name:
                in_shape = (cf.dataset.n_channels,
                            cf.target_size_train[0],
                            cf.target_size_train[1])

                loss = YOLOLoss(in_shape, cf.dataset.n_classes, cf.dataset.priors)
                metrics = [YOLOMetrics(in_shape, cf.dataset.n_classes, cf.dataset.priors)]

            elif cf.model_name == 'ssd':
                in_shape = (cf.target_size_train[0],
                            cf.target_size_train[1],
                            cf.dataset.n_channels)
                loss = MultiboxLoss(cf.dataset.n_classes, neg_pos_ratio=2.0).compute_loss
                metrics = [] # TODO: There is no metrics for the ssd model

            else:
                raise ValueError('Uknown "' + cf.model_name + '" name for the ' + cf.dataset.class_mode + ' problem type.'
                                'Only is implemented for: {yolo, tiny-yolo, ssd}')

        elif cf.dataset.class_mode == 'segmentation':
            if K.image_dim_ordering() == 'th':
                if variable_input_size:
                    in_shape = (cf.dataset.n_channels, None, None)
                else:
                    in_shape = (cf.dataset.n_channels,
                                cf.target_size_train[0],
                                cf.target_size_train[1])

            else:
                if variable_input_size:
                    in_shape = (None, None, cf.dataset.n_channels)
                else:
                    in_shape = (cf.target_size_train[0],
                                cf.target_size_train[1],
                                cf.dataset.n_channels)


            loss = cce_flatt(cf.dataset.void_class, cf.dataset.cb_weights)
            metrics = [IoU(cf.dataset.n_classes, cf.dataset.void_class)]

            # if cf.model_name == 'fcn8':
            #     loss = cce_flatt(cf.dataset.void_class, cf.dataset.cb_weights)
            #     metrics = [IoU(cf.dataset.n_classes, cf.dataset.void_class)]
            #
            # elif 'segnet' in cf.model_name:
            #     loss = 'categorical_crossentropy'
            #     metrics = []
            #
            # else:
            #     raise ValueError('Uknown "'+cf.model_name+'" name for the '+cf.dataset.class_mode+' problem type.'
            #                     'Only is implemented for: {fc8, segnet}')

        else:
            raise ValueError('Unknown problem type')

        return in_shape, loss, metrics