Labib Asari
commited on
Commit
·
5426c28
1
Parent(s):
757f0c8
added evaluation script for PPHumanSeg model (#130)
Browse files* added evaluation script for PPHumanSeg
* added quantized model, renamed dataset
* minor spacing changes
* moved _all variables outside loop and updated accuracy
* removed printing for class accuracy and IoU
* added 2 transforms
* evaluation done on same size tensor as input size with mIoU 0.9085
* final changes
* added mIoU and reference
- README.md +12 -0
- pphumanseg.py +13 -4
README.md
CHANGED
|
@@ -22,6 +22,18 @@ python demo.py --help
|
|
| 22 |
|
| 23 |

|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
## License
|
| 26 |
|
| 27 |
All files in this directory are licensed under [Apache 2.0 License](./LICENSE).
|
|
|
|
| 22 |
|
| 23 |

|
| 24 |
|
| 25 |
+
---
|
| 26 |
+
Results of accuracy evaluation with [tools/eval](../../tools/eval).
|
| 27 |
+
|
| 28 |
+
| Models | Accuracy | mIoU |
|
| 29 |
+
| ------------------ | -------------- | ------------- |
|
| 30 |
+
| PPHumanSeg | 0.9581 | 0.8996 |
|
| 31 |
+
| PPHumanSeg quant | 0.4365 | 0.2788 |
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
\*: 'quant' stands for 'quantized'.
|
| 35 |
+
|
| 36 |
+
---
|
| 37 |
## License
|
| 38 |
|
| 39 |
All files in this directory are licensed under [Apache 2.0 License](./LICENSE).
|
pphumanseg.py
CHANGED
|
@@ -19,6 +19,7 @@ class PPHumanSeg:
|
|
| 19 |
|
| 20 |
self._inputNames = ''
|
| 21 |
self._outputNames = ['save_infer_model/scale_0.tmp_1']
|
|
|
|
| 22 |
self._inputSize = [192, 192]
|
| 23 |
self._mean = np.array([0.5, 0.5, 0.5])[np.newaxis, np.newaxis, :]
|
| 24 |
self._std = np.array([0.5, 0.5, 0.5])[np.newaxis, np.newaxis, :]
|
|
@@ -36,21 +37,25 @@ class PPHumanSeg:
|
|
| 36 |
self._model.setPreferableTarget(self._targetId)
|
| 37 |
|
| 38 |
def _preprocess(self, image):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
image = image.astype(np.float32, copy=False) / 255.0
|
| 40 |
image -= self._mean
|
| 41 |
image /= self._std
|
| 42 |
return cv.dnn.blobFromImage(image)
|
| 43 |
|
| 44 |
def infer(self, image):
|
| 45 |
-
assert image.shape[0] == self._inputSize[1], '{} (height of input image) != {} (preset height)'.format(image.shape[0], self._inputSize[1])
|
| 46 |
-
assert image.shape[1] == self._inputSize[0], '{} (width of input image) != {} (preset width)'.format(image.shape[1], self._inputSize[0])
|
| 47 |
|
| 48 |
# Preprocess
|
| 49 |
inputBlob = self._preprocess(image)
|
| 50 |
|
| 51 |
# Forward
|
| 52 |
self._model.setInput(inputBlob, self._inputNames)
|
| 53 |
-
outputBlob = self._model.forward(
|
| 54 |
|
| 55 |
# Postprocess
|
| 56 |
results = self._postprocess(outputBlob)
|
|
@@ -58,6 +63,10 @@ class PPHumanSeg:
|
|
| 58 |
return results
|
| 59 |
|
| 60 |
def _postprocess(self, outputBlob):
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
return result
|
| 63 |
|
|
|
|
| 19 |
|
| 20 |
self._inputNames = ''
|
| 21 |
self._outputNames = ['save_infer_model/scale_0.tmp_1']
|
| 22 |
+
self._currentInputSize = None
|
| 23 |
self._inputSize = [192, 192]
|
| 24 |
self._mean = np.array([0.5, 0.5, 0.5])[np.newaxis, np.newaxis, :]
|
| 25 |
self._std = np.array([0.5, 0.5, 0.5])[np.newaxis, np.newaxis, :]
|
|
|
|
| 37 |
self._model.setPreferableTarget(self._targetId)
|
| 38 |
|
| 39 |
def _preprocess(self, image):
|
| 40 |
+
|
| 41 |
+
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
|
| 42 |
+
|
| 43 |
+
self._currentInputSize = image.shape
|
| 44 |
+
image = cv.resize(image, (192, 192))
|
| 45 |
+
|
| 46 |
image = image.astype(np.float32, copy=False) / 255.0
|
| 47 |
image -= self._mean
|
| 48 |
image /= self._std
|
| 49 |
return cv.dnn.blobFromImage(image)
|
| 50 |
|
| 51 |
def infer(self, image):
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# Preprocess
|
| 54 |
inputBlob = self._preprocess(image)
|
| 55 |
|
| 56 |
# Forward
|
| 57 |
self._model.setInput(inputBlob, self._inputNames)
|
| 58 |
+
outputBlob = self._model.forward()
|
| 59 |
|
| 60 |
# Postprocess
|
| 61 |
results = self._postprocess(outputBlob)
|
|
|
|
| 63 |
return results
|
| 64 |
|
| 65 |
def _postprocess(self, outputBlob):
|
| 66 |
+
|
| 67 |
+
outputBlob = outputBlob[0]
|
| 68 |
+
outputBlob = cv.resize(outputBlob.transpose(1,2,0), (self._currentInputSize[1], self._currentInputSize[0]), interpolation=cv.INTER_LINEAR).transpose(2,0,1)[np.newaxis, ...]
|
| 69 |
+
|
| 70 |
+
result = np.argmax(outputBlob, axis=1).astype(np.uint8)
|
| 71 |
return result
|
| 72 |
|