Skip to content

Commit 43f72cb

Browse files
committed
Add tools to inference
1 parent 859120d commit 43f72cb

12 files changed

Lines changed: 82 additions & 80 deletions

README.md

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Abraia Vision SDK
66

7-
The Abraia Vision SDK is a Python package which provides a set of tools to develop and deploy advanced Machine Learning image applications on the edge. Moreover, with [Abraia DeepLab](https://abraia.me/deeplab/) you can easily annotate and train, your own versions of some of the best state of the art deep learning models, and get them ready to deploy with this Python SDK.
7+
The [Abraia Vision](https://abraia.me/vision/) SDK is a Python package which provides a set of tools to develop and deploy advanced Machine Learning image applications on the edge. Moreover, with [Abraia DeepLab](https://abraia.me/deeplab/) you can easily annotate and train, your own versions of some of the best state of the art deep learning models, and get them ready to deploy with this Python SDK.
88

99
Just install the Abraia SDK and CLI on Windows, Mac, or Linux:
1010

@@ -16,12 +16,13 @@ And start using deep learning models ready to work on your local devices.
1616

1717
## Deep learning custom models and applications
1818

19-
Annotate your images and train a state-of-the-art model for classification, detection, or segmentation using [DeepLab](https://abraia.me/deeplab/). You can directly load and run the model on the edge using the browser or this Python SDK.
19+
Consult your problem or directly try to annotate your images and train a state-of-the-art model for classification, detection, or segmentation using [DeepLab](https://abraia.me/deeplab/). You can directly load and run the model on the edge using the browser or this Python SDK.
2020

21-
### Object detection
21+
### Object detection and tracking
2222

23-
Detect multiple objects with a pre-trained YOLOv8 model on images, videos, or even camera streams. You just need to use
24-
the Video class to process every frame as is done for images.
23+
Identify and track multiple objects with a custom detection model on videos and camera streams, enabling real-time counting applications. You just need to use
24+
the Video class to process every frame as is done for images, and use the tracker to follow each object through
25+
every frame.
2526

2627
```python
2728
from abraia.inference import Model, Tracker
@@ -130,8 +131,6 @@ clip_model = Clip()
130131
image_embeddings = clip_model.get_image_embeddings([image])[0]
131132
text_embeddings = clip_model.get_text_embeddings(texts)
132133

133-
# To use the embeddings for zero-shot classification, you can use these two
134-
# functions. Here we run on a single image, but any number is supported.
135134
logits = [100 * cosine_similarity(image_embeddings[0], features) for features in text_embeddings]
136135
for text, p in zip(texts, softmax(logits)):
137136
print(f"Probability that the image is '{text}': {p:.3f}")
@@ -183,10 +182,9 @@ index, scores = search_vector(vector, image_index)
183182
print(f"Similarity score is {scores[index]} for image {image_paths[index]}")
184183
```
185184

186-
187185
## Hyperspectral image analysis toolbox
188186

189-
The Multiple extension provides seamless integration of multispectral and hyperspectral images. It has being developed by [ABRAIA](https://abraia.me/about) in the [Multiple project](https://multipleproject.eu/) to extend the Abraia SDK and Cloud Platform providing support for straightforward HyperSpectral Image (HSI) analysis and classification.
187+
The Multiple extension provides seamless integration of multispectral and hyperspectral images, providing support for straightforward HyperSpectral Image (HSI) analysis and classification.
190188

191189
Just click on one of the available Colab's notebooks to directly start testing the multispectral capabilities:
192190

@@ -196,7 +194,7 @@ Just click on one of the available Colab's notebooks to directly start testing t
196194

197195
![classification](https://github.com/abraia/abraia-multiple/raw/master/images/classification.png)
198196

199-
Or install the multiple extension to use the Abraia-Multiple SDK:
197+
To install the multiple extension use the command bellow:
200198

201199
```sh
202200
python -m pip install -U "abraia[multiple]"
@@ -273,61 +271,6 @@ model.train(X, y, train_ratio=0.3, epochs=5)
273271
y_pred = model.predict(X)
274272
```
275273

276-
## Command line interface
277-
278-
The Abraia CLI provides access to the Abraia Cloud Platform through the command line. It makes simple to manage your files and enables bulk image editing capabilities. It provides and easy way to resize, convert, and compress your images - JPEG, WebP, or PNG -, and get them ready to publish on the web. Moreover, you can automatically remove the background, upscale, or anonymize your images in bulk.
279-
280-
### Remove unwanted objects
281-
282-
Remove unwanted objects in images and photos locally. Just click on the object to automatically select and delete it from the image. Finally, press "s" to save the output image.
283-
284-
```sh
285-
abraia editing clean dog.jpg
286-
```
287-
288-
![inpaint output](https://github.com/abraia/abraia-multiple/raw/master/images/inpaint-output.jpg)
289-
290-
### Upscale images
291-
292-
Scale up and enhance images in bulk, doubling the size and preserving quality.
293-
294-
```sh
295-
abraia editing upscale "*.jpg"
296-
```
297-
298-
![upscaled cat](https://github.com/abraia/abraia-multiple/raw/master/images/cat-upscaled.jpg)
299-
300-
### Convert images
301-
302-
Compress images in bulk specifying the input glob pattern or folder:
303-
304-
```sh
305-
abraia editing convert "images/bird*.jpg"
306-
```
307-
308-
Automatically change the aspect ratio specifying both `width` and `height` parameters and setting the resize `mode` (pad, crop, thumb). Or simply resize images maintaining the aspect ratio just specifying the `width` or the `height` of the new image:
309-
310-
```sh
311-
abraia editing convert images/birds.jpg --width 375 --height 375 --mode pad
312-
abraia editing convert images/birds.jpg --width 375 --height 375
313-
abraia editing convert images/birds.jpg --width 750
314-
```
315-
316-
![image padded](https://github.com/abraia/abraia-multiple/raw/master/images/birds_padded.jpg)
317-
![image smart cropped](https://github.com/abraia/abraia-multiple/raw/master/images/birds_cropped.jpg)
318-
319-
So, you can automatically resize all the images in a specific folder preserving the aspect ration of each image just specifying the target `width` or `height`:
320-
321-
```sh
322-
abraia editing convert [src] --width 300
323-
```
324-
325-
Or, automatically pad or crop all the images contained in the folder specifying both `width` and `height`:
326-
327-
```sh
328-
abraia editing convert [src] --width 300 --height 300 --mode crop
329-
```
330-
331274
## License
332275

333276
This software is licensed under the MIT License. [View the license](LICENSE).

abraia/inference/tools.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
from abraia.inference.ops import count_objects, segments_intersect, point_in_polygon
3+
4+
5+
class LineCounter:
6+
def __init__(self, line):
7+
self.line = line
8+
self.in_count = 0
9+
self.out_count = 0
10+
self.prev_results = {}
11+
12+
def update(self, results):
13+
for result in results:
14+
track_id = result.get('track_id')
15+
if track_id is not None:
16+
prev_result = self.prev_results.get(track_id)
17+
if prev_result:
18+
(x1, y1, w1, h1), (x2, y2, w2, h2) = result['box'], prev_result['box']
19+
val = segments_intersect(self.line[0], self.line[1], [x1 + w1 / 2, y1 + h1 / 2], [x2 + w2 / 2, y2 + h2 / 2])
20+
if val > 0:
21+
self.in_count += 1
22+
if val < 0:
23+
self.out_count += 1
24+
self.prev_results[track_id] = result
25+
return self.in_count, self.out_count
26+
27+
28+
class RegionFilter:
29+
def __init__(self, polygon):
30+
self.region = polygon
31+
32+
def update(self, results):
33+
in_objects, out_objects = [], []
34+
for result in results:
35+
box = result.get('box')
36+
if box:
37+
x, y, w, h = box
38+
center = x + w / 2, y + h / 2
39+
if point_in_polygon(center, self.region):
40+
in_objects.append(result)
41+
else:
42+
out_objects.append(result)
43+
return in_objects, out_objects
44+
45+
46+
class RegionTimer():
47+
def __init__(self, polygon):
48+
self.region = polygon
49+
self.timers = {}
50+
51+
def update(self, results, frame_time):
52+
in_objects, out_objects = [], []
53+
for result in results:
54+
box = result.get('box')
55+
track_id = result.get('track_id')
56+
start_time = self.timers.get(track_id)
57+
if box and track_id is not None:
58+
x, y, w, h = box
59+
center = x + w / 2, y + h / 2
60+
if point_in_polygon(center, self.region):
61+
in_objects.append(result)
62+
if start_time == None:
63+
self.timers[track_id] = frame_time
64+
else:
65+
print(f'Time in zone [{track_id}]: {round(frame_time - start_time, 2)}')
66+
result['label'] = f"waiting {round(frame_time - start_time, 2)}s"
67+
del result['score']
68+
else:
69+
out_objects.append(result)
70+
if start_time != None:
71+
del self.timers[track_id]
72+
return in_objects, out_objects

images/birds_cropped.jpg

-34.3 KB
Binary file not shown.

images/birds_optimized.jpg

-74.7 KB
Binary file not shown.

images/birds_padded.jpg

-23 KB
Binary file not shown.

images/birds_resized.jpg

-45.2 KB
Binary file not shown.

images/blur-background.jpg

-195 KB
Binary file not shown.

images/cat-upscaled.jpg

-137 KB
Binary file not shown.

images/inpaint-output.jpg

-172 KB
Binary file not shown.

images/people-car-anonymized.jpg

-151 KB
Binary file not shown.

0 commit comments

Comments
 (0)