8

ubuntu 14.04 に Tensorflow をインストールします。MNIST For ML Beginnersチュートリアルを完了しました。私はそれを理解しました。

また、自分のデータを使用しようとします。T[1000][10]として列車データがあります。ラベルは L[2]、1 または 0 です。

どうすれば自分のデータにアクセスできますmnist.train.imagesか?

4

1 に答える 1

1

input_data.py では、これら 2 つの関数が主な役割を果たします。

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で完全なソース コードを参照してください。

于 2016-04-24T22:56:43.453 に答える