Skip to content

Commit 3060f14

Browse files
Load each directory's images and label
1 parent abc1fce commit 3060f14

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

Audio_Classification_Using_CNNs.ipynb

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
{
9999
"cell_type": "markdown",
100100
"source": [
101-
"## Generate Spectrogram\n",
101+
"## **Generate Spectrogram**\n",
102102
"\n"
103103
],
104104
"metadata": {
@@ -255,19 +255,26 @@
255255
{
256256
"cell_type": "code",
257257
"source": [
258-
"## load each directory's images and label:\n",
259-
"'''\n",
260-
"suggested classes for each directory:\n",
261-
"background -> 0\n",
262-
"chainsaw -> 1\n",
263-
"engine -> 2\n",
264-
"storm -> 3\n",
265-
"'''\n",
266-
"## after loading the images, concat them to the x and y lists respectively\n",
267-
"## show some of them\n",
268-
"##############################################\n",
269-
"############# YOUR CODES GO HERE #############\n",
270-
"##############################################"
258+
"## Load each directory's images and label\n",
259+
"\n",
260+
"class_mapping = {\n",
261+
" 'background': 0,\n",
262+
" 'chainsaw': 1,\n",
263+
" 'engine': 2,\n",
264+
" 'storm': 3\n",
265+
"}\n",
266+
"\n",
267+
"spectrogram_root = 'dataset/spectrograms'\n",
268+
"\n",
269+
"for class_name, label in class_mapping.items():\n",
270+
" class_path = os.path.join(spectrogram_root, class_name)\n",
271+
" images, labels = loading_spectrograms(class_path, label)\n",
272+
"\n",
273+
" x.extend(images)\n",
274+
" y.extend(labels)\n",
275+
"\n",
276+
"# Show a sample of loaded images\n",
277+
"show_images(x)"
271278
],
272279
"metadata": {
273280
"id": "qV6bm8VtMeTS"
@@ -312,7 +319,7 @@
312319
{
313320
"cell_type": "markdown",
314321
"source": [
315-
"## Build and train a CNN"
322+
"## **Build and train a CNN**"
316323
],
317324
"metadata": {
318325
"id": "LVM1AzW2R3bz"

0 commit comments

Comments
 (0)