[英]Only detect a single person using imageai.Detection
I am new to imageAI and recently I read an article about a small project of detecting pedestrians.我是 imageAI 的新手,最近我读了一篇关于检测行人的小项目的文章。 I try to get the same result, but some problems occurred.
我尝试获得相同的结果,但出现了一些问题。
Here is my code:这是我的代码:
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")
There's a warning and also the result printed:有一个警告,也打印了结果:
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
--------------------------------
Here is the photo I input: original And here is the resulting photo: new这是我输入的照片:原始照片 这是生成的照片:新的
The original photo has no box, and the new one has only one box.原照片没有盒子,新照片只有一个盒子。 But the new one should have two boxes according to two persons.
但是新的应该有两个盒子,根据两个人。
I don't know if only one box is due to the warning or something else?不知道是不是只有一个盒子是因为警告还是其他原因? Could someone help me out?
有人可以帮我吗?
Thanks.谢谢。
This is the code i use, i think ImageAI uses the box_points while running to differentiate between multiple objects, could be very wrong tho.这是我使用的代码,我认为 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("--------------------------------")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.