简体   繁体   中英

numpy IndexError: index 1 is out of bounds for axis 3 with size 1

How should I fix this error?

if frames_pose2d:
    print('valid count: ', valid_frame_count)
    tmp_keypoints = np.vstack([frames_pose2d[fn] for fn in range(valid_frame_count)])
    tmp_keypoints_x = np.vstack([frames_pose2d_x[fn] for fn in range(valid_frame_count)])
    tmp_keypoints_y = np.vstack([frames_pose2d_y[fn] for fn in range(valid_frame_count)])
    filler = np.zeros((max_num_frames-valid_frame_count, 26))
    filler_x = np.zeros((max_num_frames-valid_frame_count, 13))
    filler_y = np.zeros((max_num_frames-valid_frame_count, 13))
    keypoints = np.concatenate((tmp_keypoints, filler))
    keypoints_x = np.concatenate((tmp_keypoints_x, filler_x))
    keypoints_y = np.concatenate((tmp_keypoints_y, filler_y))
    print("tmp kps shape: ", tmp_keypoints.shape)
    print("tmp kps_x shape: ", tmp_keypoints_x.shape)
    print("tmp kps_y shape: ", tmp_keypoints_y.shape)
    print("kps shape: ", keypoints.shape)
    print("kps_x shape: ", keypoints_x.shape)
    print("kps_y shape: ", keypoints_y.shape)
    print("joint2d shape: ", joints2d.shape)
    joints2d[0, :, :, person_index] = keypoints_x
    joints2d[1, :, :, person_index] = keypoints_y
    joints_data.append(joints2d)

Error is:

  0%|                                                                                                        | 0/2 [00:00<?, ?it/s]valid count:  1598
tmp kps shape:  (1598, 26)
tmp kps_x shape:  (1598, 13)
tmp kps_y shape:  (1598, 13)
kps shape:  (3493, 26)
kps_x shape:  (3493, 13)
kps_y shape:  (3493, 13)
joint2d shape:  (2, 3493, 13, 1)
  0%|                                                                                                        | 0/2 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "process_jsons.py", line 76, in <module>
    joints2d[0, :, :, person_index] = keypoints_x
IndexError: index 1 is out of bounds for axis 3 with size 1
joints2d[0, :, :, 0] = keypoints_x
joints2d[1, :, :, 0] = keypoints_y

I realized my person_index was wrong and it should have been 0. Thanks to Reti43 for walking me through my thoughts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM