TensorFlow

tensorflow中卷积操作的padding参数

padding = "same"

outh=ceil(inhstrideh)outw=ceil(inwstridew)Note: index of h is 0, index of w is 1out_h = ceil(\frac{in_h}{stride_h})\\ out_w = ceil(\frac{in_w}{stride_w})\\ \text{Note: index of h is 0, index of w is 1}

padding = "valid"

outh=ceil(inh(filterh1)dilationhstrideh)outw=ceil(inw(filterw1)dilationwstridew)out_h=ceil(\frac{in_h-(filter_h-1)*dilation_h}{stride_h})\\ out_w=ceil(\frac{in_w-(filter_w-1)*dilation_w}{stride_w})
filters = tf.reshape(tf.constant([1., 1., 2.]), (3, 1, 1))
x = tf.reshape(tf.constant([1., 1., 0., 2., 1.]), (1, 5, 1))
tf.nn.convolution(x, filters, strides=2, padding="VALID").numpy().squeeze()
# [2, 4]
tf.nn.convolution(x, filters, strides=2, padding="SAME").numpy().squeeze()
# [3, 5, 3]

filters = tf.reshape(tf.constant([1., 1., 2.]), (3, 1, 1))
x = tf.reshape(tf.constant([1., 1., 0., 2., 1., 2.]), (1, 6, 1))
tf.nn.convolution(x, filters, strides=2, padding="VALID").numpy().squeeze()
# [2, 4]
tf.nn.convolution(x, filters, strides=2, padding="SAME").numpy().squeeze()
# [2, 4, 3]

说明:

padding = "valid"时,一定没有填补,并且将结尾多出的部分截断

padding = "same"时,填补方式为对称填补,且结尾优先填补,填补总数为

diation(k1)+1+(out1)strideindiation*(k-1)+1+(out-1)*stride-in

附:

floor(a1b)+1=ceil(ab)floor(\frac{a-1}{b})+1=ceil(\frac{a}{b})

转置卷积:

padding = "same"

padding = "valid"

带output_padding参数

new_rows = ((rows - 1) strides[0] + kernel_size[0] - 2 padding[0] + output_padding[0])

new_cols = ((cols - 1) strides[1] + kernel_size[1] - 2 padding[1] + output_padding[1])

tf1与tf2的迁移

https://blog.csdn.net/kyle1314608/article/details/100594884

tensorflow中dataloader的一个小问题记录

首先,tensorflow里面似乎没有pytorch里DataLoader=Dataset+Sampler的逻辑,tf关于数据处理的基类为:tf.data.Dataset。常见的使用方式如下:

这里的细节在于上述的dataset是一个可迭代对象而非一个迭代器,所以每次都会重新打乱样本顺序。

我要做的事情是每次随机丢弃前面若干份数据,再进行shuffle与batch,但希望使用上与上述完全一致,例如:

Last updated

Was this helpful?