MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / resize

Function resize

examples/OpticalFlow/flownet_models.py:115–139  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

113
114
115def 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
142class FlowNetBase(ModelDesc):

Callers 4

postprocessMethod · 0.85
graph_structureMethod · 0.85
flownet2_sdMethod · 0.85
upsample2xFunction · 0.85

Calls 1

shapeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…