类型错误:不支持的类型 <type 'numpy.ndarray'>

编程入门 行业动态 更新时间:2024-10-23 19:21:09
本文介绍了类型错误:不支持的类型 <type 'numpy.ndarray'>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要使用 cupy 而不是 numpy 在 GPU 中运行部分代码.所以,我只注释掉了这一行 # import numpy as np 并使用这一行而不是它 import cupy as np

I needed to run some parts of the code in GPU using cupy instead of numpy. So, I only made comment out for this line # import numpy as np and used this line instead of it 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.

how to fix this error so that use 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'>

数据这里

请问您有什么想法或建议吗?

please, your ideas or any suggestions?

推荐答案

检测也需要是 Cupy 数组.

The detections need to be a Cupy array too.

detections = np.array(net.forward())

更多推荐

类型错误:不支持的类型 <type 'numpy.ndarray'>

本文发布于:2023-11-17 08:19:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609441.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   不支持   错误   lt   type

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!