提交 e89e682f 编写于 作者: Y Yu Yang 提交者: GitHub

Merge pull request #295 from PaddlePaddle/readme

Add python current path for inference
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册