interpretation_predict.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import numpy as np
  15. def interpretation_predict(model, images):
  16. model.arrange_transforms(
  17. transforms=model.test_transforms, mode='test')
  18. new_imgs = []
  19. for i in range(images.shape[0]):
  20. img = images[i]
  21. new_imgs.append(model.test_transforms(img)[0])
  22. new_imgs = np.array(new_imgs)
  23. result = model.exe.run(
  24. model.test_prog,
  25. feed={'image': new_imgs},
  26. fetch_list=list(model.explanation_feats.values()))
  27. return result