You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by zh...@apache.org on 2022/03/01 03:22:18 UTC
[singa] branch dev updated: update the lime interpretation module
This is an automated email from the ASF dual-hosted git repository.
zhaojing pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/singa.git
The following commit(s) were added to refs/heads/dev by this push:
new e7ac4e3 update the lime interpretation module
new 3931308 Merge pull request #933 from wannature/singa_v5
e7ac4e3 is described below
commit e7ac4e3b65998aa330c0b7e6e4f8cdcf9c0385fc
Author: wenqiao zhang <we...@zju.edu.cn>
AuthorDate: Mon Feb 28 20:15:34 2022 +0800
update the lime interpretation module
---
.../singa_easy/modules/explanations/lime/lime.py | 29 +---------------------
1 file changed, 1 insertion(+), 28 deletions(-)
diff --git a/examples/singa_easy/singa_easy/modules/explanations/lime/lime.py b/examples/singa_easy/singa_easy/modules/explanations/lime/lime.py
index 578af49..1405260 100644
--- a/examples/singa_easy/singa_easy/modules/explanations/lime/lime.py
+++ b/examples/singa_easy/singa_easy/modules/explanations/lime/lime.py
@@ -1,28 +1,6 @@
-
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
from lime import lime_image
from skimage.segmentation import mark_boundaries
-import torch
-import torch.nn.functional as F
from singa_auto.model import utils
@@ -58,13 +36,8 @@ class Lime:
self._model.eval()
- # images are size of (B, W, H, C)
- with torch.no_grad():
- images = torch.FloatTensor(images).permute(0, 3, 1, 2).to(self.device)
-
images = images.to(self.device)
logits = self._model(images).to(self.device)
- probs = F.softmax(logits, dim=1)
return probs.detach().cpu().numpy()
@@ -81,4 +54,4 @@ class Lime:
hide_rest=False)
# (M, N, 3) array of float
img_boundry = mark_boundaries(temp / 255.0, mask)
- return img_boundry * 255
\ No newline at end of file
+ return img_boundry * 255