Deokyun commited on
Commit
66dd5f5
·
verified ·
1 Parent(s): 5aec942

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +32 -15
README.md CHANGED
@@ -99,27 +99,44 @@ from PIL import Image
99
  import matplotlib.pyplot as plt
100
  import matplotlib.patches as patches
101
  from io import BytesIO
 
102
 
103
- # Hugging Face image base path
104
- BASE_URL = "https://huggingface.co/datasets/etri/ForestPersons/resolve/main/"
105
-
106
- # Load sample
107
  sample = dataset[0]
 
 
 
108
  image_url = BASE_URL + sample["file_name"]
109
 
110
- # Load image
111
- image = Image.open(BytesIO(requests.get(image_url).content))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
- # Draw image + bounding box
114
- fig, ax = plt.subplots()
115
- ax.imshow(image)
116
- x, y, w, h = sample["bbox_x"], sample["bbox_y"], sample["bbox_w"], sample["bbox_h"]
117
- rect = patches.Rectangle((x, y), w, h, linewidth=2, edgecolor='red', facecolor='none')
118
- ax.add_patch(rect)
119
- plt.title(f"{sample['file_name']} | {sample['category_name']}")
120
- plt.axis("off")
121
- plt.show()
122
 
 
 
123
  ```
124
 
125
  ## License
 
99
  import matplotlib.pyplot as plt
100
  import matplotlib.patches as patches
101
  from io import BytesIO
102
+ from datasets import load_dataset
103
 
104
+ # Load the dataset from Hugging Face
105
+ dataset = load_dataset("etri/ForestPersons", split="validation")
 
 
106
  sample = dataset[0]
107
+
108
+ # Image URL
109
+ BASE_URL = "https://huggingface.co/datasets/etri/ForestPersons/resolve/main/"
110
  image_url = BASE_URL + sample["file_name"]
111
 
112
+ # Load the image, Please wait about 30 seconds....
113
+ response = requests.get(image_url)
114
+ if response.status_code == 200:
115
+ image = Image.open(BytesIO(response.content))
116
+
117
+ # Draw image and bounding box
118
+ fig, ax = plt.subplots()
119
+ ax.imshow(image)
120
+
121
+ # Bounding box coordinates
122
+ x = sample["bbox_x"]
123
+ y = sample["bbox_y"]
124
+ w = sample["bbox_w"]
125
+ h = sample["bbox_h"]
126
+
127
+ # Draw bounding box
128
+ rect = patches.Rectangle((x, y), w, h, linewidth=2, edgecolor='red', facecolor='none')
129
+ ax.add_patch(rect)
130
+
131
+ # Draw label above the bounding box
132
+ label = sample["category_name"]
133
+ ax.text(x, y - 5, label, fontsize=10, color='white', backgroundcolor='red', verticalalignment='bottom')
134
 
135
+ plt.axis("off")
136
+ plt.show()
 
 
 
 
 
 
 
137
 
138
+ else:
139
+ print(f"Failed to load image: {image_url}")
140
  ```
141
 
142
  ## License