What is difference between padding and output_padding

I want to get the padding of conv2d in module.register_forward_hook
However, I get padding and output_padding in dir(conv2d_module), what is the difference between them? Which one should I use?

dir(module) # conv2d

['__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__format__', '__getattr__', 
'__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__r
epr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_all
_buffers', '_apply', '_backend', '_backward_hooks', '_buffers', '_forward_hooks', '_forward_pre_hooks', 
'_get_name', '_load_from_state_dict', '_modules', '_parameters', '_slow_forward', '_tracing_name', '_ver
sion', 'add_module', 'apply', 'bias', 'children', 'cpu', 'cuda', 'dilation', 'double', 'dump_patches', '
eval', 'extra_repr', 'float', 'forward', 'groups', 'half', 'in_channels', 'kernel_size', 'load_state_dic
t', 'modules', 'named_children', 'named_modules', 'named_parameters', 'out_channels', 'output_padding', 
'padding', 'parameters', 'register_backward_hook', 'register_buffer', 'register_forward_hook', 'register
_forward_pre_hook', 'register_parameter', 'reset_parameters', 'share_memory', 'state_dict', 'stride', 't
o', 'train', 'training', 'transposed', 'type', 'weight', 'zero_grad']

output_padding is used in transposed conv layers. Have a look at the notes in the doc.

1 Like

Thanks
I see, the original input_size for transposed conv layer is ambiguious because output_size=math.floor(xxx / stride).