我正在尝试在我的Macbook上加载一组.jpg图像作为tensorflow的训练数据集,我使用的代码复制如下:
def load_data(dir_name, size=None, ext='.jpg'):
images = []
labels = []
for ln in os.listdir(dir_name):
new_dir_name = os.path.join(dir_name, ln)
for fn in os.listdir(new_dir_name):
if fn.endswith(ext):
fd = os.path.join(new_dir_name, fn)
images.append(load_image(fd, size))
labels.append(load_label(new_dir_name))
return {'images':np.vstack(np.array(images, dtype=np.float32)), 'labels':np.vstack(np.array(labels, dtype=np.float32))}
它转向触发ValueError,如下所示:
line 11, in load_data
return {'images':np.vstack(np.array(images, dtype=np.float32)), 'labels':np.vstack(np.array(labels, dtype=np.float32))}
ValueError: setting an array element with a sequence.
我该如何解决?