omoindrot / tensorflow-triplet-loss

Implementation of triplet loss in TensorFlow
https://omoindrot.github.io/triplet-loss
MIT License
1.12k stars 283 forks source link

the parameter 'num_channels' #9

Closed Welxiao closed 6 years ago

Welxiao commented 6 years ago

Excuse me, Sir. Thanks for you code of triplet loss, but i don't understand the 'num_channels=32' means in 'params.json'. In general, the channels of a picture are 1 or 3, 'num_channels=32' perplexes me. Could you help me , thanks much.

omoindrot commented 6 years ago

The num_channels parameter is just something I use when I build the model to determine how many channels will be in the first convolution.

It is used in the function build_model, here is a link.

num_channels = params.num_channels
bn_momentum = params.bn_momentum
channels = [num_channels, num_channels * 2]
for i, c in enumerate(channels):
    with tf.variable_scope('block_{}'.format(i+1)):
        out = tf.layers.conv2d(out, c, 3, padding='same')
        if params.use_batch_norm:
            out = tf.layers.batch_normalization(out, momentum=bn_momentum, training=is_training)
        out = tf.nn.relu(out)
        out = tf.layers.max_pooling2d(out, 2, 2)

I put it in the params.json file so that I can easily change how big the model is. So if the model is overfitting with num_channels=64 I could modify it to num_channels=32.

Welxiao commented 6 years ago

thanks for your answer