Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Code snippet to visualise the position of the box
|
| 2 |
+
|
| 3 |
+
```python
|
| 4 |
+
import matplotlib.image as img
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
from datasets import load_dataset
|
| 7 |
+
from matplotlib.patches import Rectangle
|
| 8 |
+
|
| 9 |
+
# Load dataset
|
| 10 |
+
ds_name = "HuggingFaceM4/FGVC-Aircraft"
|
| 11 |
+
ds = load_dataset(ds_name, use_auth_token=True)
|
| 12 |
+
|
| 13 |
+
# Extract information for the sample we want to show
|
| 14 |
+
index = 300
|
| 15 |
+
sample = ds["train"][index]
|
| 16 |
+
box_coord = sample["bbox"]
|
| 17 |
+
xmin = box_coord["xmin"]
|
| 18 |
+
ymin = box_coord["ymin"]
|
| 19 |
+
xmax = box_coord["xmax"]
|
| 20 |
+
ymax = box_coord["ymax"]
|
| 21 |
+
img_path = sample["image"].filename
|
| 22 |
+
|
| 23 |
+
# Create plot
|
| 24 |
+
# define Matplotlib figure and axis
|
| 25 |
+
fig, ax = plt.subplots()
|
| 26 |
+
|
| 27 |
+
# plot figure
|
| 28 |
+
image = img.imread(img_path)
|
| 29 |
+
ax.imshow(image)
|
| 30 |
+
|
| 31 |
+
# add rectangle to plot
|
| 32 |
+
ax.add_patch(
|
| 33 |
+
Rectangle((xmin, ymin), xmax-xmin, ymax - ymin, fill=None)
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# display plot
|
| 37 |
+
plt.show()
|
| 38 |
+
```
|