{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.10","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":44224,"databundleVersionId":5188730,"sourceType":"competition"}],"dockerImageVersionId":30474,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"pip install torch torchvision torchaudio","metadata":{"execution":{"iopub.status.busy":"2023-08-11T17:16:02.077501Z","iopub.execute_input":"2023-08-11T17:16:02.077907Z","iopub.status.idle":"2023-08-11T17:16:17.435531Z","shell.execute_reply.started":"2023-08-11T17:16:02.077874Z","shell.execute_reply":"2023-08-11T17:16:17.434084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport IPython\nimport scipy\nimport librosa\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport torchvision\nimport torch \n\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\n\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-08-11T17:28:39.259778Z","iopub.execute_input":"2023-08-11T17:28:39.260267Z","iopub.status.idle":"2023-08-11T17:28:44.232650Z","shell.execute_reply.started":"2023-08-11T17:28:39.260226Z","shell.execute_reply":"2023-08-11T17:28:44.231332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def list_files():\n    import os\n    for dirname, _, filenames in os.walk('/kaggle/input'):\n        for filename in filenames:\n            print(os.path.join(dirname, filename))   \n            files = os.path.join(dirname, filename)\n            zip(dirname,filename)\n            print(files)\n            \n            \n    \n    \ndef generate_mappings():\n    \"\"\"make mappings from birdname to audiofile names\"\"\"\n    mappings = {}\n    for dirpath,dirname,filename in os.walk('/kaggle/input/birdclef-2023/train_audio'):\n        mappings[dirpath] = filename\n        return mappings\n        \n    \n    \n\n    ","metadata":{"execution":{"iopub.status.busy":"2023-07-03T14:19:27.924349Z","iopub.execute_input":"2023-07-03T14:19:27.925422Z","iopub.status.idle":"2023-07-03T14:19:27.933482Z","shell.execute_reply.started":"2023-07-03T14:19:27.925376Z","shell.execute_reply":"2023-07-03T14:19:27.932045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd \ndf = pd.read_csv(\"/kaggle/input/birdclef-2023/train_metadata.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:05:27.731919Z","iopub.execute_input":"2023-09-02T15:05:27.732343Z","iopub.status.idle":"2023-09-02T15:05:27.889543Z","shell.execute_reply.started":"2023-09-02T15:05:27.732313Z","shell.execute_reply":"2023-09-02T15:05:27.888169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import librosa\nimport librosa.display\nimport os\nimport shutil\nimport numpy as np\nimport matplotlib.pyplot as plt\n\ndef generate_mel_spectrogram(input_file):\n    y, sr = librosa.load(input_file)\n    mel_spectrogram = librosa.feature.melspectrogram(y=y, sr=sr)\n    mel_spectrogram_db = librosa.power_to_db(mel_spectrogram, ref=np.max)\n    return mel_spectrogram_db, sr\n\ndef save_mel_spectrogram(input_file, mel_spectrogram, sr, output_dir):\n    file_name = os.path.splitext(os.path.basename(input_file))[0]\n    output_file = os.path.join(output_dir, f\"{file_name}_mel.png\")\n    plt.figure(figsize=(10, 6))\n    librosa.display.specshow(mel_spectrogram, sr=sr, x_axis='time', y_axis='mel')\n    plt.savefig(output_file)\n    plt.close()\n\n# Base directory containing subdirectories with .ogg files\nbase_directory = \"/kaggle/input/birdclef-2023/train_audio\"\n\n# Directory for saving mel spectrogram images\noutput_base_directory = \"/kaggle/working\"\n\n# Ensure the base directory exists\nif not os.path.exists(base_directory):\n    print(\"Base directory does not exist.\")\n    exit()\n\n# Loop through all subdirectories and their files using os.walk\nfor root, dirs, files in os.walk(base_directory):\n    for filename in files:\n        if filename.endswith(\".ogg\"):\n            input_file = os.path.join(root, filename)\n            mel_spectrogram, sr = generate_mel_spectrogram(input_file)\n            \n            # Create an output directory with the subdirectory name\n            relative_subdir = os.path.relpath(root, base_directory)\n            output_directory = os.path.join(output_base_directory, relative_subdir)\n            os.makedirs(output_directory, exist_ok=True)\n            \n            save_mel_spectrogram(input_file, mel_spectrogram, sr, output_directory)\n","metadata":{"execution":{"iopub.status.busy":"2023-09-02T08:43:24.830173Z","iopub.execute_input":"2023-09-02T08:43:24.830694Z","iopub.status.idle":"2023-09-02T08:43:35.716362Z","shell.execute_reply.started":"2023-09-02T08:43:24.830649Z","shell.execute_reply":"2023-09-02T08:43:35.714757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import gc\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2023-08-27T13:22:57.351565Z","iopub.execute_input":"2023-08-27T13:22:57.351966Z","iopub.status.idle":"2023-08-27T13:23:05.559129Z","shell.execute_reply.started":"2023-08-27T13:22:57.351921Z","shell.execute_reply":"2023-08-27T13:23:05.557745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2023-09-02T08:41:58.460943Z","iopub.execute_input":"2023-09-02T08:41:58.461654Z","iopub.status.idle":"2023-09-02T08:41:59.597351Z","shell.execute_reply.started":"2023-09-02T08:41:58.461617Z","shell.execute_reply":"2023-09-02T08:41:59.596203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import librosa\nimport librosa.display\nimport os\nimport numpy as np\nimport matplotlib.pyplot as pltimport librosa\nimport librosa.display\nimport os\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom tqdm import tqdm\nfrom IPython.display import clear_output\nimport time\n\ndef generate_mel_spectrogram(input_file):\n    y, sr = librosa.load(input_file)\n    mel_spectrogram = librosa.feature.melspectrogram(y=y, sr=sr)\n    mel_spectrogram_db = librosa.power_to_db(mel_spectrogram, ref=np.max)\n    return mel_spectrogram_db, sr\n\ndef save_mel_spectrogram(input_file, mel_spectrogram, sr, output_file):\n    plt.figure(figsize=(10, 6))\n    librosa.display.specshow(mel_spectrogram, sr=sr)\n    plt.savefig(output_file)\n    plt.close()\nbase_directory = \"/kaggle/input/birdclef-2023/train_audio\"\n\noutput_base_directory = \"/kaggle/working\"\n\nif not os.path.exists(base_directory):\n    print(\"Base directory does not exist.\")\n    exit()\n\ntotal_files = sum(len(files) for _, _, files in os.walk(base_directory))\npbar = tqdm(total=total_files, desc=\"Processing files\", unit=\"file\")\n\nstart_time = time.time()\nfor root, dirs, files in os.walk(base_directory):\n    for filename in files:\n        if filename.endswith(\".ogg\"):\n            input_file = os.path.join(root, filename)\n            \n            relative_subdir = os.path.relpath(root, base_directory)\n            output_directory = os.path.join(output_base_directory, relative_subdir)\n            os.makedirs(output_directory, exist_ok=True)\n            \n            file_name = os.path.splitext(filename)[0]\n            output_file = os.path.join(output_directory, f\"{file_name}_mel.png\")\n            \n            if not os.path.exists(output_file):\n                mel_spectrogram, sr = generate_mel_spectrogram(input_file)\n                save_mel_spectrogram(input_file, mel_spectrogram, sr, output_file)\n            \n            pbar.update(1)\n            elapsed_time = time.time() - start_time\n            remaining_files = total_files - pbar.n\n            time_per_file = elapsed_time / pbar.n if pbar.n > 0 else 0\n            time_left = remaining_files * time_per_file\n            pbar.set_postfix({\"Current Dir\": os.path.basename(root), \"Time Left\": f\"{time_left:.2f} s\"})\n            \n\npbar.close()\n","metadata":{"execution":{"iopub.status.busy":"2023-08-27T13:23:57.358946Z","iopub.execute_input":"2023-08-27T13:23:57.359337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import librosa\nimport librosa.display\nimport os\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom tqdm import tqdm\nfrom IPython.display import clear_output\nimport time","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:00:16.700840Z","iopub.execute_input":"2023-09-02T15:00:16.701606Z","iopub.status.idle":"2023-09-02T15:00:16.746090Z","shell.execute_reply.started":"2023-09-02T15:00:16.701570Z","shell.execute_reply":"2023-09-02T15:00:16.744994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def save_mel_spectrogram(input_file, mel_spectrogram, sr):\n    plt.figure(figsize=(10, 6))\n    librosa.display.specshow(mel_spectrogram, sr=sr)\n    \n    #plt.savefig(output_file)\n    plt.show()\n    plt.close()","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:00:37.071639Z","iopub.execute_input":"2023-09-02T15:00:37.072725Z","iopub.status.idle":"2023-09-02T15:00:37.078682Z","shell.execute_reply.started":"2023-09-02T15:00:37.072687Z","shell.execute_reply":"2023-09-02T15:00:37.077633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"librosa.display.specshow(mel_spectrogram, sr=sr)\n","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:03:58.381594Z","iopub.execute_input":"2023-09-02T15:03:58.381981Z","iopub.status.idle":"2023-09-02T15:03:58.848249Z","shell.execute_reply.started":"2023-09-02T15:03:58.381953Z","shell.execute_reply":"2023-09-02T15:03:58.845747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mel_spectrogram","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:02:33.769762Z","iopub.execute_input":"2023-09-02T15:02:33.770205Z","iopub.status.idle":"2023-09-02T15:02:33.778901Z","shell.execute_reply.started":"2023-09-02T15:02:33.770170Z","shell.execute_reply":"2023-09-02T15:02:33.777453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with open('outfile.a', 'w') as f:\n    f.write(mel_spectrogram)\n    ","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:02:13.891933Z","iopub.execute_input":"2023-09-02T15:02:13.893097Z","iopub.status.idle":"2023-09-02T15:02:13.927424Z","shell.execute_reply.started":"2023-09-02T15:02:13.893050Z","shell.execute_reply":"2023-09-02T15:02:13.925639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mel_spectrogram","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:01:04.450990Z","iopub.execute_input":"2023-09-02T15:01:04.451415Z","iopub.status.idle":"2023-09-02T15:01:04.460802Z","shell.execute_reply.started":"2023-09-02T15:01:04.451385Z","shell.execute_reply":"2023-09-02T15:01:04.459421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def generate_mel_spectrogram(input_file):\n    y, sr = librosa.load(input_file)\n    mel_spectrogram = librosa.feature.melspectrogram(y=y, sr=sr)\n    mel_spectrogram_db = librosa.power_to_db(mel_spectrogram, ref=np.max)\n    return mel_spectrogram_db, sr","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:00:20.740364Z","iopub.execute_input":"2023-09-02T15:00:20.740800Z","iopub.status.idle":"2023-09-02T15:00:20.747421Z","shell.execute_reply.started":"2023-09-02T15:00:20.740761Z","shell.execute_reply":"2023-09-02T15:00:20.746177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_file = \"/kaggle/input/birdclef-2023/train_audio/abethr1/XC128013.ogg\"\nmel_spectrogram, sr = generate_mel_spectrogram(input_file)\nsave_mel_spectrogram(input_file, mel_spectrogram, sr)","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:00:22.569980Z","iopub.execute_input":"2023-09-02T15:00:22.570705Z","iopub.status.idle":"2023-09-02T15:00:37.069432Z","shell.execute_reply.started":"2023-09-02T15:00:22.570658Z","shell.execute_reply":"2023-09-02T15:00:37.068260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mel_spectrogram[0]","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:03:34.251563Z","iopub.execute_input":"2023-09-02T15:03:34.251952Z","iopub.status.idle":"2023-09-02T15:03:34.258339Z","shell.execute_reply.started":"2023-09-02T15:03:34.251923Z","shell.execute_reply":"2023-09-02T15:03:34.257563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mel_spectrogram.shape","metadata":{"execution":{"iopub.status.busy":"2023-09-02T08:44:51.291035Z","iopub.execute_input":"2023-09-02T08:44:51.291477Z","iopub.status.idle":"2023-09-02T08:44:51.299653Z","shell.execute_reply.started":"2023-09-02T08:44:51.291428Z","shell.execute_reply":"2023-09-02T08:44:51.298404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nfrom scipy.signal import convolve2d\n\n# Assuming you have a 'mel_spectrogram' variable containing your Mel spectrogram\n\n# Define a custom 3x3 kernel (you can modify this kernel as needed)\ncustom_kernel = np.array([[1, 0, -1],\n                           [-1, 0, -2],\n                           [1, 0, -1]])\n\n# Apply the custom kernel to the Mel spectrogram\nresult = convolve2d(mel_spectrogram, custom_kernel, mode='same', boundary='wrap')\n\n# 'result' now contains the convolution result using the custom kernel\n","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:12:17.899563Z","iopub.execute_input":"2023-09-02T15:12:17.899960Z","iopub.status.idle":"2023-09-02T15:12:17.921890Z","shell.execute_reply.started":"2023-09-02T15:12:17.899931Z","shell.execute_reply":"2023-09-02T15:12:17.920074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"    librosa.display.specshow(result, sr=sr)\n    #plt.savefig(output_file)\n    plt.show()\n    plt.close()","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:12:18.576969Z","iopub.execute_input":"2023-09-02T15:12:18.577367Z","iopub.status.idle":"2023-09-02T15:12:18.937286Z","shell.execute_reply.started":"2023-09-02T15:12:18.577339Z","shell.execute_reply":"2023-09-02T15:12:18.936157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport scipy.signal as signal\nimport matplotlib.pyplot as plt\n\n# Create a 2D Gaussian kernel\ndef gaussian_kernel(size, sigma):\n    \"\"\"Generates a 2D Gaussian kernel.\"\"\"\n    kernel = np.fromfunction(\n        lambda x, y: (1/ (2 * np.pi * sigma ** 2)) * \n                     np.exp(- ((x - (size - 1) / 2) ** 2 + (y - (size - 1) / 2) ** 2) / (2 * sigma ** 2)),\n        (size, size)\n    )\n    return kernel / np.sum(kernel)\n\n# Create a sample image (you should replace this with your mel spectrogram)\nimage = np.random.rand(128, 128)\n\n# Define the kernel size and standard deviation (sigma)\nkernel_size = 5  # Adjust as needed\nsigma = 1.0      # Adjust as needed\n\n# Generate the Gaussian kernel\ngaussian = gaussian_kernel(kernel_size, sigma)\n\n# Apply the Gaussian filter to the image\nsmoothed_image = signal.convolve2d(mel_spectrogram, gaussian, mode='same', boundary='wrap')\n\n# Display the original and smoothed images (for visualization purposes)\n#plt.figure(figsize=(10, 5))\n#plt.subplot(1, 2, 1)\nplt.imshow(mel_spectrogram, cmap='gray')\nplt.title('Original Image')\n\n\n","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:14:17.887180Z","iopub.execute_input":"2023-09-02T15:14:17.887614Z","iopub.status.idle":"2023-09-02T15:14:18.191072Z","shell.execute_reply.started":"2023-09-02T15:14:17.887582Z","shell.execute_reply":"2023-09-02T15:14:18.190213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport scipy.signal as signal\nimport matplotlib.pyplot as plt\n\n# Create a 2D Gaussian kernel\ndef gaussian_kernel(size, sigma):\n    \"\"\"Generates a 2D Gaussian kernel.\"\"\"\n    kernel = np.fromfunction(\n        lambda x, y: (1/ (2 * np.pi * sigma ** 2)) * \n                     np.exp(- ((x - (size - 1) / 2) ** 2 + (y - (size - 1) / 2) ** 2) / (2 * sigma ** 2)),\n        (size, size)\n    )\n    return kernel / np.sum(kernel)\n\n# Create a sample image (you should replace this with your mel spectrogram)\nimage = np.random.rand(128, 128)\n\n# Define the kernel size and standard deviation (sigma)\nkernel_size = 5  # Adjust as needed\nsigma = 1.0      # Adjust as needed\n\n# Generate the Gaussian kernel\ngaussian = gaussian_kernel(kernel_size, sigma)\n\n# Apply the Gaussian filter to the image\nsmoothed_image = signal.convolve2d(image, gaussian, mode='same', boundary='wrap')\n\n# Display the original and smoothed images (for visualization purposes)\nplt.figure(figsize=(10, 5))\nplt.subplot(1, 2, 1)\nplt.imshow(mel_spectrogram, cmap='gray')\nplt.title('Original Image')\n\nplt.subplot(1, 2, 2)\nplt.imshow(smoothed_image, cmap='gray')\nplt.title('Smoothed Image (Gaussian Filter)')\n\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:15:43.501258Z","iopub.execute_input":"2023-09-02T15:15:43.502375Z","iopub.status.idle":"2023-09-02T15:15:43.988197Z","shell.execute_reply.started":"2023-09-02T15:15:43.502333Z","shell.execute_reply":"2023-09-02T15:15:43.987066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(smoothed_image, cmap='gray')\nplt.title('Smoothed Image (Gaussian Filter)')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-02T15:14:26.677474Z","iopub.execute_input":"2023-09-02T15:14:26.678120Z","iopub.status.idle":"2023-09-02T15:14:26.915386Z","shell.execute_reply.started":"2023-09-02T15:14:26.678083Z","shell.execute_reply":"2023-09-02T15:14:26.914208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport numpy as np\n\n# Create a Gabor kernel\nkernel = np.array([[0.05, 0.1, 0.05],\n                    [0.1, -0.8, 0.1],\n                    [0.05, 0.1, 0.05]])\n\n# Normalize the kernel\nkernel = kernel / np.sum(kernel)\n\n# Blur the image with the kernel\nblurred_image = cv2.filter2D(mel_spectrogram, -1, kernel)\n\n# Display the blurred image\ncv2.imshow('Blurred Image', blurred_image)\ncv2.waitKey(0)\ncv2.destroyAllWindows()","metadata":{"execution":{"iopub.status.busy":"2023-09-02T08:53:57.450796Z","iopub.execute_input":"2023-09-02T08:53:57.451212Z","iopub.status.idle":"2023-09-02T08:53:57.491359Z","shell.execute_reply.started":"2023-09-02T08:53:57.451176Z","shell.execute_reply":"2023-09-02T08:53:57.489566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numpy","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.convolve()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2023-08-11T17:28:47.084871Z","iopub.execute_input":"2023-08-11T17:28:47.085281Z","iopub.status.idle":"2023-08-11T17:28:47.137702Z","shell.execute_reply.started":"2023-08-11T17:28:47.085248Z","shell.execute_reply":"2023-08-11T17:28:47.136428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lis = []\nfor _, dirs, _ in os.walk('/kaggle/input/birdclef-2023/train_audio'):\n    lis.append(dirs)\nprint(len(lis))","metadata":{"execution":{"iopub.status.busy":"2023-08-11T17:36:15.006772Z","iopub.execute_input":"2023-08-11T17:36:15.007146Z","iopub.status.idle":"2023-08-11T17:36:19.319506Z","shell.execute_reply.started":"2023-08-11T17:36:15.007118Z","shell.execute_reply":"2023-08-11T17:36:19.318293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.arrayread_csv('/kaggle/input/birdclef-2023/eBird_Taxonomy_v2021.csv')","metadata":{"execution":{"iopub.status.busy":"2023-08-11T17:33:36.858222Z","iopub.execute_input":"2023-08-11T17:33:36.858648Z","iopub.status.idle":"2023-08-11T17:33:36.976627Z","shell.execute_reply.started":"2023-08-11T17:33:36.858615Z","shell.execute_reply":"2023-08-11T17:33:36.975416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.sort_values('rating',  ascending=False)","metadata":{"execution":{"iopub.status.busy":"2023-08-11T17:30:28.544314Z","iopub.execute_input":"2023-08-11T17:30:28.544779Z","iopub.status.idle":"2023-08-11T17:30:28.577132Z","shell.execute_reply.started":"2023-08-11T17:30:28.544745Z","shell.execute_reply":"2023-08-11T17:30:28.575712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_above_4 = df[df['rating'] > 4]\n","metadata":{"execution":{"iopub.status.busy":"2023-08-11T17:31:27.925892Z","iopub.execute_input":"2023-08-11T17:31:27.926271Z","iopub.status.idle":"2023-08-11T17:31:27.933987Z","shell.execute_reply.started":"2023-08-11T17:31:27.926241Z","shell.execute_reply":"2023-08-11T17:31:27.932642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['rating'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-08-11T17:32:38.123595Z","iopub.execute_input":"2023-08-11T17:32:38.123998Z","iopub.status.idle":"2023-08-11T17:32:38.133174Z","shell.execute_reply.started":"2023-08-11T17:32:38.123967Z","shell.execute_reply":"2023-08-11T17:32:38.132331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_above_4.size/df.size","metadata":{"execution":{"iopub.status.busy":"2023-08-11T17:32:05.277460Z","iopub.execute_input":"2023-08-11T17:32:05.277841Z","iopub.status.idle":"2023-08-11T17:32:05.285179Z","shell.execute_reply.started":"2023-08-11T17:32:05.277813Z","shell.execute_reply":"2023-08-11T17:32:05.283974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_above_4.size","metadata":{"execution":{"iopub.status.busy":"2023-08-11T17:31:40.486049Z","iopub.execute_input":"2023-08-11T17:31:40.486486Z","iopub.status.idle":"2023-08-11T17:31:40.492281Z","shell.execute_reply.started":"2023-08-11T17:31:40.486451Z","shell.execute_reply":"2023-08-11T17:31:40.491445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scipy.io.wavfile.read(f\"/kaggle/input/birdclef-2023/train_audio/{birdname}/{filename}.ogg\", mmap=False)","metadata":{"execution":{"iopub.status.busy":"2023-07-03T14:15:43.844788Z","iopub.execute_input":"2023-07-03T14:15:43.845225Z","iopub.status.idle":"2023-07-03T14:15:43.883679Z","shell.execute_reply.started":"2023-07-03T14:15:43.845192Z","shell.execute_reply":"2023-07-03T14:15:43.881848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import librosa\ndata , sample_rate = librosa.load(\"/kaggle/input/birdclef-2023/train_audio/yetgre1/XC716763.ogg\")","metadata":{"execution":{"iopub.status.busy":"2023-05-11T07:14:26.970740Z","iopub.execute_input":"2023-05-11T07:14:26.971535Z","iopub.status.idle":"2023-05-11T07:14:39.910594Z","shell.execute_reply.started":"2023-05-11T07:14:26.971494Z","shell.execute_reply":"2023-05-11T07:14:39.909625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.plot(data)","metadata":{"execution":{"iopub.status.busy":"2023-05-11T07:15:29.692032Z","iopub.execute_input":"2023-05-11T07:15:29.692428Z","iopub.status.idle":"2023-05-11T07:15:30.122748Z","shell.execute_reply.started":"2023-05-11T07:15:29.692399Z","shell.execute_reply":"2023-05-11T07:15:30.121528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import librosa\nimport numpy as np\nimport matplotlib.pyplot as plt\n\ndata , sample_rate = librosa.load(\"/kaggle/input/birdclef-2023/train_audio/yetgre1/XC716763.ogg\")\nD = librosa.stft(data)\ns = librosa.amplitude_to_db(np.abs(D), ref=np.max)\nplt.imshow(s)\nplt.imsave('test.png', s)\n","metadata":{"execution":{"iopub.status.busy":"2023-08-26T16:36:46.562483Z","iopub.execute_input":"2023-08-26T16:36:46.562968Z","iopub.status.idle":"2023-08-26T16:36:59.073245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2023-08-26T15:47:57.514708Z","iopub.execute_input":"2023-08-26T15:47:57.515239Z","iopub.status.idle":"2023-08-26T15:47:58.632378Z","shell.execute_reply.started":"2023-08-26T15:47:57.515203Z","shell.execute_reply":"2023-08-26T15:47:58.630469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install super-image\n","metadata":{"execution":{"iopub.status.busy":"2023-08-27T07:42:31.188241Z","iopub.execute_input":"2023-08-27T07:42:31.188607Z","iopub.status.idle":"2023-08-27T07:42:42.631461Z","shell.execute_reply.started":"2023-08-27T07:42:31.188578Z","shell.execute_reply":"2023-08-27T07:42:42.630486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from super_image import EdsrModel, ImageLoader\nfrom PIL import Image\nimport requests\n\nurl = 'test.png'\nimage = Image.open('test.png')\n\nmodel = EdsrModel.from_pretrained('eugenesiow/edsr-base', scale=2)      # scale 2, 3 and 4 models available\ninputs = ImageLoader.load_image(image)\npreds = model(inputs)\n\nImageLoader.save_image(preds, './scaled_2x.png')                        # save the output 2x scaled image to `./scaled_2x.png`\nImageLoader.save_compare(inputs, preds, './scaled_2x_compare.png')      # save an output comparing the super-image with a bicubic scaling\n    ","metadata":{"execution":{"iopub.status.busy":"2023-08-27T07:42:42.632980Z","iopub.execute_input":"2023-08-27T07:42:42.633294Z","iopub.status.idle":"2023-08-27T07:42:47.055642Z","shell.execute_reply.started":"2023-08-27T07:42:42.633257Z","shell.execute_reply":"2023-08-27T07:42:47.053726Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image2 = Image.open('test.png')\nimage2.show()\n\n","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pitches, magnitudes = librosa.piptrack(y=data, sr=sample_rate)\nprint(pitches)","metadata":{"execution":{"iopub.status.busy":"2023-05-14T08:18:39.987285Z","iopub.execute_input":"2023-05-14T08:18:39.987736Z","iopub.status.idle":"2023-05-14T08:18:40.961685Z","shell.execute_reply.started":"2023-05-14T08:18:39.987700Z","shell.execute_reply":"2023-05-14T08:18:40.960205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.shape(pitches)","metadata":{"execution":{"iopub.status.busy":"2023-05-14T08:21:08.086663Z","iopub.execute_input":"2023-05-14T08:21:08.087037Z","iopub.status.idle":"2023-05-14T08:21:08.094873Z","shell.execute_reply.started":"2023-05-14T08:21:08.087014Z","shell.execute_reply":"2023-05-14T08:21:08.093645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x, sr= librosa.load(file_name, sr=sr)\nmfcc_feature= librosa.feature.mfcc(x, sr=sr)\n\nfig, ax = plt.subplots(1, figsize=(12,8))\nmfcc_image=librosa.display.specshow(mfcc_feature, ax=ax, sr=sr, y_axis='linear')\nax.axes.get_xaxis().set_visible(False)\nax.axes.get_yaxis().set_visible(False)\nax.set_frame_on(False)\nax.set_xlabel(None)\nax.set_ylabel(None)\n#save the plots in testing folder\nfig.savefig('mfcc_image.png')","metadata":{"execution":{"iopub.status.busy":"2023-07-03T14:16:38.055539Z","iopub.execute_input":"2023-07-03T14:16:38.055951Z","iopub.status.idle":"2023-07-03T14:16:38.091348Z","shell.execute_reply.started":"2023-07-03T14:16:38.055911Z","shell.execute_reply":"2023-07-03T14:16:38.090120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot(path):\n    data , sample_rate = librosa.load(\"/kaggle/input/birdclef-2023/train_audio/yetgre1/XC716763.ogg\")\n    D = librosa.stft(data)\n    s = librosa.amplitude_to_db(np.abs(D), ref=np.max)\n    plt.imshow(s)\n    ","metadata":{"execution":{"iopub.status.busy":"2023-05-11T08:01:02.540614Z","iopub.execute_input":"2023-05-11T08:01:02.541358Z","iopub.status.idle":"2023-05-11T08:01:02.547606Z","shell.execute_reply.started":"2023-05-11T08:01:02.541316Z","shell.execute_reply":"2023-05-11T08:01:02.546323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plotspec(path):\n    data , sr = librosa.load(\"/kaggle/input/birdclef-2023/train_audio/yetgre1/XC716763.ogg\")\n    D = librosa.feature.melspectrogram(y=data,sr=sr,n_mels=123)\n    s = librosa.amplitude_to_db(D, ref=np.max)\n    plt.imshow(s)","metadata":{"execution":{"iopub.status.busy":"2023-05-11T08:01:55.031421Z","iopub.execute_input":"2023-05-11T08:01:55.031834Z","iopub.status.idle":"2023-05-11T08:01:55.037782Z","shell.execute_reply.started":"2023-05-11T08:01:55.031801Z","shell.execute_reply":"2023-05-11T08:01:55.036571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path=\"\"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot(\"/kaggle/input/birdclef-2023/train_audio/abethr1/XC639039.ogg\")","metadata":{"execution":{"iopub.status.busy":"2023-05-11T08:03:59.157419Z","iopub.execute_input":"2023-05-11T08:03:59.158301Z","iopub.status.idle":"2023-05-11T08:03:59.576155Z","shell.execute_reply.started":"2023-05-11T08:03:59.158265Z","shell.execute_reply":"2023-05-11T08:03:59.575028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plotspec(\"/kaggle/input/birdclef-2023/train_audio/abethr1/XC639039.ogg\")","metadata":{"execution":{"iopub.status.busy":"2023-05-11T08:03:56.558745Z","iopub.execute_input":"2023-05-11T08:03:56.559181Z","iopub.status.idle":"2023-05-11T08:03:56.881300Z","shell.execute_reply.started":"2023-05-11T08:03:56.559129Z","shell.execute_reply":"2023-05-11T08:03:56.880149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"s = librosa.amplitude_to_db(np.abs(D), ref=np.max)","metadata":{"execution":{"iopub.status.busy":"2023-05-11T07:50:40.432088Z","iopub.execute_input":"2023-05-11T07:50:40.432471Z","iopub.status.idle":"2023-05-11T07:50:40.461034Z","shell.execute_reply.started":"2023-05-11T07:50:40.432440Z","shell.execute_reply":"2023-05-11T07:50:40.459568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(s)","metadata":{"execution":{"iopub.status.busy":"2023-05-11T07:54:07.994226Z","iopub.execute_input":"2023-05-11T07:54:07.994647Z","iopub.status.idle":"2023-05-11T07:54:08.736775Z","shell.execute_reply.started":"2023-05-11T07:54:07.994617Z","shell.execute_reply":"2023-05-11T07:54:08.735596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import librosa","metadata":{"execution":{"iopub.status.busy":"2023-05-10T07:28:40.611980Z","iopub.execute_input":"2023-05-10T07:28:40.612388Z","iopub.status.idle":"2023-05-10T07:28:41.723712Z","shell.execute_reply.started":"2023-05-10T07:28:40.612356Z","shell.execute_reply":"2023-05-10T07:28:41.722526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from os import listdir\nfrom os.path import isfile, join\nmypath = '/kaggle/input/birdclef-2023/train_audio/'\nonlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]","metadata":{"execution":{"iopub.status.busy":"2023-05-10T07:28:19.964647Z","iopub.execute_input":"2023-05-10T07:28:19.965243Z","iopub.status.idle":"2023-05-10T07:28:20.117886Z","shell.execute_reply.started":"2023-05-10T07:28:19.965199Z","shell.execute_reply":"2023-05-10T07:28:20.116952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"onlyfiles","metadata":{"execution":{"iopub.status.busy":"2023-05-10T07:28:28.245163Z","iopub.execute_input":"2023-05-10T07:28:28.245591Z","iopub.status.idle":"2023-05-10T07:28:28.252788Z","shell.execute_reply.started":"2023-05-10T07:28:28.245559Z","shell.execute_reply":"2023-05-10T07:28:28.251684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pitches, magnitudes = librosa.piptrack(y=y, sr=sr)\nprint(pitches)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from os import walk\n\nfilenames =      ","metadata":{"execution":{"iopub.status.busy":"2023-05-10T07:44:34.584381Z","iopub.execute_input":"2023-05-10T07:44:34.584770Z","iopub.status.idle":"2023-05-10T07:44:34.591821Z","shell.execute_reply.started":"2023-05-10T07:44:34.584742Z","shell.execute_reply":"2023-05-10T07:44:34.590745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filenames","metadata":{"execution":{"iopub.status.busy":"2023-05-10T07:44:46.754404Z","iopub.execute_input":"2023-05-10T07:44:46.754787Z","iopub.status.idle":"2023-05-10T07:44:46.761537Z","shell.execute_reply.started":"2023-05-10T07:44:46.754759Z","shell.execute_reply":"2023-05-10T07:44:46.760584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nfiles = [filename for filenames in os.path.join('/kaggle/input', filename)]\nprint(files)","metadata":{"execution":{"iopub.status.busy":"2023-05-10T07:44:52.339642Z","iopub.execute_input":"2023-05-10T07:44:52.340080Z","iopub.status.idle":"2023-05-10T07:44:52.346902Z","shell.execute_reply.started":"2023-05-10T07:44:52.340047Z","shell.execute_reply":"2023-05-10T07:44:52.345546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = os.walk('/kaggle/input/birdclef-2023/train_audio/')","metadata":{"execution":{"iopub.status.busy":"2023-05-10T07:29:42.049145Z","iopub.execute_input":"2023-05-10T07:29:42.049656Z","iopub.status.idle":"2023-05-10T07:29:42.056138Z","shell.execute_reply.started":"2023-05-10T07:29:42.049624Z","shell.execute_reply":"2023-05-10T07:29:42.054418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nf = []\nfor (dirpath, dirnames, filenames) in walk('/kaggle/input/birdclef-2023/'):\n    f.extend(filenames)\n    break","metadata":{"execution":{"iopub.status.busy":"2023-05-10T07:41:41.318972Z","iopub.execute_input":"2023-05-10T07:41:41.319374Z","iopub.status.idle":"2023-05-10T07:41:41.325922Z","shell.execute_reply.started":"2023-05-10T07:41:41.319342Z","shell.execute_reply":"2023-05-10T07:41:41.324529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f","metadata":{"execution":{"iopub.status.busy":"2023-05-10T07:42:18.817231Z","iopub.execute_input":"2023-05-10T07:42:18.817615Z","iopub.status.idle":"2023-05-10T07:42:18.825255Z","shell.execute_reply.started":"2023-05-10T07:42:18.817587Z","shell.execute_reply":"2023-05-10T07:42:18.823916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in f:\n    ","metadata":{"execution":{"iopub.status.busy":"2023-05-11T08:13:14.992464Z","iopub.execute_input":"2023-05-11T08:13:14.992933Z","iopub.status.idle":"2023-05-11T08:13:15.000293Z","shell.execute_reply.started":"2023-05-11T08:13:14.992887Z","shell.execute_reply":"2023-05-11T08:13:14.998574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}