From ebfbc23e0e64402b6e3076f898909c3b42a3b663 Mon Sep 17 00:00:00 2001 From: xiaoting <31891223+tink2123@users.noreply.github.com> Date: Fri, 19 Jul 2019 13:47:52 +0800 Subject: [PATCH] update recognize readme (#780) * modified reademe --- 02.recognize_digits/README.cn.md | 12 +++++++----- 02.recognize_digits/README.md | 11 +++++++---- 02.recognize_digits/index.cn.html | 12 +++++++----- 02.recognize_digits/index.html | 11 +++++++---- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/02.recognize_digits/README.cn.md b/02.recognize_digits/README.cn.md index a1488b0..b6a7137 100644 --- a/02.recognize_digits/README.cn.md +++ b/02.recognize_digits/README.cn.md @@ -396,15 +396,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() # 调用train_program 获取预测值,损失值, prediction, [avg_loss, acc] = train_program() -# 输入的原始图像数据,大小为28*28*1 -img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32') +# 输入的原始图像数据,名称为img,大小为28*28*1 # 标签层,名称为label,对应输入图片的类别标签 -label = fluid.layers.data(name='label', shape=[1], dtype='int64') # 告知网络传入的数据分为两部分,第一部分是img值,第二部分是label值 -feeder = fluid.DataFeeder(feed_list=[img, label], place=place) +feeder = fluid.DataFeeder(feed_list=[‘img’, ‘label’], place=place) # 选择Adam优化器 -optimizer = fluid.optimizer.Adam(learning_rate=0.001) +optimizer = optimizer_program() optimizer.minimize(avg_loss) ``` @@ -528,9 +526,13 @@ Test with Epoch 0, avg_cost: 0.053097883707459624, acc: 0.9822850318471338 ```python def load_image(file): + # 读取图片文件,并将它转成灰度图 im = Image.open(file).convert('L') + # 将输入图片调整为 28*28 的高质量图 im = im.resize((28, 28), Image.ANTIALIAS) + # 将图片转换为numpy im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32) + # 对数据作归一化处理 im = im / 255.0 * 2.0 - 1.0 return im diff --git a/02.recognize_digits/README.md b/02.recognize_digits/README.md index 7fc2313..c55519c 100644 --- a/02.recognize_digits/README.md +++ b/02.recognize_digits/README.md @@ -377,14 +377,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() prediction, [avg_loss, acc] = train_program() # 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 = 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. -feeder = fluid.DataFeeder(feed_list=[img, label], place=place) +feeder = fluid.DataFeeder(feed_list=['img', 'label'], place=place) # choose Adam optimizer -optimizer = fluid.optimizer.Adam(learning_rate=0.001) +optimizer = optimizer_program() optimizer.minimize(avg_loss) ``` @@ -513,9 +512,13 @@ You can use trained model to classify handwriting pictures of digits. The progra ```python def load_image(file): + # open the image file and covert to grayscale im = Image.open(file).convert('L') + # adjust the input image to a 28*28 high quality image im = im.resize((28, 28), Image.ANTIALIAS) + # convert img to numpy im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32) + # normalize im = im / 255.0 * 2.0 - 1.0 return im diff --git a/02.recognize_digits/index.cn.html b/02.recognize_digits/index.cn.html index 1fb5d5c..393fdeb 100644 --- a/02.recognize_digits/index.cn.html +++ b/02.recognize_digits/index.cn.html @@ -438,15 +438,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() # 调用train_program 获取预测值,损失值, prediction, [avg_loss, acc] = train_program() -# 输入的原始图像数据,大小为28*28*1 -img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32') +# 输入的原始图像数据,名称为img,大小为28*28*1 # 标签层,名称为label,对应输入图片的类别标签 -label = fluid.layers.data(name='label', shape=[1], dtype='int64') # 告知网络传入的数据分为两部分,第一部分是img值,第二部分是label值 -feeder = fluid.DataFeeder(feed_list=[img, label], place=place) +feeder = fluid.DataFeeder(feed_list=[‘img’, ‘label’], place=place) # 选择Adam优化器 -optimizer = fluid.optimizer.Adam(learning_rate=0.001) +optimizer = optimizer_program() optimizer.minimize(avg_loss) ``` @@ -570,9 +568,13 @@ Test with Epoch 0, avg_cost: 0.053097883707459624, acc: 0.9822850318471338 ```python def load_image(file): + # 读取图片文件,并将它转成灰度图 im = Image.open(file).convert('L') + # 将输入图片调整为 28*28 的高质量图 im = im.resize((28, 28), Image.ANTIALIAS) + # 将图片转换为numpy im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32) + # 对数据作归一化处理 im = im / 255.0 * 2.0 - 1.0 return im diff --git a/02.recognize_digits/index.html b/02.recognize_digits/index.html index bf42873..c57204e 100644 --- a/02.recognize_digits/index.html +++ b/02.recognize_digits/index.html @@ -419,14 +419,13 @@ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() prediction, [avg_loss, acc] = train_program() # 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 = 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. -feeder = fluid.DataFeeder(feed_list=[img, label], place=place) +feeder = fluid.DataFeeder(feed_list=['img', 'label'], place=place) # choose Adam optimizer -optimizer = fluid.optimizer.Adam(learning_rate=0.001) +optimizer = optimizer_program() optimizer.minimize(avg_loss) ``` @@ -555,9 +554,13 @@ You can use trained model to classify handwriting pictures of digits. The progra ```python def load_image(file): + # open the image file and covert to grayscale im = Image.open(file).convert('L') + # adjust the input image to a 28*28 high quality image im = im.resize((28, 28), Image.ANTIALIAS) + # convert img to numpy im = numpy.array(im).reshape(1, 1, 28, 28).astype(numpy.float32) + # normalize im = im / 255.0 * 2.0 - 1.0 return im -- GitLab