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

标签 python tensorflow keras

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

相关文章:

python - 拟合 Keras 序列模型给出 ValueError : Failed to convert a NumPy array to a Tensor (Unsupported object type numpy. ndarray)

python - 如何在 Keras 中使用创建的 CNN 模型和新数据

c++ - 尝试将参数从简单的 Python 函数发送到 C++

python - Django - 暂停/停用帐户 N 秒

python - "zsh: illegal hardware instruction python"在 macbook pro M1 上安装 Tensorflow 时

python - IO错误 : [Errno 28] No space left on device while installing TensorFlow

python - 为什么这个 Keras Conv2D 层与输入不兼容?

python - BeautifulSoup - <em> 给我的结果带来麻烦

python - TF.Learn DNNClassifier 和 LinearClassifier 的准确性问题

tensorflow - TF 数据 API : how to efficiently sample small patches from images