首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅使用imageai.Detection检测单个人

仅使用imageai.Detection检测单个人
EN

Stack Overflow用户
提问于 2022-01-27 19:27:04
回答 1查看 68关注 0票数 0

我是imageAI的新手,最近我读到了一篇关于探测行人的小项目的文章。我试图得到同样的结果,但也出现了一些问题。

这是我的代码:

代码语言:javascript
复制
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")

有一个警告和打印的结果:

代码语言:javascript
复制
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
--------------------------------

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

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

我不知道是不是只有一个盒子是因为警告还是别的什么原因?有人能帮我吗?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2022-07-19 14:35:11

这是我使用的代码,我认为ImageAI在运行时使用box_points来区分多个对象,这可能是非常错误的。

代码语言:javascript
复制
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("--------------------------------")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70884590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档