def overlap(tensor, stride=2): # Reshape the tensor to allow it to be passed in to conv2d. reshaped = tf.reshape(tensor, [1,1,-1,1]) # Construct the block_size filters. filter_dim = [1, -1, 1, 1] x_filt = tf.reshape(tf.constant([1., 0., 0.]), filter_dim) y_filt = tf.reshape(tf.constant([0., 1., 0.]), filter_dim) z_filt = tf.reshape(tf.constant([0., 0., 1.]), filter_dim) # Stride along the tensor with the above filters. stride_window = [1, 1, stride, 1] x = tf.nn.conv2d(reshaped, x_filt, stride_window, padding='VALID') y = tf.nn.conv2d(reshaped, y_filt, stride_window, padding='VALID') z = tf.nn.conv2d(reshaped, z_filt, stride_window, padding='VALID') # Pack the three tensors along 4th dimension. result = tf.stack([x, y, z], axis=4) # Squeeze to get rid of the extra dimensions. result = tf.squeeze(result) return result 这篇关于Tensorflow:将张量切片成重叠块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 10:07