Remove redundant condition checks in get_image_size method#45461
Remove redundant condition checks in get_image_size method#45461Rocketknight1 merged 2 commits intohuggingface:mainfrom
get_image_size method#45461Conversation
| @@ -358,14 +358,6 @@ def get_image_size( | |||
| resize_height = max(int(round(resize_height / 32) * 32), 32) | |||
There was a problem hiding this comment.
The removed early-return optimization (if resize_height == height and resize_width == width) avoided tensor allocation when no resize was needed. Its removal means every call now allocates a torch.tensor even when input dimensions are already valid — this could add measurable overhead in high-throughput inference pipelines. Consider restoring the check or benchmarking the impact.
if resize_height == height and resize_width == width:
return SizeDict(height=resize_height, width=resize_width), torch.tensor(
[height, width], dtype=torch.float32, device=image.device
)
# The last return is the same as the one above.
return SizeDict(height=resize_height, width=resize_width), torch.tensor(
[height, width], dtype=torch.float32, device=image.device
) |
|
Are you sure these are redundant..? In particular, the |
resize_height = max(int(round(resize_height / 32) * 32), 32)
resize_width = max(int(round(resize_width / 32) * 32), 32)
# resize_height >=32 and resize_width >=32
if resize_height == height and resize_width == width:
return SizeDict(height=resize_height, width=resize_width), torch.tensor(
[height, width], dtype=torch.float32, device=image.device
)
...... |
|
@JiauZhang sorry, you're correct! These conditions are totally redundant. One last thing before I approve - can you use |
|
@Rocketknight1 |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: pp_ocrv5_server_det |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
What does this PR do?
Remove redundant condition checks in
get_image_sizemethod