Fixes
Browse files- fixes the example
- the number of classes is 20, not 21
README.md
CHANGED
@@ -21,15 +21,16 @@ I translated the model to ONNX format.
|
|
21 |
|
22 |
Get the `deeplabv3p-resnet50-human.onnx` file and use it with ONNXRuntime package.
|
23 |
|
24 |
-
The result of `model.run` is a `(1, 1, 512, 512,
|
25 |
|
26 |
- 1: number of output (you can squeeze it)
|
27 |
- 1: batch size (you can squeeze it)
|
28 |
- 512, 512: the size of the image (fixed)
|
29 |
-
-
|
30 |
|
31 |
```python
|
32 |
import onnxruntime
|
|
|
33 |
from PIL import Image
|
34 |
|
35 |
img = Image.open(sys.argv[1] if len(sys.argv) > 1 else "image.jpg")
|
@@ -44,7 +45,7 @@ result = np.array(result[0])
|
|
44 |
result = result.argmax(axis=3).squeeze(0)
|
45 |
|
46 |
# get the masks
|
47 |
-
for i in range(
|
48 |
detected = result == i # get the detected pixels for the class i
|
49 |
# detected is a 512, 512 boolean array
|
50 |
mask = np.zeros_like(img)
|
|
|
21 |
|
22 |
Get the `deeplabv3p-resnet50-human.onnx` file and use it with ONNXRuntime package.
|
23 |
|
24 |
+
The result of `model.run` is a `(1, 1, 512, 512, 20)` tensor:
|
25 |
|
26 |
- 1: number of output (you can squeeze it)
|
27 |
- 1: batch size (you can squeeze it)
|
28 |
- 512, 512: the size of the image (fixed)
|
29 |
+
- 20: number of classes, so you can take the `argmax`` of the tensor to get the class of each pixel
|
30 |
|
31 |
```python
|
32 |
import onnxruntime
|
33 |
+
import numpy as np
|
34 |
from PIL import Image
|
35 |
|
36 |
img = Image.open(sys.argv[1] if len(sys.argv) > 1 else "image.jpg")
|
|
|
45 |
result = result.argmax(axis=3).squeeze(0)
|
46 |
|
47 |
# get the masks
|
48 |
+
for i in range(20):
|
49 |
detected = result == i # get the detected pixels for the class i
|
50 |
# detected is a 512, 512 boolean array
|
51 |
mask = np.zeros_like(img)
|