Resize input tensor with unkown input-shape by a factor Args: x (tf.Tensor): tensor NCHW factor (int, optional): resize factor for H, W Note: Differences here against Caffe have huge impacts on the quality of the predictions. Returns: tf.Tensor:
(x, mode, factor=4)
| 113 | |
| 114 | |
| 115 | def resize(x, mode, factor=4): |
| 116 | """Resize input tensor with unkown input-shape by a factor |
| 117 | |
| 118 | Args: |
| 119 | x (tf.Tensor): tensor NCHW |
| 120 | factor (int, optional): resize factor for H, W |
| 121 | |
| 122 | Note: |
| 123 | Differences here against Caffe have huge impacts on the |
| 124 | quality of the predictions. |
| 125 | |
| 126 | Returns: |
| 127 | tf.Tensor: resized tensor NCHW |
| 128 | """ |
| 129 | assert mode in ['bilinear', 'nearest'], mode |
| 130 | shp = tf.shape(x)[2:] * factor |
| 131 | # NCHW -> NHWC |
| 132 | x = tf.transpose(x, [0, 2, 3, 1]) |
| 133 | if mode == 'bilinear': |
| 134 | x = tf.image.resize_bilinear(x, shp, align_corners=True) |
| 135 | else: |
| 136 | # better approximation of what Caffe is doing |
| 137 | x = tf.image.resize_nearest_neighbor(x, shp, align_corners=False) |
| 138 | # NHWC -> NCHW |
| 139 | return tf.transpose(x, [0, 3, 1, 2]) |
| 140 | |
| 141 | |
| 142 | class FlowNetBase(ModelDesc): |
no test coverage detected
searching dependent graphs…