CLI sign in via Linux/Python Question

Hey EI folks, another question that I thought might arrant a new thread so other people can find the answer easier.

For the camera project I’m working on, once the camera devices are distributed to their various locations, I won’t have access to them any more. Some will have wi-fi connections, and for those that do, I’d like them to be able to update their versions of both the object detection and classification models they have. I was wondering if, via the CLI, there was any way of easily doing this.

If not, I’d write a program in Python that would delete both the model files after my main object detection and classification programs are finished for the day, then attempt to download them by executing shell commands in the Python code using the ‘edge-impulse-linux-runner --download modelfile.eim --clean’ command. If I did this though, the main problem would be logging in and selecting which model I wanted to download.

Any help with this matter would be much appreciated! Thanks IE team :slight_smile:

Hello @TechDevTom,

Good idea!
You can use this command: edge-impulse-linux-runner --download modelfile.eim without the --clean flag so you don’t have to login and select the right project again.

Regards,

Louis

1 Like

Hey @louis, thanks for getting back to me! The problem is, I’m downloading two models on to my Pi, so I do actually have to specific which project I want to download the model from. I’m not too sure on how to select the project through code though, as when I do it manually I have to type things in to log in and select the project.

Is there any code/token/other way of doing this? Thanks!

You can do this using the API (here using curl but we provide snippets for python / node / ruby / php):

To do this using our API you can follow these steps with the associated endpoints:

1) Retrieve your JWT token: Login - Edge Impulse API

You may need to check the validity of your token but you don’t need to do this part every time.

2) Build the model: Build On Device Model - Edge Impulse API

