Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #10

Open
wants to merge 181 commits into
base: canonical
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
f3eaccc
Initial Home page
DavidGoedicke Jul 10, 2019
757041d
Updated Home (markdown)
DavidGoedicke Jul 10, 2019
1816c99
Created 0_SetUp.MD (markdown)
DavidGoedicke Jul 10, 2019
31c3b31
instructions ud
DavidGoedicke Jul 14, 2019
5497b53
Updated Home (markdown)
DavidGoedicke Jul 14, 2019
90254e6
inst. ud
DavidGoedicke Jul 14, 2019
d7a4119
Merge branch 'master' of https://github.com/DavidGoedicke/RealtimeAud…
DavidGoedicke Jul 14, 2019
b4bd2c1
Updated Information flow, and the underlying idea (markdown)
DavidGoedicke Jul 14, 2019
753d335
inst. ud
DavidGoedicke Jul 14, 2019
6191b72
inst. ud
DavidGoedicke Jul 14, 2019
3a8f7b9
inst. ud
DavidGoedicke Jul 14, 2019
83b788a
ud
DavidGoedicke Jul 17, 2019
4a9a3f5
Created Training a network (markdown)
DavidGoedicke Jul 29, 2019
8dc7caa
Updated Home (markdown)
wendyju Aug 1, 2019
7a76977
Updated Home (markdown)
wendyju Aug 1, 2019
d967e80
Updated Home (markdown)
wendyju Aug 1, 2019
9389ca3
Updated Home (markdown)
wendyju Aug 1, 2019
a271d6b
Created Lab 0. Installing Software, libraries and downloading dataset…
wendyju Aug 1, 2019
0e7c20c
Initial Home page
wendyju Aug 1, 2019
811b607
Updated Real time Audio Classification for Musicians (markdown)
wendyju Aug 1, 2019
78ce583
Updated Lab 0. Installing Software, libraries and downloading dataset…
wendyju Aug 1, 2019
a89b40b
Updated Lab 0. Setting up (markdown)
wendyju Aug 1, 2019
a029fd0
Destroyed Real time Audio Classification for Musicians (markdown)
wendyju Aug 1, 2019
dd40d7a
Updated Home (markdown)
wendyju Aug 1, 2019
cf343ee
Updated Home (markdown)
wendyju Aug 1, 2019
364dca1
Updated Home (markdown)
wendyju Aug 1, 2019
3d54686
Updated Information flow and the underlying idea (markdown)
wendyju Aug 1, 2019
32da432
Updated Organizing Data for Learning (markdown)
wendyju Aug 1, 2019
38fa80d
Updated Home (markdown)
wendyju Aug 1, 2019
006a6ed
Updated Home (markdown)
wendyju Aug 1, 2019
a2a2f39
Updated Lab 1. Organizing Data for Learning (markdown)
wendyju Aug 1, 2019
f1be6f2
Created Lab 2. Pictures of Sounds (markdown)
wendyju Aug 1, 2019
e72ede6
Updated Home (markdown)
wendyju Aug 1, 2019
c1aab3a
Updated Lab 0. Setting up (markdown)
wendyju Aug 1, 2019
4ca45f0
Updated Home (markdown)
wendyju Aug 1, 2019
cb6c7aa
Updated Home (markdown)
wendyju Aug 2, 2019
18dfc37
Updated Home (markdown)
wendyju Aug 2, 2019
bab6ebb
Updated Home (markdown)
wendyju Aug 2, 2019
fe0257a
Updated Home (markdown)
wendyju Aug 2, 2019
0c19642
updates from the flight
DavidGoedicke Aug 4, 2019
2c3fe2d
Updated Lab 0. Setting up (markdown)
DavidGoedicke Aug 4, 2019
0cd3602
Updated Home (markdown)
DavidGoedicke Aug 4, 2019
bc1b69d
ud
DavidGoedicke Aug 4, 2019
5f6c31c
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 4, 2019
0ee28b2
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
5a1ba3b
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
ff7a680
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
989a931
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
05a672b
image upload
DavidGoedicke Aug 5, 2019
d62b1fe
Merge branch 'master' of https://github.com/DavidGoedicke/RealtimeAud…
DavidGoedicke Aug 5, 2019
62057b4
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
8acff44
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
18e387a
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
0447351
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
f37104b
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
3dbe0a2
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
8c7d779
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
7e54e01
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
01183f6
Created Details about the TrainingResNet Notebook (markdown)
DavidGoedicke Aug 5, 2019
18e4a67
image upload
DavidGoedicke Aug 5, 2019
c290500
Merge branch 'master' of https://github.com/DavidGoedicke/RealtimeAud…
DavidGoedicke Aug 5, 2019
ff70637
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
8faa5f2
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
9646e03
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
466d6e9
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
5a41ade
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
f320ad7
Updated Lab 0. Setting up (markdown)
DavidGoedicke Aug 5, 2019
d941666
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
e20cac3
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
b862238
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
113780f
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
5b8383e
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
a3d7b8a
Updated Lab 0. Setting up (markdown)
DavidGoedicke Aug 5, 2019
6477a5c
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
b7bdbba
Updated Lab 0. Setting up (markdown)
DavidGoedicke Aug 5, 2019
0c2a158
Updated Lab 0. Setting up (markdown)
DavidGoedicke Aug 5, 2019
8481b7a
Updated Lab 0. Setting up (markdown)
DavidGoedicke Aug 5, 2019
80f2177
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
8aaa91a
Updated Lab 0. Setting up (markdown)
DavidGoedicke Aug 5, 2019
56bd969
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
6ce7d64
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
e4f2288
Updated Lab 0. Setting up (markdown)
DavidGoedicke Aug 5, 2019
0a51756
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
b433d3e
Updated Lab 0. Setting up (markdown)
wendyju Aug 5, 2019
1f548a3
Created _Sidebar (markdown)
wendyju Aug 5, 2019
059f0f1
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
d8619fa
Updated Lab 2. Pictures of Sounds (markdown)
wendyju Aug 5, 2019
8db3252
Updated Lab 1. Organizing Data for Learning (markdown)
wendyju Aug 5, 2019
8555d64
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
0308660
Updated Lab 0. Setting up (markdown)
DavidGoedicke Aug 5, 2019
81f236a
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
57c6a8f
Updated Home (markdown)
wendyju Aug 5, 2019
4a72f81
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
2260a6d
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
ce97484
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
b7bfe22
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
2b1cf85
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
737f381
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
1d01d56
Updated Lab 0. Setting up (markdown)
wendyju Aug 5, 2019
51bc736
Updated Lab 0. Setting up (markdown)
wendyju Aug 5, 2019
8e1b0aa
Updated Lab 0. Setting up (markdown)
wendyju Aug 5, 2019
35a4f53
Updated Lab 0. Setting up (markdown)
DavidGoedicke Aug 5, 2019
f46efc6
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
cc0d98c
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
cd856c0
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
5a950c3
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
9d1d78b
Updated Lab 1. Cats and Dogs binary classification (markdown)
DavidGoedicke Aug 5, 2019
5c6404a
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
9464fc7
Updated old_ignore (markdown)
wendyju Aug 5, 2019
c7d7d63
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
c2ec274
Created notes from readme.md file for David (markdown)
wendyju Aug 5, 2019
43c365f
Created Sharing your results (markdown)
DavidGoedicke Aug 5, 2019
fa15466
Updated Sharing your results (markdown)
wendyju Aug 5, 2019
4ce28e3
Updated Sharing your results (markdown)
wendyju Aug 5, 2019
b25a3ea
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 5, 2019
98e556a
Updated Sharing your results (markdown)
wendyju Aug 5, 2019
9c8a278
ud image
DavidGoedicke Aug 5, 2019
0e6f2b7
Updated Sharing your results (markdown)
wendyju Aug 5, 2019
b84ac5c
Updated Converting CSV datasets into folders (markdown)
wendyju Aug 6, 2019
3942265
Updated Home (markdown)
wendyju Aug 6, 2019
8111106
Updated Home (markdown)
wendyju Aug 6, 2019
124be58
Created Lab 2. Making the Stanford Sounds Dataset (markdown)
wendyju Aug 6, 2019
9fe7b21
Created Making audio dataset from a video dataset (markdown)
wendyju Aug 6, 2019
0f12ca4
Updated Lab 1. Cats and Dogs binary classification (markdown)
wendyju Aug 6, 2019
0e60697
Updated Lab 2. Making the Stanford Sounds Dataset (markdown)
wendyju Aug 6, 2019
45ae93d
Destroyed Lab 2. Making Datasets (markdown)
wendyju Aug 6, 2019
a9fe110
Updated _Sidebar (markdown)
wendyju Aug 6, 2019
7f60af2
Updated Home (markdown)
wendyju Aug 6, 2019
06abd01
Updated Lab 2. Making the Stanford Sounds Dataset (markdown)
wendyju Aug 6, 2019
a8f395b
Updated Lab 2. Making the Stanford Sounds Dataset (markdown)
wendyju Aug 6, 2019
057efd1
Updated Lab 2. Making the Stanford Sounds Dataset (markdown)
wendyju Aug 6, 2019
9022416
Updated Lab 2. Making the Stanford Sounds Dataset (markdown)
wendyju Aug 6, 2019
ff52cef
Updated Lab 2. Making the Stanford Sounds Dataset (markdown)
DavidGoedicke Aug 6, 2019
cf9470f
new file: Day1bBitterLesson.pdf
wendyju Aug 6, 2019
17d2433
lecture slides
DavidGoedicke Aug 6, 2019
f3b21ad
Created Cheat sheets for Python, Jupiter, etc. (markdown)
wendyju Aug 6, 2019
daf4fba
Updated Cheat sheets for Python, Jupiter, etc. (markdown)
wendyju Aug 6, 2019
ba0cd76
Updated _Sidebar (markdown)
wendyju Aug 6, 2019
941b10f
Updated Cheat sheets for Python, Jupiter, etc. (markdown)
wendyju Aug 6, 2019
fc7c765
Updated _Sidebar (markdown)
wendyju Aug 6, 2019
375da61
adding model
Aug 6, 2019
f1141d4
moving to models folder
Aug 6, 2019
ea06f91
Merge pull request #3 from skresearcher/dev
skresearcher Aug 6, 2019
e0fb36d
adding model
Aug 6, 2019
3bf5a63
Merge pull request #4 from skresearcher/dev
skresearcher Aug 6, 2019
43e92e8
minor bug fix
DavidGoedicke Aug 6, 2019
4142864
adding chopin style recognition model
wayne-chen Aug 6, 2019
7b3f727
Merge branch 'contributed' of https://github.com/FAR-Lab/RealtimeAudi…
wayne-chen Aug 6, 2019
90f7104
Revert "minor bug fix"
wayne-chen Aug 6, 2019
196e0dd
Merge pull request #5 from wayne-chen/addChopinStyleModel
wayne-chen Aug 6, 2019
11ebad6
adding model to commit
rwixen Aug 6, 2019
6b47bb4
Merge pull request #6 from rwixen/addModel
rwixen Aug 6, 2019
26057dc
new file: Day2bUrbanSoundsDataset.pdf
wendyju Aug 6, 2019
3dd8884
Merge branch 'master' of https://github.com/FAR-Lab/RealtimeAudioClas…
wendyju Aug 6, 2019
f4bc857
adding model
markhanslip Aug 6, 2019
375a989
Merge pull request #7 from markhanslip/addModel
markhanslip Aug 6, 2019
b09fe6a
Merge branch 'master' of https://github.com/FAR-Lab/RealtimeAudioClas…
wayne-chen Aug 7, 2019
022f6dd
Merge pull request #8 from FAR-Lab/canonical
wayne-chen Aug 7, 2019
5e41163
Merge pull request #9 from FAR-Lab/canonical
wayne-chen Aug 7, 2019
6b2ed4e
modified: 01_Spectrum Generation/GeneratingSpectrums2.ipynb
wendyju Aug 7, 2019
b43c011
Delete .DS_Store
wayne-chen Aug 7, 2019
8a77cd8
removing extraneous files
wayne-chen Aug 7, 2019
119c126
removing extraneous folders
wayne-chen Aug 7, 2019
87afc5f
new file: 05_Interaction/Interaction.ipynb
wendyju Aug 8, 2019
8414b0d
modified: Interaction.ipynb
wendyju Aug 8, 2019
4dae9ad
modified: Interaction.ipynb
wendyju Aug 8, 2019
a48fed5
modified: GeneratingSpectrums2.ipynb
wendyju Aug 8, 2019
1c89fac
modified: ../03_Running/ResNetInferenceInteractive.ipynb
wendyju Aug 8, 2019
1259b7c
new file: Musical_Interaction.ipynb
wendyju Aug 8, 2019
9811fa1
modified: Interaction.ipynb
wendyju Aug 8, 2019
b3e05ad
deleted: Interaction.html
wendyju Aug 8, 2019
4b50cdb
ud inference
DavidGoedicke Aug 8, 2019
ff22391
Merge branch 'master' of https://github.com/FAR-Lab/RealtimeAudioClas…
DavidGoedicke Aug 8, 2019
41dd811
Added full NN output
DavidGoedicke Aug 8, 2019
824b37e
deleted: GeneratingSpectrums2.ipynb
wendyju Aug 8, 2019
4096c8e
modified: Musical_Interaction.ipynb
wendyju Aug 8, 2019
f17d7ef
modified: Interaction_osc.ipynb
wendyju Aug 8, 2019
ae2fb60
modified: Interaction.ipynb
wendyju Aug 8, 2019
d36a23d
removing unnecessary file.
wayne-chen Aug 22, 2019
6044d84
late ud
DavidGoedicke Mar 24, 2020
b3bd000
new file: 2020day1NN.pdf
wendyju Aug 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 142 additions & 11 deletions 01_Spectrum Generation/GeneratingSpectrums.ipynb

