0

我是 imageAI 的新手,最近我读了一篇关于检测行人的小项目的文章。我尝试获得相同的结果,但出现了一些问题。

这是我的代码:

from imageai.Detection import ObjectDetection
import os

execution_path = os.getcwd()

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(os.path.join(execution_path , "resnet50_coco_best_v2.1.0.h5"))
detector.loadModel()
custom_objects = detector.CustomObjects(person=True, car=False)
detections = detector.detectCustomObjectsFromImage(input_image=os.path.join(execution_path , "image.png"), output_image_path=os.path.join(execution_path , "image_new.png"), custom_objects=custom_objects, minimum_percentage_probability=65)


for eachObject in detections:
    print(str(eachObject["name"]) + " : " + str(eachObject["percentage_probability"]))
    print("--------------------------------")

# show the image
from IPython.display import Image
Image("image_new.png")

有一个警告,也打印了结果:

WARNING:tensorflow:No training configuration found in the save file, so the model was *not* compiled. Compile it manually.

<ipython-input-11-277100bcf064>:11: DeprecationWarning: 'detectCustomObjectsFromImage()' function has been deprecated and will be removed in future versions of ImageAI. 
 Kindly use 'detectObjectsFromImage()' 
  detections = detector.detectCustomObjectsFromImage(input_image=os.path.join(execution_path , "image.png"), output_image_path=os.path.join(execution_path , "image_new.png"), custom_objects=custom_objects, minimum_percentage_probability=65)

WARNING:tensorflow:6 out of the last 6 calls to <function Model.make_predict_function.<locals>.predict_function at 0x7fbfc2d4df70> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for  more details.
person : 72.94188737869263
--------------------------------

这是我输入的照片: 原始照片 这是生成的照片: 新的

原照片没有盒子,新照片只有一个盒子。但是新的应该有两个盒子,根据两个人。

不知道是不是只有一个盒子是因为警告还是其他原因?有人可以帮我吗?

谢谢。

4

0 回答 0