Skip to content

Commit 86b60df

Browse files
committed
reorganize notebooks for better sharing
1 parent f99080f commit 86b60df

7 files changed

+948
-835
lines changed

01-ssd-framework-single-shot-detector-for-object-detection.ipynb

Lines changed: 436 additions & 0 deletions
Large diffs are not rendered by default.

02-data-encoding-and-decoding.ipynb

Lines changed: 455 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.

explore-dataset.ipynb renamed to 99-check-dataset-class-imbalance.ipynb

Lines changed: 57 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# global variables"
7+
"## Dependecies and Parameters\n",
8+
"\n",
9+
"Let's quickly import dependecies and define some useful parameters for this notebook."
810
]
911
},
1012
{
1113
"cell_type": "code",
12-
"execution_count": 1,
14+
"execution_count": 7,
1315
"metadata": {},
1416
"outputs": [],
1517
"source": [
18+
"# dependecies\n",
19+
"import csv\n",
20+
"import json\n",
21+
"import numpy as np\n",
22+
"import random\n",
23+
"\n",
1624
"# data options\n",
1725
"LABELS_CODES = [0, 1, 2, 3]\n",
1826
"LABEL_CODE_BACKGROUND = 0\n",
@@ -38,31 +46,14 @@
3846
"cell_type": "markdown",
3947
"metadata": {},
4048
"source": [
41-
"# dependecies"
42-
]
43-
},
44-
{
45-
"cell_type": "code",
46-
"execution_count": 2,
47-
"metadata": {},
48-
"outputs": [],
49-
"source": [
50-
"import csv\n",
51-
"import json\n",
52-
"import numpy as np\n",
53-
"import random"
54-
]
55-
},
56-
{
57-
"cell_type": "markdown",
58-
"metadata": {},
59-
"source": [
60-
"# load metadata"
49+
"## Read Metadata\n",
50+
"\n",
51+
"Read metadata (files paths locations for images and boxes coordinates)."
6152
]
6253
},
6354
{
6455
"cell_type": "code",
65-
"execution_count": 14,
56+
"execution_count": 8,
6657
"metadata": {},
6758
"outputs": [],
6859
"source": [
@@ -101,67 +92,22 @@
10192
"cell_type": "markdown",
10293
"metadata": {},
10394
"source": [
104-
"# object detection"
95+
"## Check Class Imbalance"
10596
]
10697
},
10798
{
10899
"cell_type": "code",
109-
"execution_count": 15,
100+
"execution_count": 9,
110101
"metadata": {},
111102
"outputs": [],
112103
"source": [
113104
"# which data should be evaluated?\n",
114105
"PATH_FILES_LABELS_BOXES = path_files_labels_boxes_train"
115106
]
116107
},
117-
{
118-
"cell_type": "markdown",
119-
"metadata": {},
120-
"source": [
121-
"## samples, images and boxes aspect ratios for each class"
122-
]
123-
},
124-
{
125-
"cell_type": "code",
126-
"execution_count": 16,
127-
"metadata": {},
128-
"outputs": [],
129-
"source": [
130-
"# for each class initialize counters for samples (images), instances (objects) and boxes aspect ratios (width / height)\n",
131-
"# storing samples indexes per class and then counting the number of unique indexes it's a simple way to count samples per class\n",
132-
"samples_per_class = {label: [] for label in LABELS_CODES if label != LABEL_CODE_BACKGROUND}\n",
133-
"instances_per_class = {label: 0 for label in LABELS_CODES if label != LABEL_CODE_BACKGROUND}\n",
134-
"boxes_aspect_ratios_per_class = {label: [] for label in LABELS_CODES if label != LABEL_CODE_BACKGROUND}\n",
135-
"\n",
136-
"# for each file count number of samples per class and images per class\n",
137-
"for i, path_file_labels_boxes in enumerate(PATH_FILES_LABELS_BOXES):\n",
138-
"\n",
139-
" # read ground truth labels and boxes\n",
140-
" with open(path_file_labels_boxes, 'r') as f:\n",
141-
" for label, xmin, ymin, xmax, ymax in csv.reader(f):\n",
142-
"\n",
143-
" # format ground truth data\n",
144-
" label = int(label)\n",
145-
" width = float(xmax) - float(xmin) + 1.0\n",
146-
" height = float(ymax) - float(ymin) + 1.0 \n",
147-
"\n",
148-
" # add indexes for count samples later on\n",
149-
" samples_per_class[label].append(i)\n",
150-
"\n",
151-
" # increment instances counter\n",
152-
" instances_per_class[label] += 1\n",
153-
"\n",
154-
" # add aspect ratio to the list\n",
155-
" boxes_aspect_ratios_per_class[label].append(width / height)\n",
156-
"\n",
157-
"\n",
158-
"# calculate the number of samples per class\n",
159-
"samples_per_class = {label: len(set(indexes)) for label, indexes in samples_per_class.items()}"
160-
]
161-
},
162108
{
163109
"cell_type": "code",
164-
"execution_count": 18,
110+
"execution_count": 10,
165111
"metadata": {},
166112
"outputs": [
167113
{
@@ -180,7 +126,7 @@
180126
"*** instances ***\n",
181127
"************************\n",
182128
"> monorail: 1,861 - 34%\n",
183-
"> person: 2,097 - 38%\n",
129+
"> person: 2,071 - 38%\n",
184130
"> forklift: 1,535 - 28%\n",
185131
"\n",
186132
"************************\n",
@@ -198,14 +144,14 @@
198144
" - p80: 3.376\n",
199145
" - p90: 5.129\n",
200146
"> person\n",
201-
" - p10: 0.315\n",
202-
" - p20: 0.385\n",
203-
" - p30: 0.467\n",
204-
" - p40: 0.557\n",
147+
" - p10: 0.318\n",
148+
" - p20: 0.388\n",
149+
" - p30: 0.471\n",
150+
" - p40: 0.559\n",
205151
" - p50: 0.662\n",
206-
" - p60: 0.781\n",
207-
" - p70: 0.955\n",
208-
" - p80: 1.277\n",
152+
" - p60: 0.788\n",
153+
" - p70: 0.972\n",
154+
" - p80: 1.325\n",
209155
" - p90: 2.571\n",
210156
"> forklift\n",
211157
" - p10: 0.461\n",
@@ -221,6 +167,37 @@
221167
}
222168
],
223169
"source": [
170+
"# for each class initialize counters for samples (images), instances (objects) and boxes aspect ratios (width / height)\n",
171+
"# storing samples indexes per class and then counting the number of unique indexes it's a simple way to count samples per class\n",
172+
"samples_per_class = {label: [] for label in LABELS_CODES if label != LABEL_CODE_BACKGROUND}\n",
173+
"instances_per_class = {label: 0 for label in LABELS_CODES if label != LABEL_CODE_BACKGROUND}\n",
174+
"boxes_aspect_ratios_per_class = {label: [] for label in LABELS_CODES if label != LABEL_CODE_BACKGROUND}\n",
175+
"\n",
176+
"# for each file count number of samples per class and images per class\n",
177+
"for i, path_file_labels_boxes in enumerate(PATH_FILES_LABELS_BOXES):\n",
178+
"\n",
179+
" # read ground truth labels and boxes\n",
180+
" with open(path_file_labels_boxes, 'r') as f:\n",
181+
" for label, xmin, ymin, xmax, ymax in csv.reader(f):\n",
182+
"\n",
183+
" # format ground truth data\n",
184+
" label = int(label)\n",
185+
" width = float(xmax) - float(xmin) + 1.0\n",
186+
" height = float(ymax) - float(ymin) + 1.0 \n",
187+
"\n",
188+
" # add indexes for count samples later on\n",
189+
" samples_per_class[label].append(i)\n",
190+
"\n",
191+
" # increment instances counter\n",
192+
" instances_per_class[label] += 1\n",
193+
"\n",
194+
" # add aspect ratio to the list\n",
195+
" boxes_aspect_ratios_per_class[label].append(width / height)\n",
196+
"\n",
197+
"\n",
198+
"# calculate the number of samples per class\n",
199+
"samples_per_class = {label: len(set(indexes)) for label, indexes in samples_per_class.items()}\n",
200+
"\n",
224201
"# print samples\n",
225202
"total_samples = sum(samples_per_class.values())\n",
226203
"print('\\n************************')\n",
@@ -274,7 +251,7 @@
274251
"name": "python",
275252
"nbconvert_exporter": "python",
276253
"pygments_lexer": "ipython3",
277-
"version": "3.10.12"
254+
"version": "3.11.9"
278255
},
279256
"orig_nbformat": 4
280257
},
File renamed without changes.

0 commit comments

Comments
 (0)