edge-connect icon indicating copy to clipboard operation
edge-connect copied to clipboard

Fix generator input.size() not equal to output.size()

Open wasd96040501 opened this issue 5 years ago • 2 comments

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.

wasd96040501 avatar Mar 08 '19 11:03 wasd96040501

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)

GuardSkill avatar May 19 '19 08:05 GuardSkill

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

Mistariano avatar Aug 31 '19 15:08 Mistariano