Compute Library
 21.08
caffe_mnist_image_extractor Namespace Reference

Variables

 parser = argparse.ArgumentParser('Extract Caffe mnist image data')
 
 dest
 
 type
 
 str
 
 required
 
 True
 
 help
 
 default
 
 args = parser.parse_args()
 
 images_filename = os.path.join(args.dataDir, 'mnist/t10k-images-idx3-ubyte')
 
 labels_filename = os.path.join(args.dataDir, 'mnist/t10k-labels-idx1-ubyte')
 
 images_file = open(images_filename, 'rb')
 
 labels_file = open(labels_filename, 'rb')
 
 images_magic
 
 images_size
 
 rows
 
 cols
 
 labels_magic
 
 labels_size
 
 images = array('B', images_file.read())
 
 labels = array('b', labels_file.read())
 
 input10_path = os.path.join(args.outDir, 'input10.npy')
 
 input100_path = os.path.join(args.outDir, 'input100.npy')
 
 labels100_path = os.path.join(args.outDir, 'labels100.npy')
 
 outputs_10 = np.zeros(( 10, 28, 28, 1), dtype=np.float32)
 
 outputs_100 = np.zeros((100, 28, 28, 1), dtype=np.float32)
 
 labels_output = open(labels100_path, 'w')
 
float image = np.array(images[i * rows * cols : (i + 1) * rows * cols]).reshape((rows, cols)) / 256.0
 

Detailed Description

Extracts mnist image data from the Caffe data files and stores them in numpy arrays
Usage
    python caffe_mnist_image_extractor.py -d path_to_caffe_data_directory -o desired_output_path

Saves the first 10 images extracted as input10.npy, the first 100 images as input100.npy, and the
corresponding labels to labels100.txt.

Tested with Caffe 1.0 on Python 2.7

Variable Documentation

◆ args

args = parser.parse_args()

Definition at line 23 of file caffe_mnist_image_extractor.py.

◆ cols

◆ default

default

Definition at line 22 of file caffe_mnist_image_extractor.py.

◆ dest

dest

Definition at line 21 of file caffe_mnist_image_extractor.py.

◆ help

help

Definition at line 21 of file caffe_mnist_image_extractor.py.

◆ image

float image = np.array(images[i * rows * cols : (i + 1) * rows * cols]).reshape((rows, cols)) / 256.0

Definition at line 43 of file caffe_mnist_image_extractor.py.

◆ images

images = array('B', images_file.read())

Definition at line 32 of file caffe_mnist_image_extractor.py.

◆ images_file

images_file = open(images_filename, 'rb')

Definition at line 28 of file caffe_mnist_image_extractor.py.

◆ images_filename

images_filename = os.path.join(args.dataDir, 'mnist/t10k-images-idx3-ubyte')

Definition at line 25 of file caffe_mnist_image_extractor.py.

◆ images_magic

images_magic

Definition at line 30 of file caffe_mnist_image_extractor.py.

◆ images_size

images_size

Definition at line 30 of file caffe_mnist_image_extractor.py.

◆ input100_path

input100_path = os.path.join(args.outDir, 'input100.npy')

Definition at line 36 of file caffe_mnist_image_extractor.py.

◆ input10_path

input10_path = os.path.join(args.outDir, 'input10.npy')

Definition at line 35 of file caffe_mnist_image_extractor.py.

◆ labels

labels = array('b', labels_file.read())

Definition at line 33 of file caffe_mnist_image_extractor.py.

◆ labels100_path

labels100_path = os.path.join(args.outDir, 'labels100.npy')

Definition at line 37 of file caffe_mnist_image_extractor.py.

◆ labels_file

labels_file = open(labels_filename, 'rb')

Definition at line 29 of file caffe_mnist_image_extractor.py.

◆ labels_filename

labels_filename = os.path.join(args.dataDir, 'mnist/t10k-labels-idx1-ubyte')

Definition at line 26 of file caffe_mnist_image_extractor.py.

◆ labels_magic

labels_magic

Definition at line 31 of file caffe_mnist_image_extractor.py.

◆ labels_output

labels_output = open(labels100_path, 'w')

Definition at line 41 of file caffe_mnist_image_extractor.py.

◆ labels_size

labels_size

Definition at line 31 of file caffe_mnist_image_extractor.py.

◆ outputs_10

outputs_10 = np.zeros(( 10, 28, 28, 1), dtype=np.float32)

Definition at line 39 of file caffe_mnist_image_extractor.py.

◆ outputs_100

outputs_100 = np.zeros((100, 28, 28, 1), dtype=np.float32)

Definition at line 40 of file caffe_mnist_image_extractor.py.

◆ parser

parser = argparse.ArgumentParser('Extract Caffe mnist image data')

Definition at line 20 of file caffe_mnist_image_extractor.py.

◆ required

required

Definition at line 21 of file caffe_mnist_image_extractor.py.

◆ rows

◆ str

str

Definition at line 21 of file caffe_mnist_image_extractor.py.

◆ True

True

Definition at line 21 of file caffe_mnist_image_extractor.py.

◆ type

type

Definition at line 21 of file caffe_mnist_image_extractor.py.