Sklearn

Concerning processing components: filters, file load/save, visualizations, communication ...
Post Reply
mhadji05
Posts: 53
Joined: Tue Mar 16, 2021 9:37 am

Sklearn

Post by mhadji05 »

Hello all,

I m trying to run the MI-CSP scenario with the Sklearn algorithms.
As I can see Classifier Trainer box has different inputs than the Trainer Sklearn box.
If I press right click I cant see inputs setting to add new input.

Is it possible to run the classifier scenario by replace the Classifier Trainer box with the Trainer Sklearn box and by replace the Classifier Box with the Process Sklearn box in the online scenario.

Image

Thanks in advance.

mhadji05
Posts: 53
Joined: Tue Mar 16, 2021 9:37 am

Re: Sklearn

Post by mhadji05 »

Is there an expert who can tell me how to connect Sklearn to the scenario in the image of the previous post?

I would appreciate it a lot.

mhadji05
Posts: 53
Joined: Tue Mar 16, 2021 9:37 am

Re: Sklearn

Post by mhadji05 »

In continuation of the post above, how can I merge the feature vectors of the left and right hand movement into one, so that I can give them as an input to Trainer Sklearn for classification?

Thomas
Posts: 210
Joined: Wed Mar 04, 2020 3:38 pm

Re: Sklearn

Post by Thomas »

Hi mhadji05,

It is possible to use the Trainer Sklearn box instead of the Classifier Trainer box, but as you understood, they don't work quite the same way.

You are correct in wanting to merge both branches into one in order to feed into the Trainer Sklearn box, but the trick is that you do not need the feature aggregator this time.

You can use the Signal Merger box to merge the ouputs of the Simple DSP boxes, and then link the output of the Signal Merger box to the Trainer Sklearn box.

Let us know how you get on.

Cheers,
Thomas

mhadji05
Posts: 53
Joined: Tue Mar 16, 2021 9:37 am

Re: Sklearn

Post by mhadji05 »

Thanks for your response Thomas.

Here is my scenario.

Image

Unfortunately Openvibe return these errors.

Image

How can I solve it?

mhadji05
Posts: 53
Joined: Tue Mar 16, 2021 9:37 am

Re: Sklearn

Post by mhadji05 »

Does anyone have any idea why the Signal Merger box crashes?

Please note that with different individual's signals it crashes at different time.

Thanks in advance!

mhadji05
Posts: 53
Joined: Tue Mar 16, 2021 9:37 am

Re: Sklearn

Post by mhadji05 »

Please, I am stuck with this error.
If anyone can give me a solution with this error I would appreciate it a lot.

Thanks

Thomas
Posts: 210
Joined: Wed Mar 04, 2020 3:38 pm

Re: Sklearn

Post by Thomas »

Hi Marios,

Indeed, the Signal Merger box is not happy because it's meant to merge synchronised signals. However, because the Stimulation Based Epoching boxes are epoching at different times, the start times of the signal coming on input 0 and intput 1 of the Signal Merger box are not the same.

I have another solution for you! Since the Sklearn Trainer box expects signal on one input and detects the class from the stimulation received, as the two branches of the pipeline (Time Based Epoching, signal power log) are identical, you could actually have only one branch to do it all.

Since OpenViBE 3.3.0, it is possible to give multiple stimulations to the Stimulation Based Epoching box, therefore you could epoch for the Right and Left through the same branch, and as the Sklearn Trainer box also receives the stimulation, it knows what class of signal is coming.

Hope this makes sense, let us know how you get on.

Cheers,
Thomas

mhadji05
Posts: 53
Joined: Tue Mar 16, 2021 9:37 am

Re: Sklearn

Post by mhadji05 »

Dear Thomas

Is this what you suggest?

Image

The problem in this scenario is that model.clf cannot be saved because Player Controller box is unable to end the scenario.
What I'm doing wrong?

Also how can I convert the Online scenario?

As you can see in the image below Process Sklearn box cannot connect with the Graz visualization box

Image

Can you please provide me an image with the solution of these 2 scenarios?
I will appreciate it so much.
I'm stuck and I don't know how to proceed with this urgent problem.

If anyone can help is more than welcome.

Thanks in advance.

Thomas
Posts: 210
Joined: Wed Mar 04, 2020 3:38 pm

Re: Sklearn

Post by Thomas »

Hi Marios,

Yes, this is nearly what I suggest.
To complete it, you want to keep the connection from the identity box stimulation output to the sklearn trainer stimulation input so that the sklearn box can differentiate the incoming classes.

As for the Player Controller, the Trainer Sklearn box outputs the "OVTK_StimulationId_ExperimentStop" stimulation when it has finished training on the data.
A tip in case you need this kind of info again: you can use the Stimulation Listener box to check what stimulations come out of a box.

As for the Graz Visualisation, this is complicated. Indeed the Process Sklearn box cannot replace the Classifier processor here, as it only outputs detected targets. The Classifier processor feeds the Graz visualisation with a Hyperplane distance (if the algorithm provides it) which is not available in the Process Sklearn box.

I think you could create a python script (using the Python Scripting box) to generate a fake hyperplane matrix with one dimension only, containing 0.0 for target 1 and 1.0 for target 2. You will need to play a bit with it, I am not entirely sure this will work.

Hope this helps a bit.

Cheers,
Thomas

mhadji05
Posts: 53
Joined: Tue Mar 16, 2021 9:37 am

Re: Sklearn

Post by mhadji05 »

Unfortunately the scenario cannot be stopped unless and ONLY if it is terminated with the stop button.

By extension, the model.clf is not created.

The stimulation listener box doesn't print any information to the console .

After the Sklearn training, is there any chance to used in the online scenario the classifier processor box instead of the Sklearn process box


Image

Thomas
Posts: 210
Joined: Wed Mar 04, 2020 3:38 pm

Re: Sklearn

Post by Thomas »

mhadji05 wrote:
Wed Mar 01, 2023 10:36 am
Unfortunately the scenario cannot be stopped unless and ONLY if it is terminated with the stop button.
I understand from this that the Sklearn Trainer box does not send the ExperimentStop stimulation (and it does not appear in the stimulation listener log either), right ?

The Sklearn Trainer box starts training the model once it stops receiving signal.
What happens in OpenViBE is that a box sends a header describing the signal, then many packets of signal, and finally a packet of end.
The Sklearn Trainer box should start training the model when receiving the end packet.
Did you run your scenario until the Generic Stream Reader has finished reading the file ?

Unfortunately, the classifier box will not be able to interpret the .clf model generated by the sklearn trainer box, so you won't be able to swap them easily.

Thomas

mhadji05
Posts: 53
Joined: Tue Mar 16, 2021 9:37 am

Re: Sklearn

Post by mhadji05 »

Since OpenViBE 3.3.0, it is possible to give multiple stimulations to the Stimulation Based Epoching box, therefore you could epoch for the Right and Left through the same branch, and as the Sklearn Trainer box also receives the stimulation, it knows what class of signal is coming.
Answer: How Stimulation Based Epoching box can epoch for the Right and Left through the same branch?
Am I doing something wrong? (Please see image)

Image

I understand from this that the Sklearn Trainer box does not send the ExperimentStop stimulation (and it does not appear in the stimulation listener log either), right ?
Answer: YES
Did you run your scenario until the Generic Stream Reader has finished reading the file ?
Answer: YES running for hours. EEG recording is only 7 mins.
Console says: "No correct location has been given to load the model from, thus a new model will be created"
But the model is not created.
I think you could create a python script (using the Python Scripting box) to generate a fake hyperplane matrix with one dimension only, containing 0.0 for target 1 and 1.0 for target 2.
Answer: Is there any example? I m not sure how to do it.

Is there any other way to do it with openvibe boxes without scripting?

illusion
Posts: 7
Joined: Tue Dec 27, 2022 11:24 am

Re: Sklearn

Post by illusion »

Hello mhadji05,

Have you found a solution for this?

It is very interesting and useful if we can use so many algorithms in our scenarios.
If you manage to use Sklearn, please let us know how it is possible.

Thomas
Posts: 210
Joined: Wed Mar 04, 2020 3:38 pm

Re: Sklearn

Post by Thomas »

Hi Marios,
How Stimulation Based Epoching box can epoch for the Right and Left through the same branch?
Am I doing something wrong? (Please see image)
You can add a stimulation setting by right-clicking on the box, then modify settings -> new.... Once done, a new stimulation setting will appear in the box settings.
YES running for hours. EEG recording is only 7 mins.
Sorry this had me digging a bit in the code, and as a matter of fact, the use of END chunks is not implemented everywhere in OpenViBE, leading to the possibility of not having such chunk at the end of the file. That seems to be your case. From what I see, sklearn exemple coming with OpenViBE is using CSV format to read/write from. The CSV reader box does add a END chunk at the end of the file, triggering the Trainer box.
The Sklearn Trainer box could be updated to trigger training upon receiving a specific stimulation rather than the END chunk (like the Classifier trainer box), until the use of END chunk is implemented everywhere (which might not be soon...).

For your work, you could therefore look into updating the sklearn box of course, but if you need a more short term option, you could try recording your data into CSV, for training purpose. You can convert easily your OV files using the ov2csv.xml scenario coming with openvibe (in scenarios/convert).
Is there any example? I m not sure how to do it.
There is no exemple for the specific task, but there are python scripting exemples in OpenViBE, in the folder scenarios/box-tutorials/python3 to show you the basic steps of receiving and sending data using the python box. The link I shared in my previous post also has information on how to use the python scripting box.

I don't see other ways of connecting the sklean processor to the graz visualization without scripting or, of course, modifying the sklearn processor box.

Sorry for the delay, I hope this helps a bit.

Cheers,
Thomas

Post Reply