nicknochnack / RealTimeObjectDetection

370 stars 587 forks source link

Dimension issue #28

Open Annieliaquat opened 2 years ago

Annieliaquat commented 2 years ago

Can someone help me out on how to resolve this issue. It was first detecting the test image in colab but when I run it again it gives me this error. And when it gives me the bounding box on the test image, the font size is too small. I have tried different methods but its not working. I am doing all this training and testing in colab.

Here is the code. Object detection Api setup runs successfully and model is trained and tested. img = cv2.imread(IMAGE_PATH) image_np = np.array(img)

input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32) detections = detect_fn(input_tensor)

num_detections = int(detections.pop('num_detections')) detections = {key: value[0, :num_detections].numpy() for key, value in detections.items()} detections['num_detections'] = num_detections

detection_classes should be ints.

detections['detection_classes'] = detections['detection_classes'].astype(np.int64) label_id_offset = 1 image_np_with_detections = image_np.copy()

viz_utils.visualize_boxes_and_labels_on_image_array( image_np_with_detections, detections['detection_boxes'], detections['detection_classes']+label_id_offset, detections['detection_scores'], category_index, use_normalized_coordinates=True, line_thickness=9, max_boxes_to_draw=5, min_score_thresh=.3, agnostic_mode=False)

image=cv2.resize(image_np_with_detections,(1500, 800),interpolation = cv2.INTER_NEAREST) plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) plt.show()

Here is the error

File "/content/drive/MyDrive/Tensorflow/Research/models/research/object_detection/core/preprocessor.py", line 3327, in resize_image * new_image = tf.image.resize_images(

ValueError: 'images' must have either 3 or 4 dimension
kumarpriyanshu2k2 commented 2 years ago

Your camera is not taking the input make sure you have deleted the extra cap.release() cell and try to alter the numbers in cv2.VideoCapture(number) mostly its either 0 or 1

Annieliaquat commented 2 years ago

Your camera is not taking the input make sure you have deleted the extra cap.release() cell and try to alter the numbers in cv2.VideoCapture(number) mostly its either 0 or 1

No I am not using camera. I am detecting using image stored in a folder. This error is removed now thank you for your reply. Kindly can you guide me on my second problem which I have already asked above. This problem "And when it gives me the bounding box on the test image, the font size is too small. I have tried different methods but its not working. I am doing all this training and testing in colab." Please if you can give some guidance