使用Python的对象检测项目
我正在做一个物体检测项目。我遇到了很多错误,我已经修复了大部分错误,只剩下一个错误了。这是我的google colab笔记本: 错误在检测部分 以下是我的检测部分的代码:使用Python的对象检测项目,python,tensorflow,machine-learning,computer-vision,object-detection,Python,Tensorflow,Machine Learning,Computer Vision,Object Detection,我正在做一个物体检测项目。我遇到了很多错误,我已经修复了大部分错误,只剩下一个错误了。这是我的google colab笔记本: 错误在检测部分 以下是我的检测部分的代码: with detection_graph.as_default(): with tf.Session(graph=detection_graph) as sess: ret = True while (ret): ret,image_np = cap.read()
with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:
ret = True
while (ret):
ret,image_np = cap.read()
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
# Each box represents a part of the image where a particular object was detected.
boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
# Each score represent how level of confidence for each of the objects.
# Score is shown on the result image, together with the class label.
scores = detection_graph.get_tensor_by_name('detection_scores:0')
classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
# Actual detection.
(boxes, scores, classes, num_detections) = sess.run(
[boxes, scores, classes, num_detections],
feed_dict={image_tensor: image_np_expanded})
# feed_dict=[image_tensor, image_np_expanded])
# Visualization of the results of a detection.
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8)
cv2.imshow('image',cv2.resize(image_np,(1280,960)))
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
cap.release()
break
这是该代码的输出或错误:
TypeError Traceback (most recent call last)
<ipython-input-22-7fd26fbacd23> in <module>()
21 (boxes, scores, classes, num_detections) = sess.run(
22 [boxes, scores, classes, num_detections],
---> 23 feed_dict={image_tensor: image_np_expanded})
24 # feed_dict=[image_tensor, image_np_expanded])
25
2 frames
/usr/local/lib/python3.6/dist-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
83
84 """
---> 85 return array(a, dtype, copy=False, order=order)
86
87
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
TypeError回溯(最近一次调用)
在()
21(框、分数、类别、数量检测)=sess.run(
22[方框、分数、等级、数量检测],
--->23 feed_dict={image_tensor:image_np_expanded})
24#feed_dict=[图像张量,图像np_展开])
25
2帧
/asarray中的usr/local/lib/python3.6/dist-packages/numpy/core//\u asarray.py(a,数据类型,顺序)
83
84 """
--->85返回数组(a,数据类型,副本=False,顺序=order)
86
87
TypeError:int()参数必须是字符串、类似字节的对象或数字,而不是“NoneType”
为了更好地理解,请从上面的链接中查看我在google colab中的完整项目。错误是因为没有提供图像。由于您无法直接从google colab打开网络摄像头,请查看如何执行此操作的答案。嗨,Zain。表单中的问题“这是我的外部代码运行程序,请为我修复它。”“我们不在这里讨论这个话题。它有两个问题:(1)问题代码需要存在于问题本身中-欢迎外部代码运行者,但不要求他们理解问题,因为问题一解决,他们就会被修复;(2) 我们希望问题作者明白他们将完成大部分工作。