0

Multi-labeled image classification using 'inception resnet v2' model.

I'm changing the required part to a sigmoid.

Beyond a certain number of studies, it shows results such as softmax.

The code is part of the 'inception resnet v2' in use.

def inception_resnet_v2(inputs, num_classes=16, is_training=True, dropout_keep_prob=0.8, reuse=None,scope='InceptionResnetV2', create_aux_logits=True, activation_fn=tf.nn.sigmoid):

end_points = {}

with tf.variable_scope(scope, 'InceptionResnetV2', [inputs],
                     reuse=reuse) as scope:
with slim.arg_scope([slim.batch_norm, slim.dropout],
                    is_training=is_training):

  net, end_points = inception_resnet_v2_base(inputs, scope=scope,
                                             activation_fn=activation_fn)

  if create_aux_logits and num_classes:
    with tf.variable_scope('AuxLogits'):
      aux = end_points['PreAuxLogits']
      aux = slim.avg_pool2d(aux, 5, stride=3, padding='VALID',
                            scope='Conv2d_1a_3x3')
      aux = slim.conv2d(aux, 128, 1, scope='Conv2d_1b_1x1')
      aux = slim.conv2d(aux, 768, aux.get_shape()[1:3],
                        padding='VALID', scope='Conv2d_2a_5x5')
      aux = slim.flatten(aux)
      aux = slim.fully_connected(aux, num_classes, activation_fn=None,
                                 scope='Logits')
      end_points['AuxLogits'] = aux

  with tf.variable_scope('Logits'):
    # TODO(sguada,arnoegw): Consider adding a parameter global_pool which
    # can be set to False to disable pooling here (as in resnet_*()).
    kernel_size = net.get_shape()[1:3]
    if kernel_size.is_fully_defined():
      net = slim.avg_pool2d(net, kernel_size, padding='VALID',
                            scope='AvgPool_1a_8x8')
    else:
      net = tf.reduce_mean(net, [1, 2], keep_dims=True, name='global_pool')
    end_points['global_pool'] = net
    if not num_classes:
      return net, end_points
    net = slim.flatten(net)
    net = slim.dropout(net, dropout_keep_prob, is_training=is_training,
                       scope='Dropout')
    end_points['PreLogitsFlatten'] = net
    logits = slim.fully_connected(net, num_classes, activation_fn=None,
                                  scope='Logits')
    end_points['Logits'] = logits

    end_points['Predictions'] = tf.nn.sigmoid(logits, name='Predictions')

return logits, end_points

def inception_resnet_v2_arg_scope(
weight_decay=0.00004,
batch_norm_decay=0.9997,
batch_norm_epsilon=0.001,
activation_fn=tf.nn.sigmoid,
batch_norm_updates_collections=tf.GraphKeys.UPDATE_OPS,
batch_norm_scale=False):

with slim.arg_scope([slim.conv2d, slim.fully_connected],
                  weights_regularizer=slim.l2_regularizer(weight_decay),
                  biases_regularizer=slim.l2_regularizer(weight_decay)):

batch_norm_params = {
    'decay': batch_norm_decay,
    'epsilon': batch_norm_epsilon,
    'updates_collections': batch_norm_updates_collections,
    'fused': None,  # Use fused batch norm if possible.
    'scale': batch_norm_scale,
}
# Set activation_fn and parameters for batch_norm.
with slim.arg_scope([slim.conv2d], activation_fn=activation_fn,
                    normalizer_fn=slim.batch_norm,
                    normalizer_params=batch_norm_params) as scope:
  return scope

Is there a case like me?

Or I wonder if I haven't used the sigmoid properly

AZDDKKS
  • 41
  • 1
  • 8
  • Are you getting any errors? How is loss function defined? What is your problem exactly? – Sharky May 22 '19 at 12:21
  • There is no error in the code. But I changed the code to sigmoid in order to multi-label classification, but the result is car 0.97 red 0.01 Sport car 0.02 Because it looks like softmax, I want to get the idea of whether the place I modified with sigmoid is wrong. Of course, the input picture is a red sports car. – AZDDKKS May 23 '19 at 06:06
  • What loss function are you using? – Sharky May 23 '19 at 08:19
  • use 'slim.losses.sigmoid_cross_entropy' – AZDDKKS May 23 '19 at 10:49
  • please add code – Sharky May 23 '19 at 11:01
  • Use 'slim.losses.binary_cross_entropy' in line 450 at link 'train_image_classifier.py' https://github.com/tensorflow/models/tree/master/research/slim – AZDDKKS May 24 '19 at 04:55

0 Answers0