gpt4 book ai didi

python - 断言 'GDK_IS_DISPLAY (display)' 失败 - 无法确定以下参数 : data 的类型

转载 作者:行者123 更新时间:2023-12-02 16:11:35 27 4
gpt4 key购买 nike

我正在做一个车辆跟踪和计数程序。当我尝试运行这段代码时遇到错误:

import mxnet
import gluoncv as gcv
import cv2.cv2 as cv2
import matplotlib.pyplot as plt
import math
import numpy as np
import gluoncv.data.transforms.image as image
import time

def main():
ctx = mxnet.gpu(1)
# This bunch of codes used to recognise specific classes

classes = ["Motorbike", "Car/Van"]
net = gcv.model_zoo.get_model("ssd_512_resnet50_v1_voc", pretrained=True, ctx=ctx)
net.reset_class(classes)
net.load_parameters("vehicle_best.params")

cap = cv2.VideoCapture("tang2ngay3_10video2.mp4")
out = cv2.VideoWriter("result_video.mp4", 0x7634706d, 30.0, (910, 512))

frame_number = 0
counting_point = 750
nof_vehicle = [0] * len(classes)
tracks_active = []
start = time.time()
while (cap.isOpened()):

ret, frame = cap.read()

if ret == False:
break
# if frame_number == 100:
# break


frame = mxnet.nd.array(frame)

img_tf, _ = gcv.data.transforms.presets.ssd.transform_test(frame, short=512)
frame = frame.asnumpy().astype('uint8')
frame = cv2.resize(frame, (910, 512))

class_IDs, scores, detections = net(img_tf.copyto(ctx))

class_IDs = class_IDs.squeeze().asnumpy()
scores = scores.squeeze().asnumpy()
detections = detections.squeeze().asnumpy()

predicts = []
for idx, det in enumerate(detections):
xmin, ymin, xmax, ymax = det
if scores[idx] > 0.5 and xmin + (xmax - xmin) / 2 < counting_point + 10:
# if scores[idx] > 0.5 and ymin + (ymax - ymin) / 2 < counting_point + 10:
predicts.append({"id": class_IDs[idx], "score": scores[idx], "bbox": list(det)})

updated_tracks = []

for obj in tracks_active:
# update information of vehicle
if len(predicts) > 0:

best_match = max(predicts, key=lambda x: iou(obj["bbox"], x["bbox"]))

if iou(obj["bbox"], best_match["bbox"]) >= 0.5:
obj["bbox"] = best_match["bbox"]
if best_match["score"] > obj["score"]:
obj["score"] = best_match["score"]
obj["id"] = best_match["id"]
xmin, ymin, xmax, ymax = obj["bbox"]
if xmin + (xmax - xmin) / 2 > counting_point and obj["is_counted"] == False:
# if ymin + (ymax - ymin) / 2 > counting_point and obj["is_counted"] == False:
nof_vehicle[int(obj["id"])] += 1
obj["is_counted"] = True
updated_tracks.append(obj)
del predicts[predicts.index(best_match)]

new_objects = [{"id": pred["id"], "score": pred["score"], "bbox": pred["bbox"], "is_counted": False} for pred in predicts]
tracks_active = updated_tracks + new_objects
bboxes = []
ids = []

for track in tracks_active:
if (track["is_counted"] == False):
bboxes.append(track["bbox"])
ids.append(int(track["id"]))

bboxes = np.array(bboxes)
ids = np.array(ids)
colors = {0: (82, 7, 242), 1: (215, 242, 5)}

frame = gcv.utils.viz.cv_plot_bbox(frame, bboxes, labels=ids, class_names=classes, colors=colors)

frame_number += 1

cv2.line(frame, (counting_point, 0), (counting_point, 512), (0, 255, 0), 2)
for i in range(len(classes)):
text = "{} : {:d}".format(classes[i], nof_vehicle[i])
cv2.putText(frame, text, (10, 20 * (i + 1)), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 0), 1)
out.write(frame)
end = time.time()
print("Total time: {}".format(end - start))
print("FPS: {}",format(frame_number / (end - start)))
cap.release()
out.release()

if __name__ == "__main__":
main()

我不确定错误是什么意思。
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused

(vehicle.py:12794): Gdk-CRITICAL **: 08:57:21.070: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
/home/hangnguyen/.local/lib/python3.6/site-packages/mxnet/gluon/block.py:1389: UserWarning: Cannot decide type for the following arguments. Consider providing them as input:
data: None
input_sym_arg_type = in_param.infer_type()[0]
terminate called after throwing an instance of 'dmlc::Error'
what(): [08:57:21] src/ndarray/ndarray.cc:1288: GPU is not enabled
Stack trace:
[bt] (0) /home/hangnguyen/.local/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x307d3b) [0x7f365b03dd3b]
[bt] (1) /home/hangnguyen/.local/lib/python3.6/site-packages/mxnet/libmxnet.so(mxnet::CopyFromTo(mxnet::NDArray const&, mxnet::NDArray const&, int, bool)+0x6db) [0x7f365e31628b]

我尝试在 google 和 StackOverflow 上查找它,但似乎没有人有这个错误。我能找到的最接近的文章是 this one ,但我已经安装了 mxnet 1.6。我在远程服务器上运行此代码,这是问题吗?

谁能帮帮我?非常感谢。

最佳答案

您可以尝试安装此库并检查

pip install opencv-contrib-python

关于python - 断言 'GDK_IS_DISPLAY (display)' 失败 - 无法确定以下参数 : data 的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62143783/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com