{"cells":[{"metadata":{},"cell_type":"markdown","source":"[This dataset](https://www.kaggle.com/pchlq82/birdsong-log-mel-spectrograms) was created to speed up CV models training stages. The images are log-scale mel-spectrograms with size of 224. [Tawara](https://www.kaggle.com/ttahara)'s [datasets](https://www.kaggle.com/ttahara/birdsong-resampled-train-audio-04) were used to generate the images. The folder splitting structure is identical. Python script is also available.","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport random\nfrom typing import List\nfrom pathlib import Path\nfrom PIL import Image\nfrom dataclasses import dataclass\nimport pylab\nimport matplotlib.pyplot as plt\n%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"@dataclass\nclass Project:\n\n    base_dir: Path = Path(\".\").absolute().parent\n    birdsong_imgs_dir = base_dir / \"input/birdsong-log-mel-spectrograms\"\n    fold_0 = birdsong_imgs_dir / \"fold_0/fold_0\"\n    get_n_images = 6\n    \nproj = Project()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Number of images in each fold\nfor i in range(5):\n    print(\"fold: \", i, \"-->\", len(list(proj.birdsong_imgs_dir.glob(f\"fold_{i}/fold_{i}/*/*.png\"))))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels = np.unique([i.name for i in list(proj.fold_0.glob(\"*\"))])\nrandom_lables = random.choices(labels, k=proj.get_n_images)\n\n# selecting 6 different labels\nlabel_paths = [random.choice( list(proj.fold_0.glob(f\"{label}/*.png\")) ) for label in random_lables]\nlabel_paths","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def plot_imgs(imgs_lst: List[Path]=label_paths) -> None:\n    plt.figure(figsize=[20,14])\n    ncols = 3\n    nrows = np.ceil( len(imgs_lst)/ncols ).astype(int)\n    for i, im_path in enumerate(imgs_lst):\n        ax = plt.subplot(nrows, ncols, i + 1)\n        ax.set_title(im_path.parent.name, fontsize=12)\n        ax.imshow(Image.open(im_path))\n        ax.set_xlabel(\"time\")\n        ax.set_ylabel(\"Hz\")\n    \n    plt.suptitle('Mel Spectrograms [224x224 pixels]', y=1.05,  fontsize=16)   \n    plt.tight_layout()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plot_imgs()","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"%%html\n<marquee style='width: 50%; color: blue;'><b>THANKS FOR YOUR ATTENTION!</b></marquee>","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}