'Invalid file: expected {0} rows.'.format(cimg)) # Read labels. res = np.fromstring(gz.read(cimg), dtype=np.uint8) finally: os.remove(gzfname) return res.reshape((cimg, 1)) if __name__ == "__main__": trnData = loadData( 'http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz', 60000) trnLbl = loadLabels( 'http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz', 60000) trn = np.hstack((trnLbl, trnData)) print 'Writing train text file...' np.savetxt(r'./../Data/Train-28x28.txt', trn, fmt='%u', delimiter='\t') convert(r'./../Data/Train-28x28.txt', r'./../Data/Train-28x28_cntk_text.txt', 1, 784, 0, 1, 10) os.remove(r'./../Data/Train-28x28.txt') print 'Done.' testData = loadData( 'http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz', 10000) testLbl = loadLabels( 'http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz', 10000) test = np.hstack((testLbl, testData)) print 'Writing test text file...' np.savetxt(r'./../Data/Test-28x28.txt', test, fmt='%u', delimiter='\t') convert(r'./../Data/Test-28x28.txt', r'./../Data/Test-28x28_cntk_text.txt', 1, 784, 0, 1, 10) os.remove(r'./../Data/Test-28x28.txt') print 'Done.'
if n[0] != 0x1080000: raise Exception('Invalid file: unexpected magic number.') # Read number of entries. n = struct.unpack('>I', gz.read(4)) if n[0] != cimg: raise Exception('Invalid file: expected {0} rows.'.format(cimg)) # Read labels. res = np.fromstring(gz.read(cimg), dtype = np.uint8) finally: os.remove(gzfname) return res.reshape((cimg, 1)) if __name__ == "__main__": trnData = loadData('http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz', 60000) trnLbl = loadLabels('http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz', 60000) trn = np.hstack((trnLbl, trnData)) print ('Writing train text file...') np.savetxt(r'./../Data/Train-28x28.txt', trn, fmt = '%u', delimiter='\t') convert(r'./../Data/Train-28x28.txt', r'./../Data/Train-28x28_cntk_text.txt', 1, 784, 0, 1, 10) os.remove(r'./../Data/Train-28x28.txt'); print ('Done.') testData = loadData('http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz', 10000) testLbl = loadLabels('http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz', 10000) test = np.hstack((testLbl, testData)) print ('Writing test text file...') np.savetxt(r'./../Data/Test-28x28.txt', test, fmt = '%u', delimiter='\t') convert(r'./../Data/Test-28x28.txt', r'./../Data/Test-28x28_cntk_text.txt', 1, 784, 0, 1, 10) os.remove(r'./../Data/Test-28x28.txt'); print ('Done.')
try: opts, args = getopt.getopt(argv, 'hf:', ['help', 'outFormat=']) except getopt.GetoptError: usage() sys.exit(1) for opt, arg in opts: if opt in ('-h', '--help'): usage() sys.exit() elif opt in ('-f', '--outFormat'): fmt = arg if fmt != 'cudnn' and fmt != 'legacy': print ('Invalid output format option.') usage() sys.exit(1) return fmt if __name__ == "__main__": fmt = parseCmdOpt(sys.argv[1:]) trn, tst = loadData('http://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz', fmt) print ('Writing train text file...') np.savetxt(r'./Train.txt', trn, fmt = '%u', delimiter='\t') convert(r'./Train.txt', r'./Train_cntk_text.txt', 1, 3072, 0, 1, 10) os.remove(r'./Train.txt'); print ('Done.') print ('Writing test text file...') np.savetxt(r'./Test.txt', tst, fmt = '%u', delimiter='\t') convert(r'./Test.txt', r'./Test_cntk_text.txt', 1, 3072, 0, 1, 10) os.remove(r'./Test.txt'); print ('Done.')