python - 使用 UCI 数据集进行 Tensorflow 数据处理

标签 python tensorflow machine-learning neural-network mnist

我正在尝试使用 Tensorflow 识别 UCI 数据集( https://archive.ics.uci.edu/ml/datasets/Optical+Recognition+of+Handwritten+Digits )的手写数字。其中每行都是图像像素的展平 8*8 矩阵,最后一个属性是类代码 0-9。 然而,我遵循的教程是关于 MNIST 数据的,这是完全不同的。它有一个 28*28 的矩阵,值为 0-255。所以,事情是这样的:

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data", one_hot=True)
x = tf.placeholder('float', [None, 784])
y = tf.placeholder('float')

由于我对 Tensorflow 还很陌生,因此无法为 UCI 数据准备神经网络模型。我只是想要一些关于如何进行的指导。我有 2 个主要问题。

  1. 这是导入数据的正确方法吗?
  2. 如何获取“y”标签作为最后一个属性?

目前我正在考虑做这样的事情:

filename_queue = tf.train.string_input_producer(["optdigits.tra"])
reader = tf.TextLineReader()
_, serialized_example = reader.read(filename_queue)
image,label = decode(serialized_example)
x = tf.placeholder('float', [None, 64])
y = tf.placeholder('float')

基本上,我想准备一个具有 64 个节点的输入层和一个带有输出的 'y' 标签,以训练 NN 模型

最佳答案

我也是新人,这可能不是一个好方法。 我使用numpy导入数据,然后将其转换为tensorflow格式。

import tensorflow as tf
import numpy as np

trainingDataSet_ = np.loadtxt('/data/optdigits.tra', delimiter=',');
trainingDataSet = tf.convert_to_tensor(trainingDataSet_, np.int32)

# store labels of each sample
y = trainingDataSet[:, 64]

# remove lables from features
x = trainingDataSet[:, :64]

关于python - 使用 UCI 数据集进行 Tensorflow 数据处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49093207/

相关文章:

python - reshape pandas 数据框 : New row for every 76 entries

python - 循环打印

neural-network - 为什么 dropout 会阻止卷积神经网络的收敛?

python - 训练后如何同时获得分数和准确率

python - 如何将损失函数中的变量存储到实例变量中

python - IDLE 和命令行之间的性能差异。 IDLE 表现更好的地方

python - 用线条替换 QTextEdit 边界框

python - Keras my_layer.output 返回 KerasTensor 对象而不是 Tensor 对象(在自定义损失函数中)

在 OSX 上使用 Docker 时出现 Tensorflow Serving 编译错误

python - 如何在核密度估计中找到局部最大值?