Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [2704,54] vs. shape[1] = [8112,18] [Op:ConcatV2] name: concat #126

Open
VedVyapak opened this issue Jun 23, 2021 · 0 comments

Comments

@VedVyapak
Copy link

I have changed the test file according to my use in colab.

I am getting the following error:

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-90-cc7e8926b76f> in <module>()
     75     # X = np.array(pred_bbox, dtype="object")
     76     # print(X.shape)
---> 77     pred_bbox = tf.concat(pred_bbox, axis=0)
     78     bboxes = postprocess_boxes(pred_bbox, image_size, INPUT_SIZE, SCORE_THRESHOLD)
     79     bboxes = nms(bboxes, IOU_THRESHOLD , method='nms')

4 frames
/usr/local/lib/python3.7/dist-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [2704,54] vs. shape[1] = [8112,18] [Op:ConcatV2] name: concat

I have put print function many times in my code to understand the code and I have also mentioned the output in comments wherever the print function is present.
My code is

predicted_dir_path = '/content/drive/MyDrive/Okutama/mAP/predicted'
ground_truth_dir_path = '/content/drive/MyDrive/Okutama/mAP/ground-truth'

INPUT_SIZE   = 416
NUM_CLASS    = 13
CLASSES      = ['"None"\n', '"Handshaking"\n', '"Hugging"\n', '"Reading"\n', '"Drinking"\n', '"Pushing/Pulling"\n', '"Carrying"\n', '"Calling"\n', '"Running"\n', '"Walking"\n', '"Lying"\n', '"Sitting"\n', '"Standing"\n']
    

feature_maps = YOLOv4(input_layer)

bbox_tensors = []
for i, fm in enumerate(feature_maps):
    if i == 0:
        bbox_tensor = decode_train(fm, 52, 13, 8, ANCHORS = anchors, i = i, XYSCALE = xyscale)
    elif i == 1:
        bbox_tensor = decode_train(fm, 26, 13, 16, ANCHORS = anchors, i = i, XYSCALE = xyscale)
    else:
        bbox_tensor = decode_train(fm, 13, 13, 32, ANCHORS = anchors, i = i, XYSCALE = xyscale)
    bbox_tensors.append(fm)
    bbox_tensors.append(bbox_tensor)


model = tf.keras.Model(input_layer, bbox_tensors)
model.load_weights("/content/drive/MyDrive/Okutama/YoloV4_2.h5")

detetction_path = '/content/drive/MyDrive/Okutama/detection'
IOU_THRESHOLD = 0.45 
SCORE_THRESHOLD = 0.3

for num in range(len(x_test)):
    image = cv2.imread(x_test[num])
    boxes = load_annotation_test(filename=y_test[num], frame=frame_no_test[num])
    # boxes = load_annotation(filename=y_test[i%len(y_test)], frame=frame_no_test[i%len(frame_no_test)])
    # bbox_data_gt = np.array([list(map(int, box.split(','))) for box in boxes])
    bbox_data_gt = np.array(boxes)

    if len(bbox_data_gt) == 0:
        bboxes_gt=[]
        classes_gt=[]
    else:
        bboxes_gt, classes_gt = bbox_data_gt[:, :4], bbox_data_gt[:, 4]

    ground_truth_path = os.path.join(ground_truth_dir_path, str(num) + '.txt')

    image_path = x_test[0]
    image_name = image_path.split('/')[-1]

    print('=> ground truth of %s:' % image_name)
    num_bbox_gt = len(bboxes_gt)


    with open(ground_truth_path, 'w') as f:
        for i in range(num_bbox_gt):
            class_name = CLASSES[int(classes_gt[i])]
            xmin, ymin, xmax, ymax = list(map(str, bboxes_gt[i]))
            bbox_mess = ' '.join([class_name, xmin, ymin, xmax, ymax]) + '\n'
            f.write(bbox_mess)
            print('\t' + str(bbox_mess).strip())
    
    print('=> predict result of %s:' % image_name)
    predict_result_path = os.path.join(predicted_dir_path, str(num) + '.txt')
    # Predict Process.

    print(image.shape)  # (720, 1280, 3)
    image_size = image.shape[:2]
    print(image_size)    # (720, 1280)
    image_data = image_preporcess(np.copy(image), [INPUT_SIZE, INPUT_SIZE])
    print(image_data.shape)  #(416, 416, 3)
    image_data = image_data[np.newaxis, ...].astype(np.float32)
    print(image_data.shape)  #(1, 416, 416, 3)

    pred_bbox = model.predict(image_data)
    pred_bbox = [tf.reshape(x, (-1, tf.shape(x)[-1])) for x in pred_bbox]
    # X = np.array(pred_bbox, dtype="object")
    # print(X.shape)
    pred_bbox = tf.concat(pred_bbox, axis=0)
    bboxes = postprocess_boxes(pred_bbox, image_size, INPUT_SIZE, SCORE_THRESHOLD)
    bboxes = nms(bboxes, IOU_THRESHOLD , method='nms')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant