使用Keras进行特征提取不包括类标签

时间:2018-06-16 12:51:39

标签: machine-learning keras feature-extraction convolutional-neural-network

我使用Keras在MNIST数据集上应用图像分类,实现可用here。我使用此实现,但添加以下方法从训练图像中提取特征:

def feature_extraction(model, x_test, path_to_save):
    extract = keras.Model(inputs=model.input, outputs=model.get_layer('dense_1').output)
    features = extract.predict(x_test)
    np.savetxt(path_to_save, features, delimiter=",")

输出文件不包含类标签,即文件中的每一行都是一组功能但没有类标签。有没有办法修改此方法,以便它还添加每个提取的功能(即每一行)的类标签?

1 个答案:

答案 0 :(得分:1)

您可以获得多个输出,因此功能和预测标签概率都是:

np.argmax

预测现在会给你两个输出。您可能希望#include <unistd.h> #include <sys/types.h> uid_t getuid(void); uid_t geteuid(void); 获取实际的类标签,而不是取决于模型的概率。