类型错误:不支持的类型

2024-05-26

我需要在 GPU 中运行代码的某些部分cupy代替numpy。所以,我只对这一行做了评论# import numpy as np并用这一行代替它import cupy as np

完整代码:

from imutils.video import VideoStream
from imutils.video import FPS
# import numpy as np
import cupy as np
import argparse
import imutils
import time
import cv2
net = cv2.dnn.readNetFromCaffe('prototxt.txt', 'caffemodel')
vs = cv2.VideoCapture(0)
vs.release()
vs = cv2.VideoCapture(0)
time.sleep(2.0)
fps = FPS().start()
while True:
    ret, frame = vs.read()  # add ret,
    frame = imutils.resize(frame, width=400)
    (h, w) = frame.shape[:2]
    blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)),0.007843, (300, 300), 127.5)
    net.setInput(blob)
    detections = net.forward()
    big_area = 0
    big_center = 320
    detected = 0
    for i in np.arange(0, detections.shape[2]):
        confidence = detections[0, 0, i, 2]
        object_type = int(detections[0, 0, i, 1])
        if object_type == 15 and confidence > 0.2:
            box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
            (startX, startY, endX, endY) = box.astype("int")
            label = "{}: {:.2f}%".format('person', confidence * 100)
            cv2.rectangle(frame, (startX, startY), (endX, endY), [0, 0, 255], 2)
            y = startY - 15 if startY - 15 > 15 else startY + 15
            cv2.putText(frame, label, (startX, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, [0, 0, 255], 2)
            rect_area = (endX - startX) * (endY - startY)
            detected = 1
            if rect_area > big_area:
                big_area = rect_area
    cv2.imshow("Frame", frame)
    key = cv2.waitKey(1) & 0xFF
    if key == ord("q"):
        break
vs.release()
cv2.destroyAllWindows()

如何修复此错误以便使用 cupy.

/home/redhwan/learn1.py:26: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  confidence = detections[0, 0, i, 2]
/home/redhwan/learn1.py:27: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  object_type = int(detections[0, 0, i, 1])
/home/redhwan/learn1.py:29: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
Traceback (most recent call last):
  File "/home/redhwan/learn1.py", line 29, in <module>
    box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
  File "cupy/core/core.pyx", line 940, in cupy.core.core.ndarray.__mul__
  File "cupy/core/_kernel.pyx", line 811, in cupy.core._kernel.ufunc.__call__
  File "cupy/core/_kernel.pyx", line 89, in cupy.core._kernel._preprocess_args
TypeError: Unsupported type <type 'numpy.ndarray'>

data here https://github.com/jakelarsen17/TurtleBot-Follow-Person

请问您的想法或建议?


检测也需要是 Cupy 阵列。

detections = np.array(net.forward())
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

类型错误:不支持的类型 的相关文章

随机推荐

  • 将 Null 与 MySQL 触发器中的另一个值进行比较

    所以这是我的问题 我在更新表行时比较新值和旧值 但新值或旧值有时会为空 所以下面的代码不起作用 我可以解决这个问题吗 谢谢 BEFORE UPDATE ON mytable FOR EACH ROW BEGIN IF OLD assigne
  • 将 XMM 寄存器压入堆栈

    有没有办法将打包双字整数从 XMM 寄存器推送到堆栈 然后在需要时将其弹出 理想情况下 我正在寻找通用寄存器的 PUSH 或 POP 之类的东西 我已经检查了英特尔手册 但我要么错过了命令 要么没有 或者我是否必须将值解压到通用寄存器然后推
  • 布局中的模型破坏了其他页面

    由于缺乏 MVC4 经验 我有一个设计缺陷 问题是我的布局中有一个模型 model BasicFinanceUI Models LoginModel Content Site css rel stylesheet type text css
  • 随机字体颜色

    我需要用 2 或 3 种随机颜色为文本着色 我如何在 PHP 或 JavaScript 中执行此操作 color str pad sprintf x x x rand 0 255 rand 0 255 rand 0 255 6 rand 0
  • 使用 Gradle 在多个 Android 应用程序之间共享 Android 库

    我有 Android 应用程序 A 和 B 我想将每个应用程序中的重复代码提取到共享库 L 中 如何使用 Gradle 执行此操作 我之前见过这个问题的一些排列 但答案很少 最接近 最好的已问问题是这个 多个 Android 应用程序依赖于
  • Angular2:类型错误:无法读取未定义的属性“Symbol(Symbol.iterator)”

    我是可观察对象的新手 正在尝试 Christoph Burgdorf 的基本自动完成变体Angular2 博客中的可观察量 http blog thoughtram io angular 2016 01 07 taking advantag
  • CakePHP 中的 hasMan 简化为 hasOne

    基本上我在 CakePHP 中有以下模型 User id username Photo id user id path 我已经建立了以下关系 用户有很多照片 在一个屏幕上 我想列出用户 并在每个用户旁边显示随机照片 我尝试建立以下关系 用户
  • 如何将字符串列表转换为正确的 Python 类型?

    给定一个 python 字符串列表 如何自动将它们转换为正确的类型 意思是 如果我有 hello 3 3 64 1 我希望将其转换为列表 hello 3 3 64 1 其中第一个元素是字符串 第二个元素是 int 第三个元素是 float
  • 如何发出HTTP请求将文件从reactjs上传到googledrive?

    我对文档有点困惑 我做了我的研究 资源很少 也许有人可以帮助我 我正在使用 CRNA create react app 我有一个按钮 可以使用 URI 将文件上传到 Google Drive 我已经有了 API 密钥 客户端 ID 启用 A
  • 使用 Windows 锁定屏幕后删除 Kerberos 缓存票证

    无论如何 有没有办法阻止 Kerberos 缓存的票证在 Windows 进入锁定屏幕后被删除 首次登录 Windows 时 klist exe 显示 2 个缓存票证 但是 发生 Windows 锁屏事件后 klist exe 显示 0 个
  • C# Winform 表单中的表单

    我想打开一个表单的多个实例并将其显示在另一种表单或另一种表单的面板中 怎么做 如果您不使用 MDI 您仍然可以将一个窗体添加到另一个窗体或窗体上的面板 public Form1 InitializeComponent Form2 embed
  • Python 字典不按顺序排列

    我创建了一个字母表字典 其值从0开始 并根据单词文件增加一定的量 我对最初的字典进行了硬编码 我希望它保持按字母顺序排列 但事实并非如此 我希望它按字母顺序返回字典 基本上与初始字典保持相同 我怎样才能保持秩序 from wordData
  • NodeJS“加密”哈希似乎产生与 Crypto-JS javascript 库不同的输出

    我正在使用 NodeJS 的捆绑包crypto http nodejs org api crypto html crypto class hash服务器端 SHA256 哈希模块 在客户端 我使用一个名为的 javascript 库Cryp
  • 如何强制重装iOS模拟器?

    我想下载模拟器组件 Xcode 6 2 但在下载过程中我的互联网连接丢失了 Xcode 仍然显示我已经安装了 7 1 模拟器 你知道如何强制重装iOS模拟器吗 我已完成以下步骤 从 Library Caches com apple dt X
  • 无法在 routerOnActivate 上获取查询参数

    我在尝试使用新的路线库获取查询参数时遇到问题 VERSION2 0 0 rc 1 Problem routerOnActivate curr RouteSegment prev RouteSegment currTree RouteTree
  • 使用 pybind11 修改 std::array 的默认值

    我的目标是修改在中声明的数组C struct并赋予默认值 我读过了this https pybind11 readthedocs io en stable advanced cast stl html making opaque types
  • 如何避免在 ASP.NET 代码隐藏中编写混乱的 JavaScript?

    我想知道在 ASP NET 中使用 Javascript 的最佳实践是什么 我不知道这是否是最佳实践 但我在代码隐藏中添加了 javascript 客户端事件 它工作正常 但这是最佳实践吗 例如 我有一个单选按钮控件 并在 Page Ini
  • 如何复制/克隆一个既不派生又不派生的结构?

    我正在尝试用 Piston 进行一些游戏编程 但我正在努力解决opengl graphics Texture 因为它没有导出Copy or Clone extern crate piston window extern crate pist
  • 如何使用亚马逊商品广告 API 获取 ItemLookup/Search 的 JSON 响应

    我正在尝试从亚马逊产品的 ASIN 中获取其详细信息 产品 API 允许执行 ItemlookupASIN 但返回值在XML 我想从客户端调用 Itemlookup 所以想做一个JSONP打电话 我找不到 我在网上找到了一些将XML转换为J
  • ' aria-label='类型错误:不支持的类型 '> 类型错误:不支持的类型

    我需要在 GPU 中运行代码的某些部分cupy代替numpy 所以 我只对这一行做了评论 import numpy as np并用这一行代替它import cupy as np 完整代码 from imutils video import