我是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
--------------------------------原来的照片没有盒子,而新的只有一个盒子。但是根据两个人的说法,新的盒子应该有两个盒子。
我不知道是不是只有一个盒子是因为警告还是别的什么原因?有人能帮我吗?
谢谢。
发布于 2022-07-19 14:35:11
这是我使用的代码,我认为ImageAI在运行时使用box_points来区分多个对象,这可能是非常错误的。
for eachObject, eachObjectPath in zip(detections, objects_path):
print(eachObject["name"] , " : " , eachObject["percentage_probability"], " : ", eachObject["box_points"] )
print("Object's image saved in " + eachObjectPath)
print("--------------------------------")https://stackoverflow.com/questions/70884590
复制相似问题