Tensorflow - TypeError:int()参数必须是字符串

时间:2018-01-30 19:05:14

标签: python opencv tensorflow

我在tensorflow上执行对象检测时遇到问题。它工作但现在不行。你可以找到错误的打击..

错误

Traceback (most recent call last):
  File "object_detection_CONVERRTED.py", line 166, in <module>
    feed_dict={image_tensor: image_np_expanded})
  File "/home/just/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 895, in run
    run_metadata_ptr)
  File "/home/just/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1093, in _run
    np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
  File "/home/just/anaconda3/lib/python3.6/site-packages/numpy/core/numeric.py", line 531, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

您还可以找到产生错误的行:

  # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
  image_np_expanded = np.expand_dims(image_np, axis=0)
  # Actual detection.
  (boxes, scores, classes, num) = sess.run(
      [detection_boxes, detection_scores, detection_classes, num_detections],
      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('object detection',cv2.resize(image_np,(800,600)))

2 个答案:

答案 0 :(得分:0)

当流式传输失败或结束时会发生这种情况。 即

ret, image_np = cap.read()
print(image_np is None)
  

//检查此评估是否为True

当流式传输失败时,您可以通过提供额外条件退出while循环

if ret == 0:
    break

答案 1 :(得分:0)

我解决了这个问题。这是因为视频格式。当我将视频格式avi转换为mp4时,它可以工作。

但现在我有不同的问题。

Traceback (most recent call last):
  File "object_detection_tutorial_CONVERRTED.py", line 175, in <module>
    cv2.imshow('object detection',cv2.resize(image_np,(800,600)))
cv2.error: /tmp/build/80754af9/opencv_1512687413662/work/modules/highgui/src/window.cpp:611: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage

您对此错误有任何疑问吗?感谢您的关注。