跳到主要内容

10 篇博文 含有标签「AI」

查看所有标签

MNIST数据集解析

· 阅读需 4 分钟

MNIST数据集官网可以下载MNIST数据集。

MNIST数据集以.gz格式压缩,Python可以直接读取而不需要解压缩:

import gzip

with gzip.open('t10k-images-idx3-ubyte.gz') as f:
buf = f.read()

MNIST数据集使用二进制文件,而不是常规的图片文件格式。以t10k-images-idx3-ubyte为例,在官网有其结构说明:

[offset] [type]          [value]          [description]
0000 32 bit integer 0x00000803(2051) magic number
0004 32 bit integer 10000 number of images
0008 32 bit integer 28 number of rows
0012 32 bit integer 28 number of columns
0016 unsigned byte ?? pixel
0017 unsigned byte ?? pixel
........
xxxx unsigned byte ?? pixel

TensorFlow基础入门

· 阅读需 2 分钟

TensorFlow安装

CPU版本直接pip install tf-nightly即可。

GPU版本需要安装显卡驱动、cuda、cudnn,注意版本。若手动安装cuda还要将cuda的lib64目录加入LD_LIBRARY_PATH环境变量。然后使用pip install tf-nightly-gpu安装即可。

在Python中一般使用

import tensorflow as tf

来import tensorflow。

Numpy使用教程(二)

· 阅读需 10 分钟

numpy随机抽样

随机数生成

numpy.random.rand(d0, d1, ..., dn) 方法的作用为:指定一个数组,并使用 [0, 1) 区间随机数据填充,这些数据均匀分布。

In [1]: import numpy as np

In [2]: np.random.rand(2,3)
Out[2]:
array([[ 0.09887339, 0.75074537, 0.9944429 ],
[ 0.92790081, 0.84365033, 0.3087985 ]])

Numpy使用教程(一)

· 阅读需 5 分钟

术语

axis

对于二维数组,垂直为轴0,水平为轴1。许多操作可以沿着一个轴进行。

>>> x = np.arange(12).reshape(3,4)
>>> x
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
>>> x.sum(axis=0)
array([12, 15, 18, 21])
>>> x.sum(axis=1)
array([ 6, 22, 38])