Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return anomaly maps in range 0-255 #146

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions model_api/cpp/models/src/anomaly_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ std::unique_ptr<ResultBase> AnomalyModel::postprocess(InferenceResult& infResult
pred_mask.convertTo(pred_mask, CV_8UC1, 1 / 255.);
cv::resize(pred_mask, pred_mask, cv::Size{inputImgSize.inputImgWidth, inputImgSize.inputImgHeight});
anomaly_map = normalize(anomaly_map, pixelThreshold);
anomaly_map.convertTo(anomaly_map, CV_8UC1, 255);

pred_score = normalize(pred_score, imageThreshold);
if (!anomaly_map.empty()) {
Expand Down
2 changes: 2 additions & 0 deletions model_api/python/openvino/model_api/models/anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def postprocess(self, outputs: dict[str, np.ndarray], meta: dict[str, Any]):
assert anomaly_map is not None
pred_mask = (anomaly_map >= self.pixel_threshold).astype(np.uint8)
anomaly_map = self._normalize(anomaly_map, self.pixel_threshold)
anomaly_map *= 255
anomaly_map = anomaly_map.astype(np.uint8)
pred_mask = cv2.resize(
pred_mask, (meta["original_shape"][1], meta["original_shape"][0])
)
Expand Down
4 changes: 2 additions & 2 deletions tests/python/accuracy/public_scope.json
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
{
"image": "coco128/images/train2017/000000000074.jpg",
"reference": [
"anomaly_map min:0.594 max:1.0;pred_score:1.0;pred_label:Anomaly;pred_mask min:1 max:1;"
"anomaly_map min:151 max:255;pred_score:1.0;pred_label:Anomaly;pred_mask min:1 max:1;"
]
}
]
Expand All @@ -379,7 +379,7 @@
{
"image": "coco128/images/train2017/000000000074.jpg",
"reference": [
"anomaly_map min:0.495 max:1.0;pred_score:1.0;pred_label:Anomaly;pred_mask min:0 max:1;"
"anomaly_map min:126 max:255;pred_score:1.0;pred_label:Anomaly;pred_mask min:0 max:1;"
]
}
]
Expand Down
Loading