Large diffs are not rendered by default.

2,116 changes: 0 additions & 2,116 deletions 01_Spectrum Generation/GeneratingSpectrums2.ipynb

This file was deleted.

310 changes: 0 additions & 310 deletions 01_Spectrum Generation/SpectrumsSettingsTool2.ipynb

This file was deleted.

Binary file added 01_Spectrum Generation/lastSpect.pickle
Binary file not shown.
1,726 changes: 1,726 additions & 0 deletions 02_Training/TrainingResNet2.ipynb

Large diffs are not rendered by default.

148 changes: 141 additions & 7 deletions 03_Running/ResNetInference.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions 03_Running/ResNetInferenceInteractive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python3.7 (ImageCalc)",
"display_name": "Python 3",
"language": "python",
"name": "imagecalc"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand Down
172 changes: 172 additions & 0 deletions 03_Running/ResNetInferenceV2.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load library"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from importlib import reload\n",
"import RunningResNetLibrary as RTA\n",
"from IPython.display import clear_output, display\n",
"import os\n",
"import subprocess"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Run Program"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This involves creating an audio buffer that we continually update with information from the microphone, then creating an image and running it through the neural net. This happens as fast as possible over and over again."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def DoStuff(Input,Probablity):\n",
" clear_output(wait=True)\n",
" print(Input,Probablity)\n",
" return;\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def FullOut(predicted,prob,classes):\n",
" clear_output(wait=True)\n",
" print(classes[predicted[0,0]], prob[0,0])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Dogs tensor(0.5714, grad_fn=<SelectBackward>)\n",
"Stopping!\n",
"Stopped and Done!\n"
]
}
],
"source": [
"RTA.RunTheSystem(TargetTime=20,ModelPath=\"../models/CatDogResNetNew.pth\",CallBackFunction=DoStuff,CallBack2=FullOut)"
]
},
{
"cell_type": "code",
"execution_count": 104,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<module 'RunningResNetLibrary' from '/Users/d.goedicke/Desktop/CoctailParty/RealtimeAudioClassification/03_Running/RunningResNetLibrary.py'>"
]
},
"execution_count": 104,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reload(RTA)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loading all relevant data.\n"
]
},
{
"ename": "KeyError",
"evalue": "'resolution'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-10-7a9696bc83e3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mRTA\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mRunTheSystem\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mTargetTime\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m15\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mModelPath\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"../models/UrbanSoundsClean\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mCallBackFunction\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mDoStuff\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mCallBack2\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mFullOut\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m~/GitRepos/RealtimeAudioClassification/03_Running/RunningResNetLibrary.py\u001b[0m in \u001b[0;36mRunTheSystem\u001b[0;34m(TargetTime, ModelPath, CallBackFunction, CallBack2)\u001b[0m\n\u001b[1;32m 160\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mRunTheSystem\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mTargetTime\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m30\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mModelPath\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"../models/UrbanResNet.pth\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mCallBackFunction\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mDoStuff\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mCallBack2\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 161\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Loading all relevant data.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 162\u001b[0;31m \u001b[0mStartAudio\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mModelPath\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mModelPath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 163\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Starting Running\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 164\u001b[0m \u001b[0mt0\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/GitRepos/RealtimeAudioClassification/03_Running/RunningResNetLibrary.py\u001b[0m in \u001b[0;36mStartAudio\u001b[0;34m(ModelPath)\u001b[0m\n\u001b[1;32m 66\u001b[0m \u001b[0;32mglobal\u001b[0m \u001b[0mstream\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 67\u001b[0m \u001b[0mModelData\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mModelPath\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mmap_location\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'cpu'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 68\u001b[0;31m \u001b[0mInput_Resolution\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mModelData\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'resolution'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 69\u001b[0m \u001b[0mSpectrumVariables\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mModelData\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'SpectrumVariables'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 70\u001b[0m \u001b[0mclasses\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mModelData\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'classes'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mKeyError\u001b[0m: 'resolution'"
]
}
],
"source": [
"RTA.RunTheSystem(TargetTime=15,ModelPath=\"../models/UrbanSoundsClean\",CallBackFunction=DoStuff,CallBack2=FullOut)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python3.6 workshop",
"language": "python",
"name": "workshop"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
172 changes: 172 additions & 0 deletions 03_Running/RunningResNetLibrary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/env python
# coding: utf-8

## Load library
import pyaudio
import librosa
import numpy as np
from numpy_ringbuffer import RingBuffer
import matplotlib.pyplot as plt
import pyaudio
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import datasets, transforms, models

import torchvision
import time
from numpy_ringbuffer import RingBuffer
from torch.autograd import Variable
from threading import Thread
from time import sleep
import cv2
import time
import pickle
from IPython.display import clear_output, display
#import rtmidi
from IPython.display import Image
import os


model=None
classes=None
ringBuffer=None
Input_Resolution=None
SamplingRate =48000
SpectrumVariables=None
ringBuffer = RingBuffer(28672*2)
pa = None
stream = None
RunningAverageSlow={}
RunningAverageFast={}
timer = 0


def SmoothingFunction(PredictedClassName, Probablity,CallBackFunction):
global RunningAverageSlow
global RunningAverageFast
if(not PredictedClassName in RunningAverageSlow):
RunningAverageSlow[PredictedClassName]=0
if(not PredictedClassName in RunningAverageFast):
RunningAverageFast[PredictedClassName]=0

RunningAverageFast[PredictedClassName]=RunningAverageFast[PredictedClassName]*0.7+0.3*Probablity
RunningAverageSlow[PredictedClassName]=RunningAverageSlow[PredictedClassName]*0.9+0.1*Probablity
if(RunningAverageFast[PredictedClassName]-RunningAverageSlow[PredictedClassName])>0.25 and Probablity>2.0:
CallBackFunction(PredictedClassName,Probablity)
return
#print(RunningAverageSlow)
CallBackFunction('None',Probablity)

def StartAudio(ModelPath="../models/CatDogResNet.pth"):
global model
global SpectrumVariables
global classes
global Input_Resolution
global stream
ModelData = torch.load(ModelPath,map_location='cpu')
Input_Resolution = ModelData['resolution']
SpectrumVariables = ModelData['SpectrumVariables']
classes = ModelData['classes']
foundAModel=False
if ModelData['modelType']=="resnet18":
model = models.resnet18()
model.fc = nn.Linear(512, len(classes))
foundAModel=True
if not foundAModel:
print("Could not find requested Model. Please provide a network structure for model:",ModelData['modelType'])
exit()
model.load_state_dict (ModelData['model'])
model.cpu()
model.eval()
print("Opening Audio Channel")
cv2.startWindowThread()
pa = pyaudio.PyAudio()
stream = pa.open(format=pyaudio.paFloat32,
channels=1,
rate=SamplingRate,
output=False,
input=True,
stream_callback=callback)
stream.start_stream()

def callback(in_data, frame_count, time_info, flag):
audio_data = np.frombuffer(in_data, dtype=np.float32)
ringBuffer.extend(audio_data)
return None, pyaudio.paContinue

def infere_Class_Type(CallBack,CallBack2):
if(not ringBuffer.is_full):
return
N_FFT=SpectrumVariables["N_FFT"]
HOP_LENGTH= SpectrumVariables["HOP_LENGTH"]
FMIN=SpectrumVariables["FMIN"]
FMAX=SpectrumVariables["FMAX"]
N_MELS=SpectrumVariables["N_MELS"]
POWER=SpectrumVariables["POWER"]
mel_spec_power = librosa.feature.melspectrogram(np.array(ringBuffer), sr=SamplingRate, n_fft=N_FFT,
hop_length=HOP_LENGTH,
n_mels=N_MELS, power=POWER,
fmin=FMIN,fmax=FMAX)
mel_spec_db = librosa.power_to_db(mel_spec_power, ref=np.max)
image=mel_spec_db[0:Input_Resolution,0:Input_Resolution]
image = mel_spec_db; # convert to float
image -= image.min() # ensure the minimal value is 0.0
image /= image.max() # maximum value in image is now 1.0
image*=256
img = image.astype(np.uint8)
colerPic = cv2.applyColorMap(img, cv2.COLORMAP_BONE)
if(int(np.floor(colerPic.shape[1]/Input_Resolution))<0):
return 0
OutputImage = cv2.resize(colerPic[:,-Input_Resolution:,:],(Input_Resolution,Input_Resolution))
if(OutputImage.shape[1]<Input_Resolution):
return 0
imagesTensor = transforms.Compose(
[transforms.ToPILImage(),
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])(OutputImage)
imagesTensor = Variable(imagesTensor, requires_grad=False)
testImages = imagesTensor.unsqueeze(0)
outputs = model(testImages)
outputs = F.softmax(outputs)
prob, predicted = torch.topk(outputs,len(classes))
#print(predicted[:2],prob[:2])
if(not CallBack2==None):
CallBack2(predicted,prob,classes)
else:
predicted=predicted[0].numpy()
prob=prob[0].detach().numpy()
SmoothingFunction(classes[predicted[0]],prob[0],CallBack)

def StopAudio():
global pa
global stream
time.sleep(1)
stream.close()
cv2.destroyAllWindows()

def DoStuff(Input,Probablity):
#print("I heard a "+str(Input)+'with'+str(Probablity))
global timer
clear_output(wait=True)
print(Input,timer)
if(timer>0):
timer-=1
if(timer<=1):
os.system("say I think I heard a "+str(Input))
print("I heard a "+str(Input))
timer=50

def RunTheSystem(TargetTime=30,ModelPath = "../models/UrbanResNet.pth",CallBackFunction=DoStuff,CallBack2=None):
print("Loading all relevant data.")
StartAudio(ModelPath=ModelPath)
print("Starting Running")
t0 = time.time()
while stream.is_active():
infere_Class_Type(CallBackFunction,CallBack2)
if (TargetTime>0 )and ((time.time()-t0)>=TargetTime):
break
print("Stopping!")
StopAudio()
print("Stopped and Done!")

Binary file added 03_Running/cat2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 03_Running/dog2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 04_ProcessingData/Sampleaudio.mp3
Binary file not shown.
2 changes: 1 addition & 1 deletion 04_ProcessingData/Transforming Datasets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.1"
}
},
"nbformat": 4,
Expand Down
Loading