annotate notebooks/test_music_segments.ipynb @ 42:90f8a2ea6f6f branch-tests

notebook results and load_features minor edits
author mpanteli <m.x.panteli@gmail.com>
date Fri, 15 Sep 2017 16:17:17 +0100
parents e6e10013e11c
children b0e194bfb71d
rev   line source
m@6 1 {
m@6 2 "cells": [
m@6 3 {
m@6 4 "cell_type": "code",
m@6 5 "execution_count": 1,
m@6 6 "metadata": {
m@6 7 "collapsed": true
m@6 8 },
m@6 9 "outputs": [],
m@6 10 "source": [
m@6 11 "import numpy as np\n",
m@6 12 "import pickle"
m@6 13 ]
m@6 14 },
m@6 15 {
m@6 16 "cell_type": "code",
m@6 17 "execution_count": 2,
m@6 18 "metadata": {
m@6 19 "collapsed": true
m@6 20 },
m@6 21 "outputs": [],
m@6 22 "source": [
m@7 23 "filenames = ['/import/c4dm-04/mariap/train_data_melodia_8.pickle',\n",
m@6 24 " '/import/c4dm-04/mariap/val_data_melodia_8.pickle', \n",
m@6 25 " '/import/c4dm-04/mariap/test_data_melodia_8.pickle']"
m@6 26 ]
m@6 27 },
m@6 28 {
m@6 29 "cell_type": "code",
m@7 30 "execution_count": 13,
Maria@40 31 "metadata": {
Maria@40 32 "collapsed": true
Maria@40 33 },
m@6 34 "outputs": [],
m@6 35 "source": [
m@6 36 "all_Yaudio = []\n",
m@7 37 "all_Y = []\n",
m@6 38 "for filename in filenames:\n",
m@7 39 " _, Y, Yaudio = pickle.load(open(filename, 'rb'))\n",
m@6 40 " all_Yaudio.append(Yaudio)\n",
m@7 41 " all_Y.append(Y)\n",
m@7 42 "all_Yaudio = np.concatenate(all_Yaudio)\n",
m@7 43 "all_Y = np.concatenate(all_Y)"
m@6 44 ]
m@6 45 },
m@6 46 {
m@6 47 "cell_type": "code",
m@7 48 "execution_count": 5,
Maria@40 49 "metadata": {
Maria@40 50 "collapsed": true
Maria@40 51 },
m@7 52 "outputs": [],
m@6 53 "source": [
m@6 54 "uniq_audio, uniq_counts = np.unique(all_Yaudio, return_counts=True)"
m@6 55 ]
m@6 56 },
m@6 57 {
m@6 58 "cell_type": "markdown",
m@6 59 "metadata": {},
m@6 60 "source": [
m@6 61 "## Stats on audio files with very few music frames (after the speech/music discrimination)"
m@6 62 ]
m@6 63 },
m@6 64 {
m@6 65 "cell_type": "code",
m@7 66 "execution_count": 8,
m@42 67 "metadata": {},
m@6 68 "outputs": [
m@6 69 {
m@7 70 "name": "stdout",
m@7 71 "output_type": "stream",
m@7 72 "text": [
m@7 73 "63 files out of 8200 have less than 10 frames\n"
m@6 74 ]
m@6 75 }
m@6 76 ],
m@6 77 "source": [
m@6 78 "min_n_frames = 10\n",
m@7 79 "short_files_idx = np.where(uniq_counts<min_n_frames)[0]\n",
m@7 80 "print '%d files out of %d have less than %d frames' % (len(short_files_idx), len(uniq_counts), min_n_frames)"
m@7 81 ]
m@7 82 },
m@7 83 {
m@7 84 "cell_type": "markdown",
m@7 85 "metadata": {},
m@7 86 "source": [
m@7 87 "Countries for tracks with less than 10 frames"
m@7 88 ]
m@7 89 },
m@7 90 {
m@7 91 "cell_type": "code",
m@7 92 "execution_count": 17,
m@42 93 "metadata": {},
m@7 94 "outputs": [
m@7 95 {
m@7 96 "name": "stdout",
m@7 97 "output_type": "stream",
m@7 98 "text": [
m@7 99 "{'Italy': 1, 'Peru': 1, 'Solomon Islands': 2, 'France': 2, 'Ethiopia': 1, 'Somalia': 1, 'Ireland': 1, 'Swaziland': 1, 'Argentina': 1, 'Norway': 1, 'Nigeria': 1, 'Algeria': 1, 'Germany': 1, 'Puerto Rico': 1, 'Dominican Republic': 1, 'Poland': 3, 'Spain': 2, 'Netherlands': 1, 'Uganda': 4, 'Western Sahara': 5, 'Gambia': 2, 'Philippines': 2, 'Trinidad and Tobago': 1, 'Latvia': 1, 'South Sudan': 3, 'Mali': 1, 'Russia': 1, 'Romania': 1, 'Portugal': 1, 'South Africa': 3, 'Egypt': 1, 'Sierra Leone': 1, 'United Kingdom': 4, 'Lesotho': 1, 'Senegal': 2, 'Colombia': 2, 'Japan': 2, 'Nicaragua': 1, 'Botswana': 1}\n"
m@7 100 ]
m@7 101 }
m@7 102 ],
m@7 103 "source": [
m@7 104 "countries = np.array([all_Y[np.where(all_Yaudio==uniq_audio[audio_idx])[0][0]][0] for audio_idx in short_files_idx])\n",
m@7 105 "unique, counts = np.unique(countries, return_counts=True)\n",
m@7 106 "print dict(zip(unique, counts))"
m@6 107 ]
m@6 108 },
m@6 109 {
m@6 110 "cell_type": "markdown",
m@6 111 "metadata": {},
m@6 112 "source": [
m@6 113 "## Stats on average duration of the music segments for all tracks"
m@6 114 ]
m@6 115 },
m@6 116 {
m@6 117 "cell_type": "code",
m@7 118 "execution_count": 18,
m@42 119 "metadata": {},
m@6 120 "outputs": [
m@6 121 {
m@7 122 "name": "stdout",
m@7 123 "output_type": "stream",
m@7 124 "text": [
m@7 125 "mean 65.750000\n",
m@7 126 "median 44.000000\n",
m@7 127 "std 45.947865\n",
m@7 128 "mean duration 32.875000\n"
m@6 129 ]
m@6 130 }
m@6 131 ],
m@6 132 "source": [
m@6 133 "sr = 2.0 # with 8-second window and 0.5-second hop size the sampling rate is 2 about 2 samples per second\n",
m@6 134 "print 'mean %f' % np.mean(uniq_counts)\n",
m@6 135 "print 'median %f' % np.median(uniq_counts)\n",
m@6 136 "print 'std %f' % np.std(uniq_counts)\n",
m@6 137 "print 'mean duration %f' % (np.mean(uniq_counts) / sr)"
m@6 138 ]
m@6 139 },
m@6 140 {
m@6 141 "cell_type": "markdown",
m@6 142 "metadata": {},
m@6 143 "source": [
m@7 144 "## Stats on average duration of the music segments for the Smithsonian tracks"
m@7 145 ]
m@7 146 },
m@7 147 {
m@7 148 "cell_type": "code",
m@7 149 "execution_count": 23,
m@42 150 "metadata": {},
m@7 151 "outputs": [
m@7 152 {
m@7 153 "name": "stdout",
m@7 154 "output_type": "stream",
m@7 155 "text": [
m@7 156 "n tracks: 6132\n",
m@7 157 "mean 42.618885\n",
m@7 158 "median 44.000000\n",
m@7 159 "std 4.804534\n",
m@7 160 "mean duration 21.309442\n"
m@7 161 ]
m@7 162 }
m@7 163 ],
m@7 164 "source": [
m@7 165 "#British library tracks start with 'D:/Audio/...'\n",
m@7 166 "idx_SM_tracks = np.array([i for i in range(len(uniq_audio)) if len(uniq_audio[i].split('D:/'))==1])\n",
m@7 167 "sr = 2.0 # with 8-second window and 0.5-second hop size the sampling rate is 2 about 2 samples per second\n",
m@7 168 "print 'n tracks: %d' % len(idx_SM_tracks)\n",
m@7 169 "print 'mean %f' % np.mean(uniq_counts[idx_SM_tracks])\n",
m@7 170 "print 'median %f' % np.median(uniq_counts[idx_SM_tracks])\n",
m@7 171 "print 'std %f' % np.std(uniq_counts[idx_SM_tracks])\n",
m@7 172 "print 'mean duration %f' % (np.mean(uniq_counts[idx_SM_tracks]) / sr)"
m@7 173 ]
m@7 174 },
m@7 175 {
m@7 176 "cell_type": "markdown",
m@7 177 "metadata": {},
m@7 178 "source": [
m@6 179 "## Stats on average duration of the music segments for the British Library tracks"
m@6 180 ]
m@6 181 },
m@6 182 {
m@6 183 "cell_type": "code",
m@7 184 "execution_count": 22,
m@42 185 "metadata": {},
m@6 186 "outputs": [
m@6 187 {
m@7 188 "name": "stdout",
m@7 189 "output_type": "stream",
m@7 190 "text": [
m@7 191 "n tracks: 2068\n",
m@7 192 "mean 134.338008\n",
m@7 193 "median 163.000000\n",
m@7 194 "std 44.855790\n",
m@7 195 "mean duration 67.169004\n"
m@6 196 ]
m@6 197 }
m@6 198 ],
m@6 199 "source": [
m@6 200 "#British library tracks start with 'D:/Audio/...'\n",
m@6 201 "idx_BL_tracks = np.array([i for i in range(len(uniq_audio)) if len(uniq_audio[i].split('D:/'))>1])\n",
m@6 202 "sr = 2.0 # with 8-second window and 0.5-second hop size the sampling rate is 2 about 2 samples per second\n",
m@7 203 "print 'n tracks: %d' % len(idx_BL_tracks)\n",
m@6 204 "print 'mean %f' % np.mean(uniq_counts[idx_BL_tracks])\n",
m@6 205 "print 'median %f' % np.median(uniq_counts[idx_BL_tracks])\n",
m@6 206 "print 'std %f' % np.std(uniq_counts[idx_BL_tracks])\n",
m@6 207 "print 'mean duration %f' % (np.mean(uniq_counts[idx_BL_tracks]) / sr)"
m@6 208 ]
m@6 209 },
m@6 210 {
m@6 211 "cell_type": "code",
m@6 212 "execution_count": null,
m@6 213 "metadata": {
m@6 214 "collapsed": true
m@6 215 },
m@6 216 "outputs": [],
m@6 217 "source": []
m@6 218 }
m@6 219 ],
m@6 220 "metadata": {
m@6 221 "kernelspec": {
m@6 222 "display_name": "Python 2",
m@6 223 "language": "python",
m@6 224 "name": "python2"
m@6 225 },
m@6 226 "language_info": {
m@6 227 "codemirror_mode": {
m@6 228 "name": "ipython",
m@6 229 "version": 2
m@6 230 },
m@6 231 "file_extension": ".py",
m@6 232 "mimetype": "text/x-python",
m@6 233 "name": "python",
m@6 234 "nbconvert_exporter": "python",
m@6 235 "pygments_lexer": "ipython2",
m@42 236 "version": "2.7.12"
m@6 237 }
m@6 238 },
m@6 239 "nbformat": 4,
m@7 240 "nbformat_minor": 1
m@6 241 }