|
4 | 4 | "cell_type": "markdown",
|
5 | 5 | "metadata": {},
|
6 | 6 | "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." |
8 | 10 | ]
|
9 | 11 | },
|
10 | 12 | {
|
11 | 13 | "cell_type": "code",
|
12 |
| - "execution_count": 1, |
| 14 | + "execution_count": 7, |
13 | 15 | "metadata": {},
|
14 | 16 | "outputs": [],
|
15 | 17 | "source": [
|
| 18 | + "# dependecies\n", |
| 19 | + "import csv\n", |
| 20 | + "import json\n", |
| 21 | + "import numpy as np\n", |
| 22 | + "import random\n", |
| 23 | + "\n", |
16 | 24 | "# data options\n",
|
17 | 25 | "LABELS_CODES = [0, 1, 2, 3]\n",
|
18 | 26 | "LABEL_CODE_BACKGROUND = 0\n",
|
|
38 | 46 | "cell_type": "markdown",
|
39 | 47 | "metadata": {},
|
40 | 48 | "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)." |
61 | 52 | ]
|
62 | 53 | },
|
63 | 54 | {
|
64 | 55 | "cell_type": "code",
|
65 |
| - "execution_count": 14, |
| 56 | + "execution_count": 8, |
66 | 57 | "metadata": {},
|
67 | 58 | "outputs": [],
|
68 | 59 | "source": [
|
|
101 | 92 | "cell_type": "markdown",
|
102 | 93 | "metadata": {},
|
103 | 94 | "source": [
|
104 |
| - "# object detection" |
| 95 | + "## Check Class Imbalance" |
105 | 96 | ]
|
106 | 97 | },
|
107 | 98 | {
|
108 | 99 | "cell_type": "code",
|
109 |
| - "execution_count": 15, |
| 100 | + "execution_count": 9, |
110 | 101 | "metadata": {},
|
111 | 102 | "outputs": [],
|
112 | 103 | "source": [
|
113 | 104 | "# which data should be evaluated?\n",
|
114 | 105 | "PATH_FILES_LABELS_BOXES = path_files_labels_boxes_train"
|
115 | 106 | ]
|
116 | 107 | },
|
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 |
| - }, |
162 | 108 | {
|
163 | 109 | "cell_type": "code",
|
164 |
| - "execution_count": 18, |
| 110 | + "execution_count": 10, |
165 | 111 | "metadata": {},
|
166 | 112 | "outputs": [
|
167 | 113 | {
|
|
180 | 126 | "*** instances ***\n",
|
181 | 127 | "************************\n",
|
182 | 128 | "> monorail: 1,861 - 34%\n",
|
183 |
| - "> person: 2,097 - 38%\n", |
| 129 | + "> person: 2,071 - 38%\n", |
184 | 130 | "> forklift: 1,535 - 28%\n",
|
185 | 131 | "\n",
|
186 | 132 | "************************\n",
|
|
198 | 144 | " - p80: 3.376\n",
|
199 | 145 | " - p90: 5.129\n",
|
200 | 146 | "> 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", |
205 | 151 | " - 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", |
209 | 155 | " - p90: 2.571\n",
|
210 | 156 | "> forklift\n",
|
211 | 157 | " - p10: 0.461\n",
|
|
221 | 167 | }
|
222 | 168 | ],
|
223 | 169 | "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", |
224 | 201 | "# print samples\n",
|
225 | 202 | "total_samples = sum(samples_per_class.values())\n",
|
226 | 203 | "print('\\n************************')\n",
|
|
274 | 251 | "name": "python",
|
275 | 252 | "nbconvert_exporter": "python",
|
276 | 253 | "pygments_lexer": "ipython3",
|
277 |
| - "version": "3.10.12" |
| 254 | + "version": "3.11.9" |
278 | 255 | },
|
279 | 256 | "orig_nbformat": 4
|
280 | 257 | },
|
|
0 commit comments