Пример #1
0
    def extract_features(self, inputs):
        mean = tf.constant(
            self.cfg['mean_pixel'], dtype=tf.float32, shape=[1, 1, 1, 3], name="img_mean"
        )
        im_centered = inputs - mean

        if 'resnet' in self.cfg['net_type']:
            # The next part of the code depends upon which tensorflow version you have.
            vers = tf.__version__
            vers = vers.split(
                "."
            )  # Updated based on https://github.com/AlexEMG/DeepLabCut/issues/44

            net_fun = net_funcs[self.cfg['net_type']]
            if int(vers[0]) == 1 and int(vers[1]) < 4:  # check if lower than version 1.4.
                with slim.arg_scope(resnet_v1.resnet_arg_scope(False)):
                    net, end_points = net_fun(
                        im_centered, global_pool=False, output_stride=16
                    )
            else:
                with slim.arg_scope(resnet_v1.resnet_arg_scope()):
                    net, end_points = net_fun(
                        im_centered, global_pool=False, output_stride=16, is_training=False
                    )
        elif 'mobilenet' in self.cfg['net_type']:
            net_fun = net_funcs[self.cfg['net_type']]
            with slim.arg_scope(mobilenet_v2.training_scope()):
                net, end_points = net_fun(im_centered)
        elif 'efficientnet' in self.cfg['net_type']:
            im_centered /= tf.constant(eff.STDDEV_RGB, shape=[1, 1, 3])
            net, end_points = eff.build_model_base(im_centered,
                                                   self.cfg['net_type'],
                                                   use_batch_norm=self.cfg['use_batch_norm'],
                                                   drop_out=self.cfg['use_drop_out'])
        return net, end_points
Пример #2
0
 def extract_features(self,
                      inputs,
                      use_batch_norm=False,
                      use_drop_out=False):
     mean = tf.constant(self.cfg.mean_pixel,
                        dtype=tf.float32,
                        shape=[1, 1, 1, 3],
                        name='img_mean')
     im_centered = inputs - mean
     im_centered /= tf.constant(eff.STDDEV_RGB, shape=[1, 1, 3])
     with tf.variable_scope("efficientnet"):
         eff_net_type = self.cfg.net_type.replace('_', '-')
         net, end_points = eff.build_model_base(
             im_centered,
             eff_net_type,
             use_batch_norm=use_batch_norm,
             drop_out=use_drop_out)
     return net, end_points