我从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)


在上述循环中,如何将trainImagestrainLabels保存到相应的数组中以传递给模型

trainLabels = np_utils.to_categorical(trainLabels, num_classes)
model.fit(trainImages, trainLabels, nb_epoch=3, batch_size=16)

最佳答案

# 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

关于python - 如何将提取的特征传递给keras模型?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54281724/

10-12 23:04