File size: 2,654 Bytes
1aa0a2d
 
 
 
 
 
 
 
93a8c6d
1aa0a2d
 
 
 
 
93a8c6d
 
 
 
 
 
 
 
 
ba1b35b
1aa0a2d
93a8c6d
 
1aa0a2d
 
 
93a8c6d
1aa0a2d
 
 
 
 
 
ba1b35b
 
 
 
1aa0a2d
 
 
 
 
 
5c441a5
31fe55e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
dataset_info:
  features:
  - name: image
    dtype: image
  - name: image_id
    dtype: int64
  - name: annotations
    sequence:
    - name: file_name
      dtype: string
    - name: image_id
      dtype: int64
    - name: category_id
      dtype:
        class_label:
          names:
            '0': bin
            '1': hand
            '2': not_bin
            '3': not_hand
            '4': not_trash
            '5': trash
            '6': trash_arm
    - name: bbox
      sequence: float32
      length: 4
    - name: iscrowd
      dtype: int64
    - name: area
      dtype: float32
  - name: label_source
    dtype: string
  - name: image_source
    dtype: string
  splits:
  - name: train
    num_bytes: 1022952485.728
    num_examples: 1128
  download_size: 1026537298
  dataset_size: 1022952485.728
configs:
- config_name: default
  data_files:
  - split: train
    path: data/train-*
---

## Load data

```python
import datasets

dataset = datasets.load_dataset("mrdbourke/trashify_manual_labelled_images")
dataset
```

## View a sample

```python
dataset["train"][0]
```

Output:

```
{'image': <PIL.Image.Image image mode=RGB size=960x1280>,
 'image_id': 292,
 'annotations': {'file_name': ['00347467-13f1-4cb9-94aa-4e4369457e0c.jpeg',
   '00347467-13f1-4cb9-94aa-4e4369457e0c.jpeg'],
  'image_id': [292, 292],
  'category_id': [1, 0],
  'bbox': [[523.7000122070312,
    545.0999755859375,
    402.79998779296875,
    336.1000061035156],
   [10.399999618530273,
    163.6999969482422,
    943.4000244140625,
    1101.9000244140625]],
  'iscrowd': [0, 0],
  'area': [135381.078125, 1039532.4375]},
 'label_source': 'manual_prodigy_label',
 'image_source': 'manual_taken_photo'}
```

**Note:** Boxes in "bbox" key are in `XYWH` format or `[x_min, y_min, box_width, box_height]`. If you'd like them in `XYXY` format, you'll have to convert them.

## Get categories

```python
# Get the categories from the dataset
# Note: this requires the dataset to have been uploaded with this feature setup
categories = dataset["train"].features["annotations"].feature["category_id"]

# Get the names attribute
categories.names

>>> ['bin', 'hand', 'not_bin', 'not_hand', 'not_trash', 'trash', 'trash_arm']
```

## Create label2id and id2label

```python
id2label = {i: class_name for i, class_name in enumerate(categories.names)}
label2id = {value: key for key, value in id2label.items()}

id2label, label2id
```

Output:

```
({0: 'bin',
  1: 'hand',
  2: 'not_bin',
  3: 'not_hand',
  4: 'not_trash',
  5: 'trash',
  6: 'trash_arm'},
 {'bin': 0,
  'hand': 1,
  'not_bin': 2,
  'not_hand': 3,
  'not_trash': 4,
  'trash': 5,
  'trash_arm': 6})
```