In input_data.py, queste due funzioni fanno il lavoro principale.
1. Scaricare
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 immagine per 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
Sulla base di set di dati e la posizione, è possibile chiamare:
local_file = maybe_download(TRAIN_IMAGES, train_dir)
train_images = extract_images(local_file)
vedere il codice sorgente completo https://github.com/nlintz/TensorFlow-Tutorials/blob/master/input_data.py .
fonte
2016-04-24 22:56:43
Hai estratto input_data.py? Penso che otterrai alcune idee dal file. –
Lo controllo. https://github.com/tensorflow/tensorflow/blob/r0.8/tensorflow/examples/tutorials/mnist/input_data.py Ma non sottovaluto come installare e analizzare i dati. –
Lo script scarica e importa automaticamente il set di dati. Voglio farlo da solo –