提交 ebfbc23e 编写于 作者: X xiaoting 提交者: lvmengsi

update recognize readme (#780)

* modified reademe
上级 43d144e9
...@@ -396,15 +396,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() ...@@ -396,15 +396,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
# 调用train_program 获取预测值,损失值, # 调用train_program 获取预测值,损失值,
prediction, [avg_loss, acc] = train_program() prediction, [avg_loss, acc] = train_program()
# 输入的原始图像数据,大小为28*28*1 # 输入的原始图像数据,名称为img,大小为28*28*1
img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')
# 标签层,名称为label,对应输入图片的类别标签 # 标签层,名称为label,对应输入图片的类别标签
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
# 告知网络传入的数据分为两部分,第一部分是img值,第二部分是label值 # 告知网络传入的数据分为两部分,第一部分是img值,第二部分是label值
feeder = fluid.DataFeeder(feed_list=[img, label], place=place) feeder = fluid.DataFeeder(feed_list=[img, label], place=place)
# 选择Adam优化器 # 选择Adam优化器
optimizer = fluid.optimizer.Adam(learning_rate=0.001) optimizer = optimizer_program()
optimizer.minimize(avg_loss) optimizer.minimize(avg_loss)
``` ```
...@@ -528,9 +526,13 @@ Test with Epoch 0, avg_cost: 0.053097883707459624, acc: 0.9822850318471338 ...@@ -528,9 +526,13 @@ Test with Epoch 0, avg_cost: 0.053097883707459624, acc: 0.9822850318471338
```python ```python
def load_image(file): def load_image(file):
# 读取图片文件,并将它转成灰度图
im = Image.open(file).convert('L') im = Image.open(file).convert('L')
# 将输入图片调整为 28*28 的高质量图
im = im.resize((28, 28), Image.ANTIALIAS) im = im.resize((28, 28), Image.ANTIALIAS)
# 将图片转换为numpy
im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32) im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32)
# 对数据作归一化处理
im = im / 255.0 * 2.0 - 1.0 im = im / 255.0 * 2.0 - 1.0
return im return im
......
...@@ -377,14 +377,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() ...@@ -377,14 +377,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
prediction, [avg_loss, acc] = train_program() prediction, [avg_loss, acc] = train_program()
# input original image data in size of 28*28*1 # input original image data in size of 28*28*1
img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')
# label layer, called label, correspondent with label category of input picture. # label layer, called label, correspondent with label category of input picture.
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
# It is informed that data in network consists of two parts. One is img value, the other is label value. # It is informed that data in network consists of two parts. One is img value, the other is label value.
feeder = fluid.DataFeeder(feed_list=[img, label], place=place) feeder = fluid.DataFeeder(feed_list=['img', 'label'], place=place)
# choose Adam optimizer # choose Adam optimizer
optimizer = fluid.optimizer.Adam(learning_rate=0.001) optimizer = optimizer_program()
optimizer.minimize(avg_loss) optimizer.minimize(avg_loss)
``` ```
...@@ -513,9 +512,13 @@ You can use trained model to classify handwriting pictures of digits. The progra ...@@ -513,9 +512,13 @@ You can use trained model to classify handwriting pictures of digits. The progra
```python ```python
def load_image(file): def load_image(file):
# open the image file and covert to grayscale
im = Image.open(file).convert('L') im = Image.open(file).convert('L')
# adjust the input image to a 28*28 high quality image
im = im.resize((28, 28), Image.ANTIALIAS) im = im.resize((28, 28), Image.ANTIALIAS)
# convert img to numpy
im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32) im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32)
# normalize
im = im / 255.0 * 2.0 - 1.0 im = im / 255.0 * 2.0 - 1.0
return im return im
......
...@@ -438,15 +438,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() ...@@ -438,15 +438,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
# 调用train_program 获取预测值,损失值, # 调用train_program 获取预测值,损失值,
prediction, [avg_loss, acc] = train_program() prediction, [avg_loss, acc] = train_program()
# 输入的原始图像数据,大小为28*28*1 # 输入的原始图像数据,名称为img,大小为28*28*1
img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')
# 标签层,名称为label,对应输入图片的类别标签 # 标签层,名称为label,对应输入图片的类别标签
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
# 告知网络传入的数据分为两部分,第一部分是img值,第二部分是label值 # 告知网络传入的数据分为两部分,第一部分是img值,第二部分是label值
feeder = fluid.DataFeeder(feed_list=[img, label], place=place) feeder = fluid.DataFeeder(feed_list=[‘img’, ‘label’], place=place)
# 选择Adam优化器 # 选择Adam优化器
optimizer = fluid.optimizer.Adam(learning_rate=0.001) optimizer = optimizer_program()
optimizer.minimize(avg_loss) optimizer.minimize(avg_loss)
``` ```
...@@ -570,9 +568,13 @@ Test with Epoch 0, avg_cost: 0.053097883707459624, acc: 0.9822850318471338 ...@@ -570,9 +568,13 @@ Test with Epoch 0, avg_cost: 0.053097883707459624, acc: 0.9822850318471338
```python ```python
def load_image(file): def load_image(file):
# 读取图片文件,并将它转成灰度图
im = Image.open(file).convert('L') im = Image.open(file).convert('L')
# 将输入图片调整为 28*28 的高质量图
im = im.resize((28, 28), Image.ANTIALIAS) im = im.resize((28, 28), Image.ANTIALIAS)
# 将图片转换为numpy
im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32) im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32)
# 对数据作归一化处理
im = im / 255.0 * 2.0 - 1.0 im = im / 255.0 * 2.0 - 1.0
return im return im
......
...@@ -419,14 +419,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() ...@@ -419,14 +419,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
prediction, [avg_loss, acc] = train_program() prediction, [avg_loss, acc] = train_program()
# input original image data in size of 28*28*1 # input original image data in size of 28*28*1
img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')
# label layer, called label, correspondent with label category of input picture. # label layer, called label, correspondent with label category of input picture.
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
# It is informed that data in network consists of two parts. One is img value, the other is label value. # It is informed that data in network consists of two parts. One is img value, the other is label value.
feeder = fluid.DataFeeder(feed_list=[img, label], place=place) feeder = fluid.DataFeeder(feed_list=['img', 'label'], place=place)
# choose Adam optimizer # choose Adam optimizer
optimizer = fluid.optimizer.Adam(learning_rate=0.001) optimizer = optimizer_program()
optimizer.minimize(avg_loss) optimizer.minimize(avg_loss)
``` ```
...@@ -555,9 +554,13 @@ You can use trained model to classify handwriting pictures of digits. The progra ...@@ -555,9 +554,13 @@ You can use trained model to classify handwriting pictures of digits. The progra
```python ```python
def load_image(file): def load_image(file):
# open the image file and covert to grayscale
im = Image.open(file).convert('L') im = Image.open(file).convert('L')
# adjust the input image to a 28*28 high quality image
im = im.resize((28, 28), Image.ANTIALIAS) im = im.resize((28, 28), Image.ANTIALIAS)
# convert img to numpy
im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32) im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32)
# normalize
im = im / 255.0 * 2.0 - 1.0 im = im / 255.0 * 2.0 - 1.0
return im return im
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册