Skip to content

Fix pytorch upsample parsing #1186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hls4ml/converters/pytorch/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def handle_upsample(operation, layer_name, input_names, input_shapes, node, clas
layer['out_height'] = int(layer['in_height'] * scale_height)
layer['out_width'] = int(layer['in_width'] * scale_width)

output_shape = [layer['n_chan'], layer['out_height'], layer['out_width']]
output_shape = [input_shapes[0][0], layer['n_chan'], layer['out_height'], layer['out_width']]
else:
raise Exception(f'Parsing "Upsample" with {len(input_shape)}-dimensional tensors is not yet supported.')

Expand Down
6 changes: 4 additions & 2 deletions test/pytest/test_upsampling_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ class Upsample1DModel(nn.Module):
def __init__(self):
super().__init__()
self.upsample = nn.Upsample(scale_factor=2)
self.relu = nn.ReLU()

def forward(self, x):
return self.upsample(x)
return self.relu(self.upsample(x))


class Upsample2DModel(nn.Module):
def __init__(self):
super().__init__()
# this scale_factor tests proper output shape calculation with fractional scaling and parsing per-axis scales
self.upsample = nn.UpsamplingNearest2d(scale_factor=(1, 2.4)) # Would also work with Upsample(mode='nearest')
self.relu = nn.ReLU()

def forward(self, x):
return self.upsample(x)
return self.relu(self.upsample(x))


@pytest.mark.parametrize('io_type', ['io_stream', 'io_parallel'])
Expand Down
Loading