1

We have programmed a device (consisting of a raspberry pi 3) to sit in a room, listen, and characterize the room based on an existing GMM. Our code works successfully until it throws an error around the 17th or 19th iteration. We have narrowed down to where in the code the problem is occurring, but we are unsure of why.

We are beginner programmers, so apologies for the weird formatting...this is all new to us.

Thanks in advance for any help or insight you can provide!

from sklearn import preprocessing
import python_speech_features as mfcc

def calculate_delta(array):
    """Calculate and returns the delta of given feature vector matrix"""

    rows,cols = array.shape
    deltas = np.zeros((rows,20))
    N = 2
    for i in range(rows):
        index = []
        j = 1
        while j <= N:
            if i-j < 0:
                first = 0
            else:
                first = i-j
            if i+j > rows -1:
                second = rows -1
            else:
                second = i+j
            index.append((second,first))
            j+=1
        deltas[i] = ( array[index[0][0]]-array[index[0][1]] + (2 * (array[index[1][0]]-array[index[1][1]])) ) / 10
    return deltas

def extract_features(audio,rate):

        try:
            """extract 20 dim mfcc features from an audio, performs CMS and combines 
            delta to make it 40 dim feature vector"""    

            # audio is audio signal from which to compute features -> should be n*1 array
            # rate is samplerate of the signal we are working with
            # 0.025 is the length of the analysis window in seconds (default is 25ms)
            # 0.01 is the step between successive windows in seconds (default is 10ms)
            # 20 is number of cepstrum to return (default is 13)
            # append energy is true if zeroth cepstral coefficient is replaced with log of total frame energy
            # mfcc() returns a numpy array of size (NUMFRAMES by numcep) containing features, each row holds 1 feature vector 
            # further possible parameters & their defaults can be found at python-speech-features.readthedocs.io/en/latest/
            mfcc_feat = mfcc.mfcc(audio,rate, 0.025, 0.01, 20, appendEnergy = True)

            # Scale all data onto one scale, eliminating sparsity & following same concept of Normalization & Standardization 
            mfcc_feat = preprocessing.scale(mfcc_feat)

            delta = calculate_delta(mfcc_feat)

            combined = np.hstack((mfcc_feat,delta))
            print("Features extracted")
            return combined
        except Exception as e:
            print(e)
            print("Extract features failed.")

We believe the problem occurs at this line:

 mfcc_feat = mfcc.mfcc(audio,rate, 0.025, 0.01, 20, appendEnergy = True

The error it gives us is:

Backend terminated (returncode: -9)

rkartunova
  • 13
  • 2

1 Answers1

0

returncode: -9 could mean signal 9 which means

SIGKILL. The SIGKILL signal is sent to a process to cause it to terminate immediately (kill). In contrast to SIGTERM and SIGINT, this signal cannot be caught or ignored, and the receiving process cannot perform any clean-up upon receiving this signal.

and that's probably why it's not being caught by the exception.

Manvir
  • 769
  • 1
  • 7
  • 15
  • Thank you for your quick response! Do you know why this wouldn't occur the first 16-17 times? Any suggestions on how we can fix/avoid the problem? – rkartunova Jul 31 '19 at 23:04
  • @rkartunova at the moment im not sure how to fix the error but an avenue to take would be this [one](https://stackoverflow.com/questions/40888164/c-program-crashes-with-exit-code-9-sigkill) – Manvir Jul 31 '19 at 23:09
  • @rkartunova is your program using too much memory? – Manvir Jul 31 '19 at 23:34
  • Yes, I think you're right. Maybe there are sleeping processes that are occuring because our program is only saving a png and txt file in each iteration. If this is the case, do you have any suggestions on how to prevent this sleep process from happening? – rkartunova Jul 31 '19 at 23:49
  • @rkartunova its really hard to suggest anything concrete because Im only a beginner but I would suggest you look at how much memory your program is utilizing and try to look more into SIGKILL. I would definitely look into memory issues do you know how to check how much memory a process is using? – Manvir Jul 31 '19 at 23:59
  • I think that's a great suggestion, and no I have no idea how to find that out. Do you know where I should look? – rkartunova Aug 01 '19 at 00:06
  • Go to menu => accessories => task manager and watch if the process uses a lot of memory when its running in the task manager – Manvir Aug 01 '19 at 00:17
  • SOLVED! Thank you for taking the time to look into the issue @Tyger. So originally our program was running in a computer lab on a school campus. We then ran it off a personal laptop and it is working perfectly fine now. There must be a limit on the school server that we were not aware of. – rkartunova Aug 01 '19 at 01:19
  • @rkartunova sounds good if you think my answer answered your question feel free to hit the check mark for answered – Manvir Aug 01 '19 at 01:20