Sembiance mamta commited on
Commit
c401cda
0 Parent(s):

Duplicate from facebook/detr-resnet-101

Browse files

Co-authored-by: Mamta Narang <mamta@users.noreply.huggingface.co>

Files changed (5) hide show
  1. .gitattributes +16 -0
  2. README.md +122 -0
  3. config.json +216 -0
  4. preprocessor_config.json +18 -0
  5. pytorch_model.bin +3 -0
.gitattributes ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
2
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.h5 filter=lfs diff=lfs merge=lfs -text
5
+ *.tflite filter=lfs diff=lfs merge=lfs -text
6
+ *.tar.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.ot filter=lfs diff=lfs merge=lfs -text
8
+ *.onnx filter=lfs diff=lfs merge=lfs -text
9
+ *.arrow filter=lfs diff=lfs merge=lfs -text
10
+ *.ftz filter=lfs diff=lfs merge=lfs -text
11
+ *.joblib filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.pb filter=lfs diff=lfs merge=lfs -text
15
+ *.pt filter=lfs diff=lfs merge=lfs -text
16
+ *.pth filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - object-detection
5
+ - vision
6
+ datasets:
7
+ - coco
8
+ widget:
9
+ - src: >-
10
+ https://huggingface.co/datasets/mishig/sample_images/resolve/main/savanna.jpg
11
+ example_title: Savanna
12
+ - src: >-
13
+ https://huggingface.co/datasets/mishig/sample_images/resolve/main/football-match.jpg
14
+ example_title: Football Match
15
+ - src: >-
16
+ https://huggingface.co/datasets/mishig/sample_images/resolve/main/airport.jpg
17
+ example_title: Airport
18
+ duplicated_from: facebook/detr-resnet-101
19
+ ---
20
+
21
+ # DETR (End-to-End Object Detection) model with ResNet-101 backbone
22
+
23
+ DEtection TRansformer (DETR) model trained end-to-end on COCO 2017 object detection (118k annotated images). It was introduced in the paper [End-to-End Object Detection with Transformers](https://arxiv.org/abs/2005.12872) by Carion et al. and first released in [this repository](https://github.com/facebookresearch/detr).
24
+
25
+ Disclaimer: The team releasing DETR did not write a model card for this model so this model card has been written by the Hugging Face team.
26
+
27
+ ## Model description
28
+
29
+ The DETR model is an encoder-decoder transformer with a convolutional backbone. Two heads are added on top of the decoder outputs in order to perform object detection: a linear layer for the class labels and a MLP (multi-layer perceptron) for the bounding boxes. The model uses so-called object queries to detect objects in an image. Each object query looks for a particular object in the image. For COCO, the number of object queries is set to 100.
30
+
31
+ The model is trained using a "bipartite matching loss": one compares the predicted classes + bounding boxes of each of the N = 100 object queries to the ground truth annotations, padded up to the same length N (so if an image only contains 4 objects, 96 annotations will just have a "no object" as class and "no bounding box" as bounding box). The Hungarian matching algorithm is used to create an optimal one-to-one mapping between each of the N queries and each of the N annotations. Next, standard cross-entropy (for the classes) and a linear combination of the L1 and generalized IoU loss (for the bounding boxes) are used to optimize the parameters of the model.
32
+
33
+ ![model image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/detr_architecture.png)
34
+
35
+ ## Intended uses & limitations
36
+
37
+ You can use the raw model for object detection. See the [model hub](https://huggingface.co/models?search=facebook/detr) to look for all available DETR models.
38
+
39
+ ### How to use
40
+
41
+ Here is how to use this model:
42
+
43
+ ```python
44
+ from transformers import DetrFeatureExtractor, DetrForObjectDetection
45
+ import torch
46
+ from PIL import Image
47
+ import requests
48
+
49
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
50
+ image = Image.open(requests.get(url, stream=True).raw)
51
+
52
+ feature_extractor = DetrFeatureExtractor.from_pretrained("facebook/detr-resnet-101")
53
+ model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-101")
54
+
55
+ inputs = feature_extractor(images=image, return_tensors="pt")
56
+ outputs = model(**inputs)
57
+
58
+ # convert outputs (bounding boxes and class logits) to COCO API
59
+ target_sizes = torch.tensor([image.size[::-1]])
60
+ results = feature_extractor.post_process(outputs, target_sizes=target_sizes)[0]
61
+
62
+ for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
63
+ box = [round(i, 2) for i in box.tolist()]
64
+ # let's only keep detections with score > 0.9
65
+ if score > 0.9:
66
+ print(
67
+ f"Detected {model.config.id2label[label.item()]} with confidence "
68
+ f"{round(score.item(), 3)} at location {box}"
69
+ )
70
+ ```
71
+ This should output (something along the lines of):
72
+ ```
73
+ Detected cat with confidence 0.998 at location [344.06, 24.85, 640.34, 373.74]
74
+ Detected remote with confidence 0.997 at location [328.13, 75.93, 372.81, 187.66]
75
+ Detected remote with confidence 0.997 at location [39.34, 70.13, 175.56, 118.78]
76
+ Detected cat with confidence 0.998 at location [15.36, 51.75, 316.89, 471.16]
77
+ Detected couch with confidence 0.995 at location [-0.19, 0.71, 639.73, 474.17]
78
+ ```
79
+
80
+ Currently, both the feature extractor and model support PyTorch.
81
+
82
+ ## Training data
83
+
84
+ The DETR model was trained on [COCO 2017 object detection](https://cocodataset.org/#download), a dataset consisting of 118k/5k annotated images for training/validation respectively.
85
+
86
+ ## Training procedure
87
+
88
+ ### Preprocessing
89
+
90
+ The exact details of preprocessing of images during training/validation can be found [here](https://github.com/google-research/vision_transformer/blob/master/vit_jax/input_pipeline.py).
91
+
92
+ Images are resized/rescaled such that the shortest side is at least 800 pixels and the largest side at most 1333 pixels, and normalized across the RGB channels with the ImageNet mean (0.485, 0.456, 0.406) and standard deviation (0.229, 0.224, 0.225).
93
+
94
+ ### Training
95
+
96
+ The model was trained for 300 epochs on 16 V100 GPUs. This takes 3 days, with 4 images per GPU (hence a total batch size of 64).
97
+
98
+ ## Evaluation results
99
+
100
+ This model achieves an AP (average precision) of **43.5** on COCO 2017 validation. For more details regarding evaluation results, we refer to table 1 of the original paper.
101
+ ### BibTeX entry and citation info
102
+
103
+ ```bibtex
104
+ @article{DBLP:journals/corr/abs-2005-12872,
105
+ author = {Nicolas Carion and
106
+ Francisco Massa and
107
+ Gabriel Synnaeve and
108
+ Nicolas Usunier and
109
+ Alexander Kirillov and
110
+ Sergey Zagoruyko},
111
+ title = {End-to-End Object Detection with Transformers},
112
+ journal = {CoRR},
113
+ volume = {abs/2005.12872},
114
+ year = {2020},
115
+ url = {https://arxiv.org/abs/2005.12872},
116
+ archivePrefix = {arXiv},
117
+ eprint = {2005.12872},
118
+ timestamp = {Thu, 28 May 2020 17:38:09 +0200},
119
+ biburl = {https://dblp.org/rec/journals/corr/abs-2005-12872.bib},
120
+ bibsource = {dblp computer science bibliography, https://dblp.org}
121
+ }
122
+ ```
config.json ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "activation_dropout": 0.0,
3
+ "activation_function": "relu",
4
+ "architectures": [
5
+ "DetrForObjectDetection"
6
+ ],
7
+ "attention_dropout": 0.0,
8
+ "auxiliary_loss": false,
9
+ "backbone": "resnet101",
10
+ "bbox_cost": 5,
11
+ "bbox_loss_coefficient": 5,
12
+ "class_cost": 1,
13
+ "classifier_dropout": 0.0,
14
+ "d_model": 256,
15
+ "decoder_attention_heads": 8,
16
+ "decoder_ffn_dim": 2048,
17
+ "decoder_layerdrop": 0.0,
18
+ "decoder_layers": 6,
19
+ "dice_loss_coefficient": 1,
20
+ "dilation": false,
21
+ "dropout": 0.1,
22
+ "encoder_attention_heads": 8,
23
+ "encoder_ffn_dim": 2048,
24
+ "encoder_layerdrop": 0.0,
25
+ "encoder_layers": 6,
26
+ "eos_coefficient": 0.1,
27
+ "giou_cost": 2,
28
+ "giou_loss_coefficient": 2,
29
+ "id2label": {
30
+ "0": "N/A",
31
+ "1": "person",
32
+ "2": "bicycle",
33
+ "3": "car",
34
+ "4": "motorcycle",
35
+ "5": "airplane",
36
+ "6": "bus",
37
+ "7": "train",
38
+ "8": "truck",
39
+ "9": "boat",
40
+ "10": "traffic light",
41
+ "11": "fire hydrant",
42
+ "12": "N/A",
43
+ "13": "stop sign",
44
+ "14": "parking meter",
45
+ "15": "bench",
46
+ "16": "bird",
47
+ "17": "cat",
48
+ "18": "dog",
49
+ "19": "horse",
50
+ "20": "sheep",
51
+ "21": "cow",
52
+ "22": "elephant",
53
+ "23": "bear",
54
+ "24": "zebra",
55
+ "25": "giraffe",
56
+ "26": "N/A",
57
+ "27": "backpack",
58
+ "28": "umbrella",
59
+ "29": "N/A",
60
+ "30": "N/A",
61
+ "31": "handbag",
62
+ "32": "tie",
63
+ "33": "suitcase",
64
+ "34": "frisbee",
65
+ "35": "skis",
66
+ "36": "snowboard",
67
+ "37": "sports ball",
68
+ "38": "kite",
69
+ "39": "baseball bat",
70
+ "40": "baseball glove",
71
+ "41": "skateboard",
72
+ "42": "surfboard",
73
+ "43": "tennis racket",
74
+ "44": "bottle",
75
+ "45": "N/A",
76
+ "46": "wine glass",
77
+ "47": "cup",
78
+ "48": "fork",
79
+ "49": "knife",
80
+ "50": "spoon",
81
+ "51": "bowl",
82
+ "52": "banana",
83
+ "53": "apple",
84
+ "54": "sandwich",
85
+ "55": "orange",
86
+ "56": "broccoli",
87
+ "57": "carrot",
88
+ "58": "hot dog",
89
+ "59": "pizza",
90
+ "60": "donut",
91
+ "61": "cake",
92
+ "62": "chair",
93
+ "63": "couch",
94
+ "64": "potted plant",
95
+ "65": "bed",
96
+ "66": "N/A",
97
+ "67": "dining table",
98
+ "68": "N/A",
99
+ "69": "N/A",
100
+ "70": "toilet",
101
+ "71": "N/A",
102
+ "72": "tv",
103
+ "73": "laptop",
104
+ "74": "mouse",
105
+ "75": "remote",
106
+ "76": "keyboard",
107
+ "77": "cell phone",
108
+ "78": "microwave",
109
+ "79": "oven",
110
+ "80": "toaster",
111
+ "81": "sink",
112
+ "82": "refrigerator",
113
+ "83": "N/A",
114
+ "84": "book",
115
+ "85": "clock",
116
+ "86": "vase",
117
+ "87": "scissors",
118
+ "88": "teddy bear",
119
+ "89": "hair drier",
120
+ "90": "toothbrush"
121
+ },
122
+ "init_std": 0.02,
123
+ "init_xavier_std": 1.0,
124
+ "is_encoder_decoder": true,
125
+ "label2id": {
126
+ "N/A": 83,
127
+ "airplane": 5,
128
+ "apple": 53,
129
+ "backpack": 27,
130
+ "banana": 52,
131
+ "baseball bat": 39,
132
+ "baseball glove": 40,
133
+ "bear": 23,
134
+ "bed": 65,
135
+ "bench": 15,
136
+ "bicycle": 2,
137
+ "bird": 16,
138
+ "boat": 9,
139
+ "book": 84,
140
+ "bottle": 44,
141
+ "bowl": 51,
142
+ "broccoli": 56,
143
+ "bus": 6,
144
+ "cake": 61,
145
+ "car": 3,
146
+ "carrot": 57,
147
+ "cat": 17,
148
+ "cell phone": 77,
149
+ "chair": 62,
150
+ "clock": 85,
151
+ "couch": 63,
152
+ "cow": 21,
153
+ "cup": 47,
154
+ "dining table": 67,
155
+ "dog": 18,
156
+ "donut": 60,
157
+ "elephant": 22,
158
+ "fire hydrant": 11,
159
+ "fork": 48,
160
+ "frisbee": 34,
161
+ "giraffe": 25,
162
+ "hair drier": 89,
163
+ "handbag": 31,
164
+ "horse": 19,
165
+ "hot dog": 58,
166
+ "keyboard": 76,
167
+ "kite": 38,
168
+ "knife": 49,
169
+ "laptop": 73,
170
+ "microwave": 78,
171
+ "motorcycle": 4,
172
+ "mouse": 74,
173
+ "orange": 55,
174
+ "oven": 79,
175
+ "parking meter": 14,
176
+ "person": 1,
177
+ "pizza": 59,
178
+ "potted plant": 64,
179
+ "refrigerator": 82,
180
+ "remote": 75,
181
+ "sandwich": 54,
182
+ "scissors": 87,
183
+ "sheep": 20,
184
+ "sink": 81,
185
+ "skateboard": 41,
186
+ "skis": 35,
187
+ "snowboard": 36,
188
+ "spoon": 50,
189
+ "sports ball": 37,
190
+ "stop sign": 13,
191
+ "suitcase": 33,
192
+ "surfboard": 42,
193
+ "teddy bear": 88,
194
+ "tennis racket": 43,
195
+ "tie": 32,
196
+ "toaster": 80,
197
+ "toilet": 70,
198
+ "toothbrush": 90,
199
+ "traffic light": 10,
200
+ "train": 7,
201
+ "truck": 8,
202
+ "tv": 72,
203
+ "umbrella": 28,
204
+ "vase": 86,
205
+ "wine glass": 46,
206
+ "zebra": 24
207
+ },
208
+ "mask_loss_coefficient": 1,
209
+ "max_position_embeddings": 1024,
210
+ "model_type": "detr",
211
+ "num_hidden_layers": 6,
212
+ "num_queries": 100,
213
+ "position_embedding_type": "sine",
214
+ "scale_embedding": false,
215
+ "transformers_version": "4.7.0.dev0"
216
+ }
preprocessor_config.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_normalize": true,
3
+ "do_resize": true,
4
+ "feature_extractor_type": "DetrFeatureExtractor",
5
+ "format": "coco_detection",
6
+ "image_mean": [
7
+ 0.485,
8
+ 0.456,
9
+ 0.406
10
+ ],
11
+ "image_std": [
12
+ 0.229,
13
+ 0.224,
14
+ 0.225
15
+ ],
16
+ "max_size": 1333,
17
+ "size": 800
18
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0943b5a9085a95a0e3ecc1c99a7db0451ecb9d79f4dcb543b0939c1a12481a5d
3
+ size 243011543