diff --git a/02.recognize_digits/README.en.md b/02.recognize_digits/README.en.md index faa20b33ef41c312f9515e4ab851052de5ca1cfd..894d4faea990a4fca21b003395c3125825eb8838 100644 --- a/02.recognize_digits/README.en.md +++ b/02.recognize_digits/README.en.md @@ -321,14 +321,17 @@ After training is done, user can use the trained model to classify images. The f ```python from PIL import Image import numpy as np +import os def load_image(file): im = Image.open(file).convert('L') im = im.resize((28, 28), Image.ANTIALIAS) im = np.array(im).astype(np.float32).flatten() im = im / 255.0 return im + test_data = [] -test_data.append((load_image('image/infer_3.png'),)) +cur_dir = os.path.dirname(os.path.realpath(__file__)) +test_data.append((load_image(cur_dir + '/image/infer_3.png'),)) probs = paddle.infer( output_layer=predict, parameters=parameters, input=test_data) diff --git a/02.recognize_digits/README.md b/02.recognize_digits/README.md index 563590087c0ea5de1ffb80ccb638648b9a1dfed6..edb80727a21260778d295f05812e38fbb12b5172 100644 --- a/02.recognize_digits/README.md +++ b/02.recognize_digits/README.md @@ -317,14 +317,17 @@ trainer.train( ```python from PIL import Image import numpy as np +import os def load_image(file): im = Image.open(file).convert('L') im = im.resize((28, 28), Image.ANTIALIAS) im = np.array(im).astype(np.float32).flatten() im = im / 255.0 return im + test_data = [] -test_data.append((load_image('image/infer_3.png'),)) +cur_dir = os.path.dirname(os.path.realpath(__file__)) +test_data.append((load_image(cur_dir + '/image/infer_3.png'),)) probs = paddle.infer( output_layer=predict, parameters=parameters, input=test_data) diff --git a/02.recognize_digits/index.en.html b/02.recognize_digits/index.en.html index a9daec9b8af595aa3348c1ea793808ded39d97ae..53895ea940de36d6ac87f428d6eac014384ae03e 100644 --- a/02.recognize_digits/index.en.html +++ b/02.recognize_digits/index.en.html @@ -363,14 +363,17 @@ After training is done, user can use the trained model to classify images. The f ```python from PIL import Image import numpy as np +import os def load_image(file): im = Image.open(file).convert('L') im = im.resize((28, 28), Image.ANTIALIAS) im = np.array(im).astype(np.float32).flatten() im = im / 255.0 return im + test_data = [] -test_data.append((load_image('image/infer_3.png'),)) +cur_dir = os.path.dirname(os.path.realpath(__file__)) +test_data.append((load_image(cur_dir + '/image/infer_3.png'),)) probs = paddle.infer( output_layer=predict, parameters=parameters, input=test_data) diff --git a/02.recognize_digits/index.html b/02.recognize_digits/index.html index e9c3d4044d47cb7459f8110930160fb15f7661dd..82593db88e4abc0f16f10ecd14ebfa93c6832db6 100644 --- a/02.recognize_digits/index.html +++ b/02.recognize_digits/index.html @@ -359,14 +359,17 @@ trainer.train( ```python from PIL import Image import numpy as np +import os def load_image(file): im = Image.open(file).convert('L') im = im.resize((28, 28), Image.ANTIALIAS) im = np.array(im).astype(np.float32).flatten() im = im / 255.0 return im + test_data = [] -test_data.append((load_image('image/infer_3.png'),)) +cur_dir = os.path.dirname(os.path.realpath(__file__)) +test_data.append((load_image(cur_dir + '/image/infer_3.png'),)) probs = paddle.infer( output_layer=predict, parameters=parameters, input=test_data) diff --git a/02.recognize_digits/train.py b/02.recognize_digits/train.py index ec285a384ad11b7780e6bff009f3d388870added..e55752c327ab0ff0f0bb4ccb2fbed3707e565502 100644 --- a/02.recognize_digits/train.py +++ b/02.recognize_digits/train.py @@ -1,4 +1,5 @@ import gzip +import os from PIL import Image import numpy as np import paddle.v2 as paddle @@ -114,7 +115,8 @@ def main(): return im test_data = [] - test_data.append((load_image('image/infer_3.png'), )) + cur_dir = os.path.dirname(os.path.realpath(__file__)) + test_data.append((load_image(cur_dir + '/image/infer_3.png'), )) probs = paddle.infer( output_layer=predict, parameters=parameters, input=test_data) diff --git a/03.image_classification/README.en.md b/03.image_classification/README.en.md index d5e8b650199cc32bec817a884baed222d17115e3..93391af3e5999fa22e8cc55bf7e6f40d76874c21 100644 --- a/03.image_classification/README.en.md +++ b/03.image_classification/README.en.md @@ -488,6 +488,7 @@ After training is done, users can use the trained model to classify images. The ```python from PIL import Image import numpy as np +import os def load_image(file): im = Image.open(file) im = im.resize((32, 32), Image.ANTIALIAS) @@ -495,7 +496,8 @@ def load_image(file): im = im / 255.0 return im test_data = [] -test_data.append((load_image('image/dog.png'),)) +cur_dir = os.path.dirname(os.path.realpath(__file__)) +test_data.append((load_image(cur_dir + '/image/dog.png'),) probs = paddle.infer( output_layer=out, parameters=parameters, input=test_data) diff --git a/03.image_classification/README.md b/03.image_classification/README.md index 8f3a8d256173839adeec06125527a6b696b79974..96891b15fa702bf673b90667516bf2c93807c181 100644 --- a/03.image_classification/README.md +++ b/03.image_classification/README.md @@ -480,6 +480,7 @@ Test with Pass 0, {'classification_error_evaluator': 0.885200023651123} ```python from PIL import Image import numpy as np +import os def load_image(file): im = Image.open(file) im = im.resize((32, 32), Image.ANTIALIAS) @@ -487,7 +488,8 @@ def load_image(file): im = im / 255.0 return im test_data = [] -test_data.append((load_image('image/dog.png'),)) +cur_dir = os.path.dirname(os.path.realpath(__file__)) +test_data.append((load_image(cur_dir + '/image/dog.png'),) probs = paddle.infer( output_layer=out, parameters=parameters, input=test_data) diff --git a/03.image_classification/index.en.html b/03.image_classification/index.en.html index 37f1dc5f2392a931f0e5161926abe262f3fad7ee..b737fb74f3e41c01d23b247a0170a1d2241d92fd 100644 --- a/03.image_classification/index.en.html +++ b/03.image_classification/index.en.html @@ -530,6 +530,7 @@ After training is done, users can use the trained model to classify images. The ```python from PIL import Image import numpy as np +import os def load_image(file): im = Image.open(file) im = im.resize((32, 32), Image.ANTIALIAS) @@ -537,7 +538,8 @@ def load_image(file): im = im / 255.0 return im test_data = [] -test_data.append((load_image('image/dog.png'),)) +cur_dir = os.path.dirname(os.path.realpath(__file__)) +test_data.append((load_image(cur_dir + '/image/dog.png'),) probs = paddle.infer( output_layer=out, parameters=parameters, input=test_data) diff --git a/03.image_classification/index.html b/03.image_classification/index.html index 4001d122d275657a201f47e70fb4923688e523e9..25373fbdb682901987afd3e37d19900234acb4fe 100644 --- a/03.image_classification/index.html +++ b/03.image_classification/index.html @@ -522,6 +522,7 @@ Test with Pass 0, {'classification_error_evaluator': 0.885200023651123} ```python from PIL import Image import numpy as np +import os def load_image(file): im = Image.open(file) im = im.resize((32, 32), Image.ANTIALIAS) @@ -529,7 +530,8 @@ def load_image(file): im = im / 255.0 return im test_data = [] -test_data.append((load_image('image/dog.png'),)) +cur_dir = os.path.dirname(os.path.realpath(__file__)) +test_data.append((load_image(cur_dir + '/image/dog.png'),) probs = paddle.infer( output_layer=out, parameters=parameters, input=test_data) diff --git a/03.image_classification/train.py b/03.image_classification/train.py index e60b9bda3c7ec1eefb2cfb9798f72aa8fd5e2b93..9ec8237c074651c350bbc87cdfba8ab518fed30c 100644 --- a/03.image_classification/train.py +++ b/03.image_classification/train.py @@ -94,6 +94,7 @@ def main(): # inference from PIL import Image import numpy as np + import os def load_image(file): im = Image.open(file) @@ -103,7 +104,8 @@ def main(): return im test_data = [] - test_data.append((load_image('image/dog.png'), )) + cur_dir = os.path.dirname(os.path.realpath(__file__)) + test_data.append((load_image(cur_dir + '/image/dog.png'), )) probs = paddle.infer( output_layer=out, parameters=parameters, input=test_data)