chore: import upstream snapshot with attribution
CPU tests Workflow / Testing (ubuntu-latest, 3.12) (push) Failing after 1s
CPU tests Workflow / Testing (ubuntu-latest, 3.13) (push) Failing after 0s
Mypy Type Check / Type Check (push) Failing after 0s
Docs/Test WorkFlow / Test docs build (push) Failing after 1s
PR Conflict Labeler / labeling (push) Failing after 1s
Dependency resolution / Resolve [tflite] extra — Python 3.12 (push) Failing after 0s
Smoke Tests / try-all-models (ubuntu-latest, 3.10) (push) Failing after 0s
Smoke Tests / try-all-models (ubuntu-latest, 3.13) (push) Failing after 1s
CPU tests Workflow / build-pkg (push) Failing after 1s
CPU tests Workflow / Testing (ubuntu-latest, 3.10) (push) Failing after 0s
CPU tests Workflow / Testing (ubuntu-latest, 3.11) (push) Failing after 0s
Smoke Tests / try-all-models (macos-latest, 3.10) (push) Has been cancelled
Smoke Tests / try-all-models (macos-latest, 3.13) (push) Has been cancelled
Smoke Tests / try-all-models (windows-latest, 3.10) (push) Has been cancelled
Smoke Tests / try-all-models (windows-latest, 3.13) (push) Has been cancelled
CPU tests Workflow / Testing (macos-latest, 3.10) (push) Has been cancelled
CPU tests Workflow / Testing (macos-latest, 3.13) (push) Has been cancelled
CPU tests Workflow / Testing (windows-latest, 3.10) (push) Has been cancelled
CPU tests Workflow / Testing (windows-latest, 3.13) (push) Has been cancelled
CPU tests Workflow / testing-guardian (push) Has been cancelled
GPU tests Workflow / Testing (push) Has been cancelled
CPU tests Workflow / Testing (ubuntu-latest, 3.12) (push) Failing after 1s
CPU tests Workflow / Testing (ubuntu-latest, 3.13) (push) Failing after 0s
Mypy Type Check / Type Check (push) Failing after 0s
Docs/Test WorkFlow / Test docs build (push) Failing after 1s
PR Conflict Labeler / labeling (push) Failing after 1s
Dependency resolution / Resolve [tflite] extra — Python 3.12 (push) Failing after 0s
Smoke Tests / try-all-models (ubuntu-latest, 3.10) (push) Failing after 0s
Smoke Tests / try-all-models (ubuntu-latest, 3.13) (push) Failing after 1s
CPU tests Workflow / build-pkg (push) Failing after 1s
CPU tests Workflow / Testing (ubuntu-latest, 3.10) (push) Failing after 0s
CPU tests Workflow / Testing (ubuntu-latest, 3.11) (push) Failing after 0s
Smoke Tests / try-all-models (macos-latest, 3.10) (push) Has been cancelled
Smoke Tests / try-all-models (macos-latest, 3.13) (push) Has been cancelled
Smoke Tests / try-all-models (windows-latest, 3.10) (push) Has been cancelled
Smoke Tests / try-all-models (windows-latest, 3.13) (push) Has been cancelled
CPU tests Workflow / Testing (macos-latest, 3.10) (push) Has been cancelled
CPU tests Workflow / Testing (macos-latest, 3.13) (push) Has been cancelled
CPU tests Workflow / Testing (windows-latest, 3.10) (push) Has been cancelled
CPU tests Workflow / Testing (windows-latest, 3.13) (push) Has been cancelled
CPU tests Workflow / testing-guardian (push) Has been cancelled
GPU tests Workflow / Testing (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
# ------------------------------------------------------------------------
|
||||
# RF-DETR
|
||||
# Copyright (c) 2025 Roboflow. All Rights Reserved.
|
||||
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
|
||||
# ------------------------------------------------------------------------
|
||||
"""Unit tests for rfdetr.inference weight-adaptation helpers."""
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from rfdetr.inference import _adapt_input_conv
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_random_seeds():
|
||||
"""Ensure reproducible random state for every test in this module."""
|
||||
torch.manual_seed(0)
|
||||
|
||||
|
||||
class TestAdaptInputConv:
|
||||
@pytest.mark.parametrize(
|
||||
("num_channels", "expected_shape", "expected_builder"),
|
||||
[
|
||||
pytest.param(3, (8, 3, 3, 3), lambda weight: weight, id="identity_3ch"),
|
||||
pytest.param(1, (8, 1, 3, 3), lambda weight: weight.mean(dim=1, keepdim=True), id="mean_1ch"),
|
||||
pytest.param(
|
||||
4,
|
||||
(8, 4, 3, 3),
|
||||
lambda weight: torch.cat([weight, weight], dim=1)[:, :4] * (3.0 / 4.0),
|
||||
id="tile_4ch",
|
||||
),
|
||||
pytest.param(
|
||||
6,
|
||||
(8, 6, 3, 3),
|
||||
lambda weight: torch.cat([weight, weight], dim=1)[:, :6] * (3.0 / 6.0),
|
||||
id="tile_6ch",
|
||||
),
|
||||
pytest.param(
|
||||
2,
|
||||
(8, 2, 3, 3),
|
||||
lambda weight: weight[:, :2] * (3.0 / 2.0),
|
||||
id="tile_2ch",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_adapt_input_conv(self, num_channels, expected_shape, expected_builder):
|
||||
"""Verify shape and values for each _adapt_input_conv branch."""
|
||||
conv_weight = torch.randn(8, 3, 3, 3)
|
||||
|
||||
adapted_weight = _adapt_input_conv(num_channels, conv_weight)
|
||||
expected_weight = expected_builder(conv_weight)
|
||||
|
||||
assert adapted_weight.shape == expected_shape
|
||||
torch.testing.assert_close(adapted_weight, expected_weight)
|
||||
Reference in New Issue
Block a user