curl --request POST \
--url 'https://studio.edgeimpulse.com/v1/api/40479/jobs/build-ondevice-model?type=runner-mac-x86_64' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--cookie jwt=<Token> \
--data '
{
"engine": "tflite",
"modelType": "float32"
{"success":true,"id":1149219}**%**
  1. Check the job status: Get Job Status - Edge Impulse API

Example with curl:

curl --request GET \
--url https://studio.edgeimpulse.com/v1/api/40479/jobs/1149219/status \
--header 'Accept: application/json' \
--cookie jwt=<Token>
{"success":true,"job":{"id":1149219,"key":"deployment","created":"2021-07-27T13:36:11.538Z","started":"2021-07-27T13:36:11.542Z","finished":"2021-07-27T13:36:43.584Z","finishedSuccessful":true}}**%**
  1. Download model: Download - Edge Impulse API

Example with curl:

curl --request GET \
--url 'https://studio.edgeimpulse.com/v1/api/40479/deployment/download?type=runner-mac-x86_64&modelType=float32' \
--header 'Accept: application/zip' \
--cookie jwt=<Token> --output mycontainer.eim
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 16.4M 0 16.4M 0 0 1693k 0 --:--:-- 0:00:09 --:--:-- 1617k

Note that here I am using the “runner-mac-x86_64” download type, but you can change depending on your target architecture (runner-linux-armv7 or runner-linux-aarch64)

Regards,

Louis

1 Like

@TechDevTom We actually have UI for this, but it’s hidden by default (and can be enabled by user success). I’ll make that switch accessible for everyone so you can just download from the UI.

@janjongboom, the problem is no one will be there to use the UI :sweat_smile: This will all be headless and run in the background, unless you’re suggesting there’s some way to navigate through the UI in Python code?

That’s pretty much what I’m after! I don’t need the building of the model remotely yet, as I’ll still be doing that manually after collecting data from the devices, which also still needs to be figured out!

I’ll take a look through the docs on this and see what else I can find. Very useful to have those fields that you can type your credentials in so that it auto-generates the code for you, kudos for that design feature!

1 Like

@louis, will the above command get me the modelfile.eim? Or is it saying that it will download a zip file, in reference to the ‘Accept: application/zip’ comment?

No it’ll be eim file.

1 Like

Lovely! I’ll give this a shot later on, eventually I would like to collect data, send it up to EI for training/testing using the uploader, then bring the model back down again, but that’s a couple of steps away in my work yet! I’ll use this post as a reference for when I get that far.

1 Like

OK, will get an --force-target XXX option to the runner as well that lets you download for other architectures :slight_smile:

1 Like

Ah nice, that’d be great! I’ve been able to use ‘edge-impulse-linux-runner --download modelfile.eim’ and the ‘–clean’ version of that command for my Raspberry Pi/Linux project at the moment, but having other options would be good :slight_smile:

FYI you can now enable the Linux deploy options from ‘Administrative zone’ on Dashboard to download models for different architectures (from Deployment page after enabling this setting). The next Linux CLI release will add the --target command line option.

1 Like

Excellent! Just one question @janjongboom: What’s the Administrative zone on the dashboard? I have not seen a button/other for this, is it on a project dashboard?

I shall look forward to the next CLI release also, thanks :smiley:

Yeah Dashboard then there should be an ‘Administrative zone’ section.

edit: Sorry this is not live yet, will be as part of the release early next week.

2 Likes

Hey @louis and @janjongboom, just testing out the API calls now and they’re great, the JWT token call is working nicely! One thing I noticed though is that on your reference page for it, in the returned JSON example, the ‘success’ response is listed as being ‘true’, when actually it returns a ‘True’. That upper case ‘T’ in the response might throw some people off, as it’s not the response listed in the reference.

Hey guys, another question about the downloading API part, I’m getting the response “No deployment exists, did you build yet?” and I just realised that I may have misunderstood what @louis was saying a few days ago.

Is it the case that you have to build the model via the API before downloading it? I was under the impression that I could manually train the model via the online Dashboard and then use that command to download my newly trained model onto all of my devices.

If I do have to build the model via the API, does that mean I have to build the model via the API on every device that needs to download it? Or do I have a “master” device that requests the build be done, then when that has finished all other devices download it using the API?

Thanks in advance for any assistance that you can offer :smiley:

Hi @TechDevTom, yeah a model needs to be built first (separate from training), the CLI does this for you automatically. So perhaps you can do (on the master system or whatever):

$ edge-impulse-runner --download blah.eim --force-target runner-mac-x86_64

Which builds it, then it’ll be available for the other devices.

“One thing I noticed though is that on your reference page for it, in the returned JSON example, the ‘success’ response is listed as being ‘true’, when actually it returns a ‘True’. That upper case ‘T’ in the response might throw some people off, as it’s not the response listed in the reference.”

I assume you’re calling this from Python? It’s of type boolean, so true in the JSON but converted to the boolean value True in Python (not a string).

@janjongboom I see, but does that mean that once I’ve used that CLI call on the master device, that the model will then be available to all other devices via the API? None of these Edge devices I have will be connected to each other at all, so the model downloaded on the master device won’t be able to be distributed to others via a shared network.

I’m back to the original problem too, which is that by using the CLI call I can’t specify which project I want to download a model from code wise, as there are login/project fields I’d need to fill in in order to change projects.

With the CLI, is there a way of specifying my login data and which project I want to download a model from in the edge-impulse-runner command? Such as:

edge-impulse-runner --download blah.eim --force-target runner-mac-x86_64 --user username --password password --project projectID

Perhaps I need to put together a flow diagram and get it clear in my head how this might work best, I’m more of a visual learner, and might find a solution to my problem in doing so.

Regarding the True value, that’s just me not knowing enough about the Python language clearly! Apologies, I didn’t know such conversions happen, I’m from a C# background mostly, and creating mobile apps at that.

Yes, just need to be built once and then it’s cached on our servers.

With the CLI, is there a way of specifying my login data and which project I want to download a model from in the edge-impulse-runner command? Such as:

Use --api-key as a command line argument to the runner with a valid API key for your project.

1 Like