如何为tensorflow准备我自己的数据?

时间:2016-04-24 10:28:13

标签: tensorflow deep-learning mnist

我在ubuntu 14.04上安装了Tensorflow。我完成了MNIST For ML Beginners教程。我明白了。

也不,我尝试使用自己的数据。我有数据训练为T [1000] [10]。标签为L [2],1或0。

如何访问我的数据mnist.train.images

1 个答案:

答案 0 :(得分:1)

在input_data.py中,这两个函数执行主要工作。

1。下载

def maybe_download(filename, work_directory):
    """Download the data from Yann's website, unless it's already here."""
    if not os.path.exists(work_directory):
        os.mkdir(work_directory)
    filepath = os.path.join(work_directory, filename)
    if not os.path.exists(filepath):
        filepath, _ = urlretrieve(SOURCE_URL + filename, filepath)
        statinfo = os.stat(filepath)
        print('Succesfully downloaded', filename, statinfo.st_size, 'bytes.')
    return filepath

2图片到nparray

def extract_images(filename):
    """Extract the images into a 4D uint8 numpy array [index, y, x, depth]."""
    print('Extracting', filename)
    with gzip.open(filename) as bytestream:
        magic = _read32(bytestream)
        if magic != 2051:
            raise ValueError(
                'Invalid magic number %d in MNIST image file: %s' %
                (magic, filename))
        num_images = _read32(bytestream)
        rows = _read32(bytestream)
        cols = _read32(bytestream)
        buf = bytestream.read(rows * cols * num_images)
        data = numpy.frombuffer(buf, dtype=numpy.uint8)
        data = data.reshape(num_images, rows, cols, 1)
        return data

根据您的数据集和位置,您可以致电:

local_file = maybe_download(TRAIN_IMAGES, train_dir)
train_images = extract_images(local_file)

请参阅https://github.com/nlintz/TensorFlow-Tutorials/blob/master/input_data.py的完整源代码。