Edge Impulse API Training Learning Block Error

I was using https://docs.edgeimpulse.com/reference/trainkerasjob to train my Classifier. However, when I try to train the Keras model, I get the error, “Number of new classes and neurons should be a positive number!”

I matched all the API settings (for the training script) to the payloads from the Chrome browser of a working project. However, it’s still not working. I’ll paste the code I used to train the model below. I’ve also tried adding a dense layer at the end to serve as an output layer, but that didn’t work. I’ve checked and the impulse blocks are also matched.

My Project ID is 337137.

As a side question, if I run the create impulse API script twice, will the blocks be overwritten? Because I am not allowed to delete the learning blocks. So if they do not overwrite, then I have to create a new project every time I test the API (because the API creates another learning block with the same ID and all that).

import requests

url = "https://studio.edgeimpulse.com/v1/api/337137/jobs/train/keras/5"

payload = {
    "augmentationPolicySpectrogram": {
        "enabled": False,
        "gaussianNoise": "high",
        "freqMasking": "none",
        "timeMasking": "low",
        "warping": False
    },
    "akidaEdgeLearningConfig": { "enabled": False },
    "mode": "visual",
    "visualLayers": [{
            "type": "reshape",
            "columns": 13
        }, {
            "type": "conv1d",
            "neurons": 8,
            "kernelSize": 3,
            "stack": 1
        }, {
            "type": "dropout",
            "dropoutRate": 0.25
        }, {
            "type": "conv1d",
            "neurons": 16,
            "kernelSize": 3,
            "stack": 1
        }, {
            "type": "dropout",
            "dropoutRate": 0.25
        }, { "type": "flatten" }],
    "trainingCycles": 5,
    "learningRate": 0.005,
    "profileInt8": False,
    "augmentationPolicyImage": "none",
    "autoClassWeights": False,
    "trainTestSplit": 0.2
}
headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "x-api-key": "ei_128ba30ff7c8b8879d5e2b7e1ba07b0c6b02a8d60c227cf25c6a65645550643a"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)

Please let me know if you have any other questions!

Hi @jeanelled

Are you working with BrainChip hardware? I can see you are trying to use the Akida Learn Block which is specific to their hardware.

If this is for Brainchip - Did you check that your dataset contains labeled data and that the labels match the expected number of classes? If you can verify that you have at least two different classes, as a single class cannot form a classification problem.

Your payload does not explicitly mention the configuration of the output layer, which is crucial for matching the number of classes in your dataset. For classification tasks, the output layer should have a neuron for each class and typically uses a ‘softmax’ activation function to output probabilities.

Please share any edits you have made to the Learn Block, and any Expert mode changes along with a screenshot of the Create Impulse tab. Thanks!

Note: Make sure to replace num_classes with the actual number of classes in your dataset.

Best

Eoin

In my code, akidaEdgeLearningConfig is False. Is this correct, or is there another way to use the default classifier in the Studio? Because when I look in the studio, it doesn’t say it’s Akida or anything. Is this a hidden setting?

To clarify, I’m using a Nano 33 BLE Sense. Lastly, I don’t see softmax as an option in the API Documentation, I only see things like Dense and Flatten. Do I have to download the code and manually add it, or is it in another setting?

Thank you so much again!