I want to insert in a raw of my H5 file an array containing (x, y) coordinates
and None
values where the coordinates are (0.0, 0.0)
:
This is my code:
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
Why do I get this error?
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
is in the form:
[[[x, y], ...], ...]
Writing np.nan
instead of None
here:
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
works!
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.