# Using detr with custom backbone

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fusing-detr-with-custom-backbone%2F73724%3E%5C
**Category:** Models\
**Created:** [February 18, 2024, 6:03pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fusing-detr-with-custom-backbone%2F73724 "2024-02-18T18:03:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![paoloach](https://avatars.discourse-cdn.com/v4/letter/p/f0a364/32.png) [@paoloach](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpaoloach)%5C
**Post date:** [February 18, 2024, 6:03pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fusing-detr-with-custom-backbone%2F73724%2F1 "2024-02-18T18:03:30Z")

</div>

I would like to use detr model with a fine tunned resnet-50 backbone, but I can see how to configure it.

Somebody know how to do it ?

Thanks,  
Paolo

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [February 21, 2024, 8:07am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fusing-detr-with-custom-backbone%2F73724%2F2 "2024-02-21T08:07:05Z")

</div>

Hi,

Yes this is now supported using the [AutoBackbone](https://huggingface.co/docs/transformers/v4.37.2/en/main_classes/backbones#transformers.AutoBackbone) class.

Here’s how to do that:

```python
from transformers import DetrConfig, DetrForObjectDetection

config = DetrConfig(backbone="microsoft/resnet50", use_pretrained_backbone=True)

model = DetrForObjectDetection(config)

```

Also, here’s how to randomly initialize a DETR model with a custom ResNet model:

```python
from transformers import DetrConfig, ResNetConfig, DetrForObjectDetection

backbone_config = ResNetConfig.from_pretrained("microsoft/resnet-50", out_indices=[0,1,2,3])

config = DetrConfig(backbone_config=backbone_config)

model = DetrForObjectDetection(config)

```

---

<div class="post-metadata">

**Author:** ![paoloach](https://avatars.discourse-cdn.com/v4/letter/p/f0a364/32.png) [@paoloach](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpaoloach)%5C
**Post date:** [February 21, 2024, 8:23am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fusing-detr-with-custom-backbone%2F73724%2F3 "2024-02-21T08:23:12Z")

</div>

Hi Niels,  
thank you for your answer.

Paolo

---

<div class="post-metadata">

**Author:** ![halyusuf](https://avatars.discourse-cdn.com/v4/letter/h/958977/32.png) [@halyusuf](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fhalyusuf)%5C
**Post date:** [December 6, 2024, 12:13pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fusing-detr-with-custom-backbone%2F73724%2F4 "2024-12-06T12:13:21Z")

</div>

this will load the pretrained backbone “microsoft/resnet-50” with randomly initialized encoder, decoder, and head of the transformer, am i right?  
but what i’m trying to do, but i’m unable to do it is, i need to use a pretrained transformer, for exmaple: “microsoft/conditional-detr-resnet-50”, but i want to change the backbone to a fine tunned resnet backbone that i have the .pth or ckpt file for it
