我想在H5文件的原始文件中插入一个数组,该数组包含坐标为(0.0, 0.0)
的(x, y) coordinates
和None
值
这是我的代码:
none_matrix = np.zeros((num_images, len(skeleton_names_list), 2))
for i in range(num_images):
for j in range(len(skeleton_names_list)):
none_matrix[i][j] = None
hf.create_dataset('annotations', shape=(num_images, len(skeleton_names_list), 2), dtype=np.float64, data=none_matrix)
# hf.create_dataset('annotated', shape=(num_images, len(skeleton_names_list)), dtype=bool)
joints_coordinates = []
num_ann = 0
j_file = open('dog.json')
j_data = json.load(j_file)
for xy in j_data:
joints_coordinates.append(xy['joints'])
image_name = xy['segmentation_path']
image_index = idx_dict.get(image_name)
for i in range(len(skeleton_names_list)):
if joints_coordinates[num_ann][i][0] + joints_coordinates[num_ann][i][1] == 0:
joints_coordinates[num_ann][i] = None
hf["annotations"][image_index] = joints_coordinates[num_ann]
# hf["annotated"][image_index] = np.ones(len(skeleton_names_list), int)
num_ann += 1
为什么会出现这个错误?
Traceback (most recent call last):
File "C:/Users/Alberto Ursino/Desktop/IntellIj Local Files/Write on H5/write.py", line 120, in <module>
hf["annotations"][image_index] = joints_coordinates[num_ann]
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "C:\Users\Alberto Ursino\anaconda3\envs\TensorFlow 1x\lib\site-packages\h5py\_hl\dataset.py", line 707, in __setitem__
for fspace in selection.broadcast(mshape):
File "C:\Users\Alberto Ursino\anaconda3\envs\TensorFlow 1x\lib\site-packages\h5py\_hl\selections.py", line 299, in broadcast
raise TypeError("Can't broadcast %s -> %s" % (target_shape, self.mshape))
TypeError: Can't broadcast (37,) -> (37, 2)
joints_coordinates
的格式为:
[[[x, y], ...], ...]
发布于 2020-12-10 12:13:56
在此处编写np.nan
而不是None
:
for i in range(len(skeleton_names_list)):
if joints_coordinates[num_ann][i][0] + joints_coordinates[num_ann][i][1] == 0:
joints_coordinates[num_ann][i] = None
成功了!
https://stackoverflow.com/questions/65186603
复制相似问题