UlysseCoteAllard / MyoArmbandDataset

GNU General Public License v3.0
83 stars 40 forks source link

online prediction #11

Open GuiyinLi opened 2 years ago

GuiyinLi commented 2 years ago

Is the code of online prediction open source?

UlysseCoteAllard commented 2 years ago

Do you mean just on the Python side or the interface with the JACO robotic arm from KINOVA also? From a quick search, I could not retrieve it, but I can try to look more into it. Note however that it would be using the Theano implementation if I remember correctly.

The Python side is relatively easy, simply create the network, load the trained weight and fix the network with .eval(). Then when the online process call your Python method with the signal as input, you just transform that signal into a Tensor (basically treating it as a mini-batch of size 1, extract the prediction and return the class number.

GuiyinLi commented 2 years ago

Okay, I get it, thank you very much

GuiyinLi commented 2 years ago

Just real-time classify with Python. From your paper, I learned that the original signal should be split with a sliding window. I'm curious if this sliding window is implemented by the "format_data_to_train()". In addition, the "size_non_overlap = 5" is related to "The data is first separated by applying sliding windows of 52 samples (260ms) with an overlap of 235ms (i.e. 7 × 190 samples for one cycle (5s of data))" from your paper.

number_of_vector_per_example = 52
number_of_canals = 8
number_of_classes = 7
size_non_overlap = 5

def format_data_to_train(vector_to_format):
    dataset_example_formatted = []
    example = []
    emg_vector = []
    for value in vector_to_format:
        emg_vector.append(value)
        if (len(emg_vector) >= 8):
            if (example == []):
                example = emg_vector
            else:
                example = np.row_stack((example, emg_vector))
            emg_vector = []
            if (len(example) >= number_of_vector_per_example):
                example = example.transpose()
                dataset_example_formatted.append(example)
                example = example.transpose()
                example = example[size_non_overlap:]
    data_calculated = calculate_wavelet.calculate_wavelet_dataset(dataset_example_formatted)
    return np.array(data_calculated)