本文整理汇总了Python中mnist.MNIST.train_images方法的典型用法代码示例。如果您正苦于以下问题:Python MNIST.train_images方法的具体用法?Python MNIST.train_images怎么用?Python MNIST.train_images使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mnist.MNIST
的用法示例。
在下文中一共展示了MNIST.train_images方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from mnist import MNIST [as 别名]
# 或者: from mnist.MNIST import train_images [as 别名]
filename = os.path.basename(url)
if filename.split(".")[0] not in os.listdir(mndata_dir):
print "Downloading File: %s" % mnist_data_files[key]
r = requests.get(mnist_data_files[key], stream=True)
compressed_file=StringIO.StringIO()
compressed_file.write(r.content)
compressed_file.seek(0)
decompressed = gzip.GzipFile(fileobj=compressed_file, mode='rb')
with open(os.path.join(mndata_dir, filename.split(".")[0]),'wb') as handle:
handle.write(decompressed.read())
mndata = MNIST(mndata_dir)
if os.path.exists(mndata_file):
js = simplejson.load(open(mndata_file, 'r'))
mndata.train_images = js['train_data']
mndata.train_labels = js['train_labels']
mndata.test_images = js['test_data']
mndata.test_labels = js['test_labels']
else:
mndata.load_training()
mndata.load_testing()
js = {"train_data": mndata.train_images, "train_labels": mndata.train_labels.tolist(),
"test_data": mndata.test_images, "test_labels": mndata.test_labels.tolist()}
simplejson.dump(js, open(mndata_file, 'w'))
size = numpy.sqrt(len(mndata.train_images[0]))
mndata.train_images = numpy.array(mndata.train_images)