Views
No views yet


1import os
2import numpy as np
3import pandas as pd
4from transformers import DeformableDetrForObjectDetection, DeformableDetrConfig, AutoImageProcessor
5import torch.nn as nn
6import torch
7from PIL import Image
8import shutil
9import requests
10from hf_utils import PairDetr, inverse_sigmoid, forward
11
12## Or download the weights manually
13def get_weights():
14 url = "https://huggingface.co/MTSAIR/PairDETR/blob/main/pytorch_model.bin"
15 response = requests.get(url, stream=True)
16 with open('full_weights.pth', 'wb') as out_file:
17 shutil.copyfileobj(response.raw, out_file)
18
19## loading the model
20configuration = DeformableDetrConfig("SenseTime/deformable-detr")
21processor = AutoImageProcessor.from_pretrained("MTSAIR/PairDETR")
22model = DeformableDetrForObjectDetection(configuration)
23model = PairDetr(model, 1500, 3)
24get_weights()
25checkpoint = torch.load("full_weights.pth", map_location="cpu")
26model.load_state_dict(checkpoint, strict=False)
27
28## run inference
29path = "./test.jpg"
30image = Image.open(path)
31inputs = processor(images=image, return_tensors="pt")
32outputs = forward(model, inputs["pixel_values"])
33| Model | Reasnable | Bare | Partial | Heavy | Hard | Average | Checkpoints |
|---|---|---|---|---|---|---|---|
| POS | 55.49 | 48.20 | 62.00 | 80.98 | 84.58 | 66.4 | weights |
| BFJ | 42.96 | 37.96 | 48.20 | 67.31 | 71.44 | 52.5 | weights |
| BPJ | - | - | - | - | - | 50.1 | weights |
| PBADET | - | - | - | - | - | 50.8 | none |
| OURs | 35.25 | 30.38 | 38.12 | 52.47 | 55.75 | 42.9 | weights |