我从csv文件中提取了一系列图像的功能及其标签
data = pandas.read_csv("data.csv", delimiter=',', dtype=str)
for index, row in data.iterrows():
img = image.load_img(row['image_path'], target_size=(img_width, img_height))
trainImage = image.img_to_array(img)
trainImage = np.expand_dims(trainImage, axis=0)
在上述循环中,如何将trainImages
和trainLabels
保存到相应的数组中以传递给模型
trainLabels = np_utils.to_categorical(trainLabels, num_classes)
model.fit(trainImages, trainLabels, nb_epoch=3, batch_size=16)
答案 0 :(得分:1)
# create lists to hold data
X_train, y_train = [], []
# while looping add feature vector and labels to X_train, y_train resp.
X_train.append(trainImage)
y_train.append(trainLabel)
# convert y_train to categorical
# pass to model