Problem importing AudioImpulseRunner

I trained a model to detect keywords.
Now I am trying to deplyo the eim fie in my Raspberry py.
At first I went for the example code.
In the script of classify.py in Eamples folder, when it tries to execute

from edge_impulse_linux.audio import AudioImpulseRunner

This Error Occurs

Traceback (most recent call last):
  File "/home/pi/linux-sdk-python/examples/audio/classify.py", line 5, in <module>
    from edge_impulse_linux.audio import AudioImpulseRunner
  File "/home/pi/.local/lib/python3.9/site-packages/edge_impulse_linux/_init_.py", line 3, in <module>
    from edge_impulse_linux import image
  File "/home/pi/.local/lib/python3.9/site-packages/edge_impulse_linux/image.py", line 4, in <module>
    import cv2
  File "/home/pi/.local/lib/python3.9/site-packages/cv2/_init_.py", line 5, in <module>
    from .cv2 import *
ImportError: libIlmImf-2_5.so.25: cannot open shared object file: No such file or directory

What should be the solution?

Hi @Hasib,

This seems related to OpenCV. Can you run the following command to check which version you have installed?

pip list | grep opencv

Aurelien

This is version 4.5.1.48

Yes. I am really confused about why the audio classifier is using openCV. But for the time being I am really trying hard to run my eim file to run on my raspberry pi with the python SDK. this error is killing me :frowning:

Do you have any suggestion now?

This is strange, maybe reinstalling opencv would fix it.
In the meantime, you can edit the file /home/pi/.local/lib/python3.9/site-packages/edge_impulse_linux/_init_.py

and comment the line:

#from edge_impulse_linux import image

Aurelien

1 Like

Thanks a lot Aurel.
This dismissed the error.

And then the python script “classify.pi” ran successfully. It just ran and ended. nothing happened.

I am really confused how this is hoing to use my .eim file that was downloaded as my ML model that can extract audio feature. And I found nowhere to address mi mic to the script. And so does the script “audio.py” in the /linux-sdk-python/edge_impulse_linux directory.

Can you please give a short guideline on how I can access my mic, record audio and find whether the keywords are being detected with a python script?? The reference links on the edge impulse making me move round and round within a sum of pages that says similar things over and again.

You need to provide the .eim file as a parameter:
python classify.py modelfile.eim

The script will then detect the different microphones and you’ll just need to select the one you want to use.

Aurelien

1 Like

It is great!
You are such a genius !

Btw, Currently I got 2 USB mics connected with my RPi as you can see in the ScreenShot.

It is considering both of them as non compatible. :frowning:

.
What could be the case do you think?

I general scenario, both of those mics are functioning.

Again, thanks in advance :smiley:
image

Hi @Hasib,

Does it work using edge-impulse-linux-runner command?

Aurelien

Yes it does.
When I get connected to the edge impulse account over the internet and run the classifier from it’s cloud, it works fine with a very good accuracy.

But now, when I am trying to use the .eim file offline, it says the the audio device is not compatible. Though it detects them successfully.

The Python SDK uses PyAudio and it seems the audio format provided by your mics is not supported.

To investigate more, could you provide me your project ID used to generate the .eim file?

Also, if you can edit the /home/pi/.local/lib/python3.9/site-packages/edge_impulse_linux/audio.py file, and add the following print statement in the listAvailableDevices(self) function:

for i in range (0,numdevices):
            print(self.interface.get_device_info_by_index(i)) # <- add this line
            if self.interface.get_device_info_by_host_api_device_index(0,i).get('maxInputChannels')>0:
                input_devices.append((i, self.interface.get_device_info_by_host_api_device_index(0,i).get('name')))

From there we can check the parameters of your modelfile with PyAudio capabilities.

Aurelien

Of course, why not!
My project ID is 72779.
Here I used google speech command dataset to train few keyword with almost all the default settings.

And, I will let you know after I add those lines. A very big download is currently happening. I will come up with that result asap.

So here is the result after I added the print line.

I hope you are still there to help :smiley:
I also checked the edge-impulse-linux-runner command again and it works fine with both of my mics.

Hi @Hasib,

Your project works fine with my Rasp Pi and Mic. For some reason the pyaudio library doesn’t support your mic. We can dig a bit deeper to see if this is link to the sampling rate or bit width, here’s what you can change in the same audio.py file (checkDeviceModelCompatiblity function):

        try:
            supported = self.interface.is_format_supported(self.rate,
                        input_device=device_id,
                        input_channels=self.channels,
                        input_format=pyaudio.paInt16)
        except Exception as e: # <- change this line
            print(e) # <- add the print
            supported = False

This should give you a more detailed error with a PortAudio error. You can also remove the print statement from my last message.

Sorry for all the back and forth debug, it’s a big harder without access to the hardware :slight_smile:.

Aurelien