Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .github/actions/install-colint/action.yaml

This file was deleted.

58 changes: 8 additions & 50 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,60 +1,18 @@
name: Lint Checks

on: [pull_request, push]

jobs:
sort_libraries:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install Colint
uses: ./.github/actions/install-colint

- name: Run Sort Libraries Check
run: |
colint sort-libraries . --check --config-file ./lint

code_format:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install Colint
uses: ./.github/actions/install-colint

- name: Run Code Format Check
run: |
colint code-format . --check --config-file ./lint

grammar_check:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install Colint
uses: ./.github/actions/install-colint

- name: Run Grammar Check
run: |
colint grammar-check . --check --config-file ./lint

newline_fix:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install Colint
uses: ./.github/actions/install-colint
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10.12"

- name: Run Newline Fix Check
- name: Run linting
run: |
colint newline-fix . --check --config-file ./lint
make setup-env
make lint CHECK=1
2 changes: 1 addition & 1 deletion .github/workflows/push-to-registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10.12'
python-version: "3.10.12"

- name: Install Build Dependencies
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build
*.jpg
.DS_Store
.venv/
.venv-lint/
.vscode
*.eim
.act-secrets
Expand Down
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
VENV_DIR := $(abspath .venv-lint)
PIP := $(VENV_DIR)/bin/pip
PYTHON := $(VENV_DIR)/bin/python
RUFF := $(VENV_DIR)/bin/ruff
DPRINT := $(VENV_DIR)/bin/dprint
TARGET_DIRS ?= .
CHECK ?= 0

.PHONY: clean
clean:
git clean -Xdf --exclude "!.env"

.PHONY: setup-venv
setup-venv:
@if [ ! -d "$(VENV_DIR)" ]; then \
echo "Creating virtual environment for linters..."; \
python3 -m venv $(VENV_DIR); \
$(PIP) install --upgrade pip; \
$(PIP) install ruff; \
fi

.PHONY: setup-dprint
setup-dprint: setup-venv
@if [ ! -f "$(DPRINT)" ]; then \
echo "Installing dprint to $(VENV_DIR)/bin..."; \
mkdir -p $(VENV_DIR)/bin; \
curl -fsSL https://dprint.dev/install.sh | DPRINT_INSTALL=$(VENV_DIR) sh; \
fi

.PHONY: setup-env
setup-env: setup-venv setup-dprint

.PHONY: ruff
ruff: setup-venv
@if [ "$(CHECK)" = "1" ]; then \
echo "Running Ruff in check mode..."; \
$(RUFF) check $(TARGET_DIRS); \
LINT_STATUS=$$?; \
$(RUFF) format $(TARGET_DIRS) --check; \
FMT_STATUS=$$?; \
if [ $$LINT_STATUS -ne 0 ] || [ $$FMT_STATUS -ne 0 ]; then exit 1; fi; \
else \
echo "Running Ruff and fixing issues..."; \
$(RUFF) check $(TARGET_DIRS) --fix; \
LINT_STATUS=$$?; \
$(RUFF) format $(TARGET_DIRS); \
FMT_STATUS=$$?; \
if [ $$LINT_STATUS -ne 0 ] || [ $$FMT_STATUS -ne 0 ]; then exit 1; fi; \
fi

.PHONY: dprint
dprint: setup-dprint
@if [ "$(CHECK)" = "1" ]; then \
echo "Running dprint in check mode..."; \
$(DPRINT) check $(TARGET_DIRS); \
else \
echo "Running dprint and formatting..."; \
$(DPRINT) fmt $(TARGET_DIRS); \
fi

.PHONY: lint
lint: ruff dprint
61 changes: 31 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@ This library lets you run machine learning models and collect sensor data on Lin
1. Install a recent version of [Python 3](https://www.python.org/downloads/) and `pip` tools.
1. Install the SDK:

**Raspberry Pi**
**Raspberry Pi**

```
$ sudo apt-get install libatlas-base-dev libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev libopenjp2-7 libgtk-3-0 libswscale-dev libavformat58 libavcodec58
$ pip3 install edge_impulse_linux -i https://pypi.python.org/simple
```
```
$ sudo apt-get install libatlas-base-dev libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev libopenjp2-7 libgtk-3-0 libswscale-dev libavformat58 libavcodec58
$ pip3 install edge_impulse_linux -i https://pypi.python.org/simple
```

**Other platforms**
**Other platforms**

```
$ pip3 install edge_impulse_linux
```
```
$ pip3 install edge_impulse_linux
```

1. Clone this repository to get the examples:

```
$ git clone https://github.com/edgeimpulse/linux-sdk-python
```
```
$ git clone https://github.com/edgeimpulse/linux-sdk-python
```

4. Install pip dependencies:
1. Install pip dependencies:

```
$ pip3 install -r requirements.txt
```
```
$ pip3 install -r requirements.txt
```

For the computer vision examples you'll want `opencv-python>=4.5.1.48,<5`
Note on macOS on apple silicon, you will need to use a later version,
4.10.0.84 tested and installs cleanly
For the computer vision examples you'll want `opencv-python>=4.5.1.48,<5`
Note on macOS on apple silicon, you will need to use a later version,
4.10.0.84 tested and installs cleanly

## Collecting data

Expand All @@ -69,31 +69,32 @@ To classify data (whether this is from the camera, the microphone, or a custom s
1. Install the [Edge Impulse for Linux CLI](https://docs.edgeimpulse.com/docs/edge-impulse-for-linux).
1. Download the model file via:

```
$ edge-impulse-linux-runner --download modelfile.eim
```
```
$ edge-impulse-linux-runner --download modelfile.eim
```

This downloads the file into `modelfile.eim`. (Want to switch projects? Add `--clean`)
This downloads the file into `modelfile.eim`. (Want to switch projects? Add `--clean`)

Then you can start classifying realtime sensor data. We have examples for:

* [Audio](https://github.com/edgeimpulse/linux-sdk-python/blob/master/examples/audio/classify.py) - grabs data from the microphone and classifies it in realtime.
* [Camera](https://github.com/edgeimpulse/linux-sdk-python/blob/master/examples/image/classify.py) - grabs data from a webcam and classifies it in realtime.
* [Camera (full frame)](https://github.com/edgeimpulse/linux-sdk-python/blob/master/examples/image/classify-full-frame.py) - grabs data from a webcam and classifies it twice (once cut from the left, once cut from the right). This is useful if you have a wide-angle lense and don't want to miss any events.
* [Still image](https://github.com/edgeimpulse/linux-sdk-python/blob/master/examples/image/classify-image.py) - classifies a still image from your hard drive.
* [Video](https://github.com/edgeimpulse/linux-sdk-python/blob/master/examples/image/classify-video.py) - grabs frames from a video source from your hard drive and classifies it.
* [Custom data](https://github.com/edgeimpulse/linux-sdk-python/blob/master/examples/custom/classify.py) - classifies custom sensor data.
- [Audio](https://github.com/edgeimpulse/linux-sdk-python/blob/master/examples/audio/classify.py) - grabs data from the microphone and classifies it in realtime.
- [Camera](https://github.com/edgeimpulse/linux-sdk-python/blob/master/examples/image/classify.py) - grabs data from a webcam and classifies it in realtime.
- [Camera (full frame)](https://github.com/edgeimpulse/linux-sdk-python/blob/master/examples/image/classify-full-frame.py) - grabs data from a webcam and classifies it twice (once cut from the left, once cut from the right). This is useful if you have a wide-angle lense and don't want to miss any events.
- [Still image](https://github.com/edgeimpulse/linux-sdk-python/blob/master/examples/image/classify-image.py) - classifies a still image from your hard drive.
- [Video](https://github.com/edgeimpulse/linux-sdk-python/blob/master/examples/image/classify-video.py) - grabs frames from a video source from your hard drive and classifies it.
- [Custom data](https://github.com/edgeimpulse/linux-sdk-python/blob/master/examples/custom/classify.py) - classifies custom sensor data.

## Troubleshooting

### Collecting print out from the model

To display the logging messages (ie, you may be used to in other deployments), init the runner like so

```
# model_info = runner.init(debug=True) # to get debug print out
```
This will pipe stdout and stderr into the same of your own process

This will pipe stdout and stderr into the same of your own process

### [Errno -9986] Internal PortAudio error (macOS)

Expand Down
33 changes: 33 additions & 0 deletions dprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"yaml": {
"formatComments": true,
"braceSpacing": false,
"preferSingleLine": true
},
"json": {
"lineWidth": 80
},
"toml": {
"lineWidth": 80
},
"markdown": {
"emphasisKind": "asterisks"
},
"markup": {
"formatComments": true
},
"includes": [
"**/*.{yaml,yml}",
"**/*.json",
"**/*.toml",
"**/*.md",
"**/*.html"
],
"plugins": [
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.6.0.wasm",
"https://plugins.dprint.dev/toml-0.7.0.wasm",
"https://plugins.dprint.dev/json-0.21.3.wasm",
"https://plugins.dprint.dev/markdown-0.22.1.wasm",
"https://plugins.dprint.dev/g-plane/markup_fmt-v0.27.3.wasm"
]
}
12 changes: 5 additions & 7 deletions examples/custom/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
freq = 1000 / INTERVAL_MS
values_list = []
for i in range(2 * int(round(freq, 0))):
values_list.append(
[
math.sin(i * 0.1) * 10,
math.cos(i * 0.1) * 10,
(math.sin(i * 0.1) + math.cos(i * 0.1)) * 10,
]
)
values_list.append([
math.sin(i * 0.1) * 10,
math.cos(i * 0.1) * 10,
(math.sin(i * 0.1) + math.cos(i * 0.1)) * 10,
])

data = {
"protected": {
Expand Down
1 change: 0 additions & 1 deletion examples/image/classify-video.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def getFrame(sec):
img = getFrame(sec)

while img.size != 0:

# imread returns images in BGR format, so we need to convert to RGB
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

Expand Down
10 changes: 4 additions & 6 deletions examples/image/set-thresholds.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,10 @@ def main(argv):
print("Invalid input, please enter a number")

# dynamically override the thresold from 0.2 -> 0.8
runner.set_threshold(
{
"id": threshold_id,
"min_score": new_threshold,
}
)
runner.set_threshold({
"id": threshold_id,
"min_score": new_threshold,
})

res = runner.classify(features)
print("classify response", json.dumps(res, indent=4))
Expand Down
46 changes: 0 additions & 46 deletions lint.toml

This file was deleted.

Loading
Loading