RuntimeWarning:exp(imageai)中遇到溢出

时间:2019-10-20 19:14:46

标签: python python-3.x tensorflow object-detection yolo

我正在研究/正在研究图像检测。

我正在关注this tutorial

我更改了检测代码以支持多幅图像输入:

from imageai.Detection.Custom import CustomObjectDetection
import os

detector = CustomObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath("PhoHast.h5") 
detector.setJsonPath("detection_config.json")
detector.loadModel()
diretorio = "hololens/validation/images/"
directory = os.fsencode(diretorio)
for file in os.listdir(directory):
    filename = os.fsdecode(file)
    detections = detector.detectObjectsFromImage(input_image=diretorio+filename, output_image_path=diretorio+filename+"-detected.jpg")
    for detection in detections:
        print(detection["name"], " : ", detection["percentage_probability"], " : ", detection["box_points"])

因此,当我运行代码时,我会在终端中获得以下输出:

hololens  :  70.00470757484436  :  [122, 37, 179, 64]
hololens  :  61.76692247390747  :  [164, 26, 283, 100]
hololens  :  58.87643098831177  :  [8, 39, 263, 167]
hololens  :  53.12047004699707  :  [15, 31, 68, 56]
hololens  :  65.72685837745667  :  [177, 23, 258, 52]
hololens  :  55.395132303237915  :  [83, 29, 143, 50]
hololens  :  58.40786099433899  :  [128, 19, 176, 52]
/home/username/.virtualenvs/test1/lib/python3.6/site-packages/imageai/Detection/Custom/__init__.py:1234: RuntimeWarning: overflow encountered in exp
  return 1. / (1. + np.exp(-x))
hololens  :  64.8678719997406  :  [110, 16, 236, 93]
hololens  :  52.41330862045288  :  [31, 58, 213, 135]
hololens  :  61.7838978767395  :  [240, 11, 304, 38]
hololens  :  57.54014849662781  :  [202, 36, 240, 60]
hololens  :  50.5328893661499  :  [124, 21, 190, 51]
hololens  :  62.890440225601196  :  [64, 28, 179, 135]
hololens  :  68.86326670646667  :  [21, 46, 127, 142]
hololens  :  62.89368271827698  :  [165, 8, 235, 39]
hololens  :  58.59404802322388  :  [110, 31, 158, 58]
hololens  :  51.92608833312988  :  [205, 0, 283, 119]

因此,在输出中,我得到了以下警告:

/home/username/.virtualenvs/test1/lib/python3.6/site-packages/imageai/Detection/Custom/__init__.py:1234: RuntimeWarning: overflow encountered in exp
  return 1. / (1. + np.exp(-x))

对此的解释是:

  

不幸的是,在计算大于709(709.7827)或小于-745(-745.133)的值的exp时,Numpy有一些局限性,对于数据集,加权和的值约为881.52149758和-804.364266793 。 Numpy产生了此警告-RuntimeWarning:exp中遇到溢出-显然,这是Python的局限性。尝试使用Numpy或仅使用Python计算710或-746的exp。

作者在this link中为其代码提供了解决方案。

如何为我的代码实施解决方案?

0 个答案:

没有答案