Achilles
Achilles

Reputation: 1129

Tensorflow padding with 1s instead of zeroes

Tensorflow functions seem to use only zeroes for padding (for example, the tf.nn.conv2d function).

Is there an easy way (that requires minimal changes in existing code) to run the same functions with paddings of 1s or any other arbitrary numbers instead of zeroes?

Upvotes: 0

Views: 55

Answers (1)

Steven
Steven

Reputation: 5162

The easiest way would be to change the padding in conv2d from "SAME" to "VALID" and perform the padding yourself.

img = tf.ones([img_height+padding,img_width+padding, channels])
img[padding//2:img_height, padding//2:img_width] = old_img
result = conv2d(img, kernel, padding="VALID")

Upvotes: 1

Related Questions