I am working on a object detection project. I faced a lot of errors and I have fixed most of them, and there is only one error left. Here is my google colab notebook: https://colab.research.google.com/drive/19mvzDGr0BTV_FgvGwT4DbwccYnPF7SMu.
The error was in the detection part.
Here is the code of my detection part:
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
And this is the output or error of this code:
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'
For better understanding please checkout my full project in google colab from the above link.
The error is because there are no images being fed. As you can't open your webcam directly from Google Colab, have a look at the answer to this question on how to do it.