edge-connect
edge-connect copied to clipboard
Fix generator input.size() not equal to output.size()
fix #4
def output_align(input, output):
"""
In testing, sometimes output is several pixels less than irregular-size input,
here is to fill them
"""
if output.size() != input.size():
diff_width = input.size(-1) - output.size(-1)
diff_height = input.size(-2) - output.size(-2)
m = nn.ReplicationPad2d((0, diff_width, 0, diff_height))
output = m(output)
return output
This function is from @youyuge34 Because images are resized to (256, 256) in training stage, this function has no side effect when running in training stage.
but the outputs in the forwarding process are not a single one, can it add into the forwarding process like this?
self.output_align(inputs,outputs)
but the outputs in the forwarding process are not a single one, can it add into the forwarding process like this?
self.output_align(inputs,outputs)
In test mode the batch size is set to 1 so, from my perspective, it's ok.
BTW my solution for the problem is to apply a resizing transformation on those images in load_item
in dataset.py
def load_item(self, index):
...
if size != 0:
img = self.resize(img, size, size)
else:
img = self.resize(img, img.shape[0] // 4 * 4, img.shape[1] // 4 * 4)
# also apply it on masks and edges