Enable HF pretrained backbones (#31145)
* Enable load HF or tim backbone checkpoints * Fix up * Fix test - pass in proper out_indices * Update docs * Fix tvp tests * Fix doc examples * Fix doc examples * Try to resolve DPT backbone param init * Don't conditionally set to None * Add condition based on whether backbone is defined * Address review comments
This commit is contained in:
@@ -276,6 +276,34 @@ class DPTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
|
||||
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
|
||||
)
|
||||
|
||||
def test_backbone_selection(self):
|
||||
def _validate_backbone_init():
|
||||
for model_class in self.all_model_classes:
|
||||
model = model_class(config)
|
||||
model.to(torch_device)
|
||||
model.eval()
|
||||
|
||||
if model.__class__.__name__ == "DPTForDepthEstimation":
|
||||
# Confirm out_indices propogated to backbone
|
||||
self.assertEqual(len(model.backbone.out_indices), 2)
|
||||
|
||||
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
|
||||
config.use_pretrained_backbone = True
|
||||
config.backbone_config = None
|
||||
config.backbone_kwargs = {"out_indices": [-2, -1]}
|
||||
# Force load_backbone path
|
||||
config.is_hybrid = False
|
||||
|
||||
# Load a timm backbone
|
||||
config.backbone = "resnet18"
|
||||
config.use_timm_backbone = True
|
||||
_validate_backbone_init()
|
||||
|
||||
# Load a HF backbone
|
||||
config.backbone = "facebook/dinov2-small"
|
||||
config.use_timm_backbone = False
|
||||
_validate_backbone_init()
|
||||
|
||||
@slow
|
||||
def test_model_from_pretrained(self):
|
||||
model_name = "Intel/dpt-large"
|
||||
|
||||
Reference in New Issue
Block a user