我拍摄了一堆图像,将它们转换为灰色,然后将其存储到img_data_list中,然后将它们转换为一个numpy数组,一切正常,直到现在这部分代码起作用为止
import cv2
import os
import numpy as np
people = ['s1', 's2']
num_classes = 2
img_data_list = []
labels = []
valid_images = [".jpg",".gif",".png"]
for index, person in enumerate(people):
print(index)
dir_path = 'I:\\project_face_detection\\face_detetion\\training_data\\' + person
for img_path in os.listdir(dir_path):
name, ext = os.path.splitext(img_path)
if ext.lower() not in valid_images:
continue
img_data = cv2.imread(dir_path + '\\' + img_path)
# convert image to gray
img_data=cv2.cvtColor(img_data, cv2.COLOR_BGR2GRAY)
img_data_list.append(img_data)
labels.append(index)
img_data = np.array(img_data_list)
但是当我尝试将数组转换为float32数据类型时,出现ValueError
img_data = img_data.astype('float32')
这是错误
ValueError: setting an array element with a sequence.
这是我的图像存储方式
- training_data
- s1
- 0.jpg
- 1.jpg
- s2
- 0.jpg
- ......
如果你们能以任何方式帮助我,我将不胜感激,感谢您的关注:)。