MCPcopy Create free account
hub / github.com/drinkingcoder/FlowFormer-Official / __call__

Method __call__

core/utils/flow_transforms.py:126–233  ·  view source on GitHub ↗
(self, inputs, target)

Source from the content-addressed store, hash-verified

124
125
126 def __call__(self, inputs, target):
127 h, w, _ = inputs[0].shape
128 th, tw = self.crop
129 meshgrid = torch.meshgrid([torch.Tensor(range(th)), torch.Tensor(range(tw))])[::-1]
130 cornergrid = torch.meshgrid([torch.Tensor([0,th-1]), torch.Tensor([0,tw-1])])[::-1]
131
132 for i in range(50):
133 # im0
134 self.to_identity()
135 #TODO add mirror
136 if np.random.binomial(1,0.5):
137 mirror = True
138 else:
139 mirror = False
140 ##TODO
141 #mirror = False
142 if mirror:
143 self.left_multiply(-1, 0, 0, 1, .5 * tw, -.5 * th);
144 else:
145 self.left_multiply(1, 0, 0, 1, -.5 * tw, -.5 * th);
146 scale0 = 1; scale1 = 1; squeeze0 = 1; squeeze1 = 1;
147 if not self.rot is None:
148 rot0 = np.random.uniform(-self.rot[0],+self.rot[0])
149 rot1 = np.random.uniform(-self.rot[1]*self.schedule_coeff, self.rot[1]*self.schedule_coeff) + rot0
150 self.left_multiply(np.cos(rot0), np.sin(rot0), -np.sin(rot0), np.cos(rot0), 0, 0)
151 if not self.trans is None:
152 trans0 = np.random.uniform(-self.trans[0],+self.trans[0], 2)
153 trans1 = np.random.uniform(-self.trans[1]*self.schedule_coeff,+self.trans[1]*self.schedule_coeff, 2) + trans0
154 self.left_multiply(1, 0, 0, 1, trans0[0] * tw, trans0[1] * th)
155 if not self.squeeze is None:
156 squeeze0 = np.exp(np.random.uniform(-self.squeeze[0], self.squeeze[0]))
157 squeeze1 = np.exp(np.random.uniform(-self.squeeze[1]*self.schedule_coeff, self.squeeze[1]*self.schedule_coeff)) * squeeze0
158 if not self.scale is None:
159 scale0 = np.exp(np.random.uniform(self.scale[2]-self.scale[0], self.scale[2]+self.scale[0]))
160 scale1 = np.exp(np.random.uniform(-self.scale[1]*self.schedule_coeff, self.scale[1]*self.schedule_coeff)) * scale0
161 self.left_multiply(1.0/(scale0*squeeze0), 0, 0, 1.0/(scale0/squeeze0), 0, 0)
162
163 self.left_multiply(1, 0, 0, 1, .5 * w, .5 * h);
164 transmat0 = self.t.copy()
165
166 # im1
167 self.to_identity()
168 if mirror:
169 self.left_multiply(-1, 0, 0, 1, .5 * tw, -.5 * th);
170 else:
171 self.left_multiply(1, 0, 0, 1, -.5 * tw, -.5 * th);
172 if not self.rot is None:
173 self.left_multiply(np.cos(rot1), np.sin(rot1), -np.sin(rot1), np.cos(rot1), 0, 0)
174 if not self.trans is None:
175 self.left_multiply(1, 0, 0, 1, trans1[0] * tw, trans1[1] * th)
176 self.left_multiply(1.0/(scale1*squeeze1), 0, 0, 1.0/(scale1/squeeze1), 0, 0)
177 self.left_multiply(1, 0, 0, 1, .5 * w, .5 * h);
178 transmat1 = self.t.copy()
179 transmat1_inv = self.inverse()
180
181 if self.black:
182 # black augmentation, allowing 0 values in the input images
183 # https://github.com/lmb-freiburg/flownet2/blob/master/src/caffe/layers/black_augmentation_layer.cu

Callers

nothing calls this directly

Calls 4

to_identityMethod · 0.95
left_multiplyMethod · 0.95
inverseMethod · 0.95
grid_transformMethod · 0.95

Tested by

no test coverage detected