gpt4 book ai didi

python - 如何将提取的特征传递给keras模型?

转载 作者:行者123 更新时间:2023-12-01 08:25:27 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com