我正在尝试使用 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 个主要问题。
- 这是导入数据的正确方法吗?
- 如何获取“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/