File size: 834 Bytes
91860ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
## Code snippet to visualise the position of the box

```python
import matplotlib.image as img
import matplotlib.pyplot as plt
from datasets import load_dataset
from matplotlib.patches import Rectangle

# Load dataset
ds_name = "HuggingFaceM4/FGVC-Aircraft"
ds = load_dataset(ds_name, use_auth_token=True)

# Extract information for the sample we want to show
index = 300
sample = ds["train"][index]
box_coord = sample["bbox"]
xmin = box_coord["xmin"]
ymin = box_coord["ymin"]
xmax = box_coord["xmax"]
ymax = box_coord["ymax"]
img_path = sample["image"].filename

# Create plot
# define Matplotlib figure and axis
fig, ax = plt.subplots()

# plot figure
image = img.imread(img_path)
ax.imshow(image)

# add rectangle to plot
ax.add_patch(
    Rectangle((xmin, ymin), xmax-xmin, ymax - ymin, fill=None)
)

# display plot
plt.show()
```