add snippet to readme
Browse files- README.md +40 -0
- data_readme/sample_100_box_pos.png +0 -0
README.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
| 1 |
---
|
| 2 |
license: cc-by-4.0
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: cc-by-4.0
|
| 3 |
---
|
| 4 |
+
|
| 5 |
+
## Code snippet to visualise the position of the box
|
| 6 |
+
|
| 7 |
+
```python
|
| 8 |
+
import matplotlib.image as img
|
| 9 |
+
import matplotlib.pyplot as plt
|
| 10 |
+
from datasets import load_dataset
|
| 11 |
+
from matplotlib.patches import Rectangle
|
| 12 |
+
|
| 13 |
+
# Load dataset
|
| 14 |
+
ds_name = "SaulLu/Caltech-101"
|
| 15 |
+
ds_config = "without_background_category"
|
| 16 |
+
|
| 17 |
+
ds_without = load_dataset(ds_name, ds_config, use_auth_token=True, cache_dir="new_cache_2")
|
| 18 |
+
|
| 19 |
+
# Extract information for the sample we want to show
|
| 20 |
+
index = 100
|
| 21 |
+
sample = ds_without["train"][index]
|
| 22 |
+
box_coord = sample["annotation"]["box_coord"][0]
|
| 23 |
+
img_path = sample["image"].filename
|
| 24 |
+
|
| 25 |
+
# Create plot
|
| 26 |
+
# define Matplotlib figure and axis
|
| 27 |
+
fig, ax = plt.subplots()
|
| 28 |
+
|
| 29 |
+
# plot figure
|
| 30 |
+
image = img.imread(img_path)
|
| 31 |
+
ax.imshow(image)
|
| 32 |
+
|
| 33 |
+
# add rectangle to plot
|
| 34 |
+
ax.add_patch(
|
| 35 |
+
Rectangle((box_coord[2], box_coord[0]), box_coord[3] - box_coord[2], box_coord[1] - box_coord[0], fill=None)
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# display plot
|
| 39 |
+
plt.show()
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Result:
|
| 43 |
+

|
data_readme/sample_100_box_pos.png
ADDED
|