Open lizhenstat opened 4 years ago
@pudae Hi, any suggestion would be appreciated
Hi @lizhenstat,
Do you mean the feature map sizes of this implementation are [55,27,13,6]? right?
If so, the difference is caused by net = slim.max_pool2d(net, 3, stride=2, padding='SAME')
, not first convolution.
But it's strange because following the padding algorithm, 'SAME' padding is right.
(from https://www.tensorflow.org/api_docs/python/tf/nn/convolution)
if data_format starts with "NC", where output_spatial_shape depends on the value of padding. If padding == "SAME": output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides[i]) If padding == "VALID": output_spatial_shape[i] = ceil((input_spatial_shape[i] - (spatial_filter_shape[i]-1) * dilation_rate[i]) / strides[i]).
Here's a test code using tf 2.0. (I'm sorry that I don't have an environment to test my code.)
import tensorflow as tf
input_value = tf.constant(0, shape=(1,224,224,3), dtype=tf.float32)
filter_value = tf.constant(0, shape=(7,7,3,64), dtype=tf.float32)
out_conv = tf.nn.conv2d(input_value, filter_value, strides=2, padding='SAME')
out_maxpool = tf.nn.max_pool_2d(out_conv, ksize=3, strides=2, padding='SAME')
print('input_value:', input_value.shape)
print('out_conv:', out_conv.shape)
print('out_maxpool:', out_maxpool.shape)
The output is
input_value: (1, 224, 224, 3)
out_conv: (1, 112, 112, 64)
out_max_pool: (1, 56, 56, 64)
@pudae Yes, the implementation of this code is [55,27,13,6].
Thanks for your reply, since I want to do some visualization based on your ImageNet pre-trained model. The nets/densenet.py is the code for training the densenet-121 on ImageNet right?
(The script is using net = slim.max_pool2d(net, 3, stride=2, padding='VALID')
therefore causing
this [55,27,13,6] output feature map size)
I got confused since in the original denseNet paper, the feature map size after each block is [112,56,28,14,7]
After this net = slim.max_pool2d(net, 3, stride=2, padding='SAME')
code, the output size match the original paper.
Yes, as you said, I think the "SAME" padding is more reasonable.
Besides, is it okay to cite your pre-trained model based on your Github repo? As I posted in this issue https://github.com/pudae/tensorflow-densenet/issues/27 Thanks a lot
Hi, thanks for your work. I found the DenseNet-121 on ImageNet's feature map size in each block is [56,28,14,7], however in the pre-trained model is [55,27,13,6]
do we need to change the this line to the following in densenet.py
to
Looking forward to your reply