google-research / receptive_field

Compute receptive fields of your favorite convnets
Apache License 2.0
434 stars 54 forks source link

Getting None in effective padding #12

Closed divyagupta25 closed 1 year ago

divyagupta25 commented 1 year ago

Hi @andrefaraujo I have a 2 layer ConvNet and I am using the following code

g = tf.Graph()
with g.as_default():
    x = tf.placeholder(tf.float32, shape=(1, 384, 384, 3), name='input_image')
    model = models.Sequential()
    model.add(layers.Conv2D(filters=64, kernel_size=(7, 7), strides=(2, 2), activation='relu', use_bias=False, padding='same', input_shape=(384, 384, 3)))      
    model.add(layers.MaxPooling2D(pool_size=(2, 2), strides=(2, 2), padding='same'))    
    model.add(layers.Conv2D(filters=384, kernel_size=(7, 7), strides=(2, 2), activation='relu', use_bias=False, padding='same'))                             
    model.add(layers.MaxPooling2D(pool_size=(2, 2), strides=(2, 2), padding='same', name='op'))   
    output = model(x)

res = [n.name for n in g.as_graph_def().node]     # print(res)

rf_x, rf_y, eff_stride_x, eff_stride_y, eff_pad_x, eff_pad_y = rf.compute_receptive_field_from_graph_def(g.as_graph_def(), 'conv2d_input', 'op/MaxPool')

I am getting None in eff_pad_x and eff_pad_y. Could you please tell if it means an effective padding of zero, or if I am using the function incorrectly?

ratom commented 1 year ago

I am unable to find the receptive fields of the pretrained models like resnet. How to implement in those models

andrefaraujo commented 1 year ago

@divyagupta25 : I believe this is an issue with TF's SAME padding, which applies variable padding depending on the input resolution. For this reason, the padding will depend on the input resolution and the effective padding parameters will only be valid when you provide a specific input resolution, as you reported in https://github.com/google-research/receptive_field/issues/1#issuecomment-1566696805

@ratom : they can be found here: https://github.com/google-research/receptive_field/blob/master/receptive_field/RECEPTIVE_FIELD_TABLE.md