awjuliani / sound-cnn Goto Github PK
View Code? Open in Web Editor NEWA convolutional neural network that classifies sounds
A convolutional neural network that classifies sounds
Hello guys, im trying to run this project and i changed the operator / to // since im using python 3. I'm still having errors:
(pythonProject3) C:\Users\User\PycharmProjects\pythonProject3>python C:\Users\User\Desktop\adsp\train.py 240 44100 C:\Users\User\Desktop\audio\ 1000 1
Traceback (most recent call last):
File "C:\Users\User\Desktop\adsp\train.py", line 19, in
classes, trainX, trainYa, valX, valY, testX, testY = util.processAudio(bpm, samplingRate, mypath)
File "C:\Users\User\Desktop\adsp\utilities.py", line 26, in processAudio
audData = np.reshape(audData[1][:, 1][0:samples * ((seconds * samplingRate) // samples)],
ZeroDivisionError: integer division or modulo by zero
By using spectrogram, we can simply treat audio recognition as image recognition, so all the technologies used at image recognition can be used at audio recognition as well
This example uses the same samples as speech_commands, that is wave audio files of people saying ten different words('yes', 'no', 'up', 'down', 'left', 'right', 'on', 'off', 'stop', 'go') from Speech Commands dataset
First, transform the original audio files into spectrograms, we use the following python code to do the task:
import numpy as np from scipy.io import wavfile X_SIZE = 16000 IMG_SIZE = 128 def spectrogram(filepath): framerate, wav_data = wavfile.read(filepath) window_length = 512 window_shift = 121 if len(wav_data) > X_SIZE: wav_data = wav_data[:X_SIZE] X = np.zeros(X_SIZE).astype('float32') X[:len(wav_data)] += wav_data spec = np.zeros((IMG_SIZE, IMG_SIZE)).astype('float32') for i in range(IMG_SIZE): start = i * window_shift end = start + window_length sig = np.abs(np.fft.rfft(X[start:end] * np.hanning(window_length))) spec[:,i] = (sig[1:IMG_SIZE + 1])[::-1] spec = (spec-spec.min())/(spec.max()-spec.min()) spec = np.log10((spec * 100 + 0.01)) spec = (spec-spec.min())/(spec.max()-spec.min()) - 0.5 return spec
For example, the spectrogram for test.wav is:
To reduce the amount of computation, we limit the size of spectrogram to 128ร128, so the model can be defined as follow:
Run this model, you will get a test accuracy around 93%(while train accuracy is 98%) after 15 epochs
student@student-Vostro-3669:~/sound-cnn$ python train.py 240 44100 /home/student/traindata 1000 150
Traceback (most recent call last):
File "train.py", line 20, in
classes,trainX,trainY,valX,valY,testX,testY = util.processAudio(bpm,samplingRate,mypath)
File "/home/student/sound-cnn/utilities.py", line 29, in processAudio
Ys = np.concatenate(labelList)
ValueError: need at least one array to concatenate
Hi. First, I tested mono .wav files which resulted in an error.
Now I'm using stereo .wav files which results in another error.
stefan@stefan-quadcore ~/dev/sound-cnn-master $ ./doit.sh
Traceback (most recent call last):
File "train.py", line 20, in <module>
classes,trainX,trainYa,valX,valY,testX,testY = util.processAudio(bpm,samplingRate,mypath)
File "/home/stefan/dev/sound-cnn-master/utilities.py", line 24, in processAudio
audData = np.reshape(audData[1][:,1][0:samples*((seconds*samplingRate)/samples)],[samples,(seconds*samplingRate)/samples])
TypeError: slice indices must be integers or None or have an __index__ method
stefan@stefan-quadcore ~/dev/sound-cnn-master $ cat doit.sh
python3 train.py 240 44100 ../sounds-stereo/ 1000 100
Why does stuff not work in this world?
Cheers
How to use use this model to make new predictions using a new audio file ?
i've tried to reload the model.ckpt file but it keeps giving me errors ...
python train.py 240 44100 audio/ 1000 150
Traceback (most recent call last):
File "train.py", line 20, in
classes,trainX,trainYa,valX,valY,testX,testY = util.processAudio(bpm,samplingRate,mypath)
File "/home/fuquo/src/sound-cnn/utilities.py", line 22, in processAudio
seconds = audData[1][:,1].shape[0]/samplingRate
IndexError: too many indices for array
Could you setup a quick demo?
I cannot understand why any input file to be theorized as a new class and i am getting error on train.py:
'ValueError: Cannot feed value of shape (1, 2) for Tensor u'Placeholder_1:0', which has shape '(?, 4)'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.