Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions 02.recognize_digits/README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ PaddlePaddle在API中提供了自动加载[MNIST](http://yann.lecun.com/exdb/mni
首先,加载PaddlePaddle的V2 api包。

```python
import gzip
import paddle.v2 as paddle
```
其次,定义三个不同的分类器:
Expand Down Expand Up @@ -256,7 +255,7 @@ def event_handler_plot(event):
step += 1
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=paddle.batch(
Expand All @@ -275,7 +274,7 @@ def event_handler(event):
event.pass_id, event.batch_id, event.cost, event.metrics)
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=paddle.batch(
Expand Down
5 changes: 2 additions & 3 deletions 02.recognize_digits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ PaddlePaddle provides a Python module, `paddle.dataset.mnist`, which downloads a
A PaddlePaddle program starts from importing the API package:

```python
import gzip
import paddle.v2 as paddle
```

Expand Down Expand Up @@ -251,7 +250,7 @@ def event_handler_plot(event):
step += 1
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=paddle.batch(
Expand All @@ -271,7 +270,7 @@ def event_handler(event):
event.pass_id, event.batch_id, event.cost, event.metrics)
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=paddle.batch(
Expand Down
5 changes: 2 additions & 3 deletions 02.recognize_digits/index.cn.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@
首先,加载PaddlePaddle的V2 api包。

```python
import gzip
import paddle.v2 as paddle
```
其次,定义三个不同的分类器:
Expand Down Expand Up @@ -298,7 +297,7 @@
step += 1
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=paddle.batch(
Expand All @@ -317,7 +316,7 @@
event.pass_id, event.batch_id, event.cost, event.metrics)
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=paddle.batch(
Expand Down
5 changes: 2 additions & 3 deletions 02.recognize_digits/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@
A PaddlePaddle program starts from importing the API package:

```python
import gzip
import paddle.v2 as paddle
```

Expand Down Expand Up @@ -293,7 +292,7 @@
step += 1
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=paddle.batch(
Expand All @@ -313,7 +312,7 @@
event.pass_id, event.batch_id, event.cost, event.metrics)
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=paddle.batch(
Expand Down
3 changes: 1 addition & 2 deletions 02.recognize_digits/train.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gzip
import os
from PIL import Image
import numpy as np
Expand Down Expand Up @@ -85,7 +84,7 @@ def event_handler(event):
event.pass_id, event.batch_id, event.cost, event.metrics)
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=paddle.batch(
Expand Down
5 changes: 2 additions & 3 deletions 03.image_classification/README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ Paddle API提供了自动加载cifar数据集模块 `paddle.dataset.cifar`。

```python
import sys
import gzip
import paddle.v2 as paddle
from vgg import vgg_bn_drop
from resnet import resnet_cifar10
Expand Down Expand Up @@ -431,7 +430,7 @@ def event_handler(event):
sys.stdout.flush()
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(
Expand Down Expand Up @@ -498,7 +497,7 @@ test_data = []
cur_dir = os.path.dirname(os.path.realpath(__file__))
test_data.append((load_image(cur_dir + '/image/dog.png'),))

# with gzip.open('params_pass_50.tar.gz', 'r') as f:
# with open('params_pass_50.tar', 'r') as f:
# parameters = paddle.parameters.Parameters.from_tar(f)

probs = paddle.infer(
Expand Down
5 changes: 2 additions & 3 deletions 03.image_classification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ We must import and initialize PaddlePaddle (enable/disable GPU, set the number o

```python
import sys
import gzip
import paddle.v2 as paddle
from vgg import vgg_bn_drop
from resnet import resnet_cifar10
Expand Down Expand Up @@ -438,7 +437,7 @@ def event_handler(event):
sys.stdout.flush()
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(
Expand Down Expand Up @@ -508,7 +507,7 @@ cur_dir = os.path.dirname(os.path.realpath(__file__))
test_data.append((load_image(cur_dir + '/image/dog.png'),))

# users can remove the comments and change the model name
# with gzip.open('params_pass_50.tar.gz', 'r') as f:
# with open('params_pass_50.tar', 'r') as f:
# parameters = paddle.parameters.Parameters.from_tar(f)

probs = paddle.infer(
Expand Down
5 changes: 2 additions & 3 deletions 03.image_classification/index.cn.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@

```python
import sys
import gzip
import paddle.v2 as paddle
from vgg import vgg_bn_drop
from resnet import resnet_cifar10
Expand Down Expand Up @@ -473,7 +472,7 @@
sys.stdout.flush()
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(
Expand Down Expand Up @@ -540,7 +539,7 @@
cur_dir = os.path.dirname(os.path.realpath(__file__))
test_data.append((load_image(cur_dir + '/image/dog.png'),))

# with gzip.open('params_pass_50.tar.gz', 'r') as f:
# with open('params_pass_50.tar', 'r') as f:
# parameters = paddle.parameters.Parameters.from_tar(f)

probs = paddle.infer(
Expand Down
5 changes: 2 additions & 3 deletions 03.image_classification/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@

```python
import sys
import gzip
import paddle.v2 as paddle
from vgg import vgg_bn_drop
from resnet import resnet_cifar10
Expand Down Expand Up @@ -480,7 +479,7 @@
sys.stdout.flush()
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(
Expand Down Expand Up @@ -550,7 +549,7 @@
test_data.append((load_image(cur_dir + '/image/dog.png'),))

# users can remove the comments and change the model name
# with gzip.open('params_pass_50.tar.gz', 'r') as f:
# with open('params_pass_50.tar', 'r') as f:
# parameters = paddle.parameters.Parameters.from_tar(f)

probs = paddle.infer(
Expand Down
5 changes: 2 additions & 3 deletions 03.image_classification/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License

import sys
import gzip

import paddle.v2 as paddle

Expand Down Expand Up @@ -67,7 +66,7 @@ def event_handler(event):
sys.stdout.flush()
if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(
Expand Down Expand Up @@ -116,7 +115,7 @@ def load_image(file):
test_data.append((load_image(cur_dir + '/image/dog.png'), ))

# users can remove the comments and change the model name
# with gzip.open('params_pass_50.tar.gz', 'r') as f:
# with open('params_pass_50.tar', 'r') as f:
# parameters = paddle.parameters.Parameters.from_tar(f)

probs = paddle.infer(
Expand Down
4 changes: 1 addition & 3 deletions 04.word2vec/README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ trainer = paddle.trainer.SGD(cost, parameters, adagrad)
`paddle.batch`的输入是一个reader,输出是一个batched reader —— 在PaddlePaddle里,一个reader每次yield一条训练数据,而一个batched reader每次yield一个minbatch。

```python
import gzip

def event_handler(event):
if isinstance(event, paddle.event.EndIteration):
if event.batch_id % 100 == 0:
Expand All @@ -315,7 +313,7 @@ def event_handler(event):
paddle.batch(
paddle.dataset.imikolov.test(word_dict, N), 32))
print "Pass %d, Testing metrics %s" % (event.pass_id, result.metrics)
with gzip.open("model_%d.tar.gz"%event.pass_id, 'w') as f:
with open("model_%d.tar"%event.pass_id, 'w') as f:
parameters.to_tar(f)

trainer.train(
Expand Down
4 changes: 1 addition & 3 deletions 04.word2vec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ Next, we will begin the training process. `paddle.dataset.imikolov.train()` and
`paddle.batch` takes reader as input, outputs a **batched reader**: In PaddlePaddle, a reader outputs a single data instance at a time but batched reader outputs a minibatch of data instances.

```python
import gzip

def event_handler(event):
if isinstance(event, paddle.event.EndIteration):
if event.batch_id % 100 == 0:
Expand All @@ -326,7 +324,7 @@ def event_handler(event):
paddle.batch(
paddle.dataset.imikolov.test(word_dict, N), 32))
print "Pass %d, Testing metrics %s" % (event.pass_id, result.metrics)
with gzip.open("model_%d.tar.gz"%event.pass_id, 'w') as f:
with open("model_%d.tar"%event.pass_id, 'w') as f:
parameters.to_tar(f)

trainer.train(
Expand Down
4 changes: 1 addition & 3 deletions 04.word2vec/index.cn.html
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,6 @@
`paddle.batch`的输入是一个reader,输出是一个batched reader —— 在PaddlePaddle里,一个reader每次yield一条训练数据,而一个batched reader每次yield一个minbatch。

```python
import gzip

def event_handler(event):
if isinstance(event, paddle.event.EndIteration):
if event.batch_id % 100 == 0:
Expand All @@ -357,7 +355,7 @@
paddle.batch(
paddle.dataset.imikolov.test(word_dict, N), 32))
print "Pass %d, Testing metrics %s" % (event.pass_id, result.metrics)
with gzip.open("model_%d.tar.gz"%event.pass_id, 'w') as f:
with open("model_%d.tar"%event.pass_id, 'w') as f:
parameters.to_tar(f)

trainer.train(
Expand Down
4 changes: 1 addition & 3 deletions 04.word2vec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,6 @@
`paddle.batch` takes reader as input, outputs a **batched reader**: In PaddlePaddle, a reader outputs a single data instance at a time but batched reader outputs a minibatch of data instances.

```python
import gzip

def event_handler(event):
if isinstance(event, paddle.event.EndIteration):
if event.batch_id % 100 == 0:
Expand All @@ -368,7 +366,7 @@
paddle.batch(
paddle.dataset.imikolov.test(word_dict, N), 32))
print "Pass %d, Testing metrics %s" % (event.pass_id, result.metrics)
with gzip.open("model_%d.tar.gz"%event.pass_id, 'w') as f:
with open("model_%d.tar"%event.pass_id, 'w') as f:
parameters.to_tar(f)

trainer.train(
Expand Down
3 changes: 1 addition & 2 deletions 07.label_semantic_roles/README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ conll05st-release/
```python
import math
import numpy as np
import gzip
import paddle.v2 as paddle
import paddle.v2.dataset.conll05 as conll05
import paddle.v2.evaluator as evaluator
Expand Down Expand Up @@ -448,7 +447,7 @@ def event_handler(event):

if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=reader, feeding=feeding)
Expand Down
3 changes: 1 addition & 2 deletions 07.label_semantic_roles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ Here we fetch the dictionary, and print its size:
```python
import math
import numpy as np
import gzip
import paddle.v2 as paddle
import paddle.v2.dataset.conll05 as conll05
import paddle.v2.evaluator as evaluator
Expand Down Expand Up @@ -466,7 +465,7 @@ def event_handler(event):

if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=reader, feeding=feeding)
Expand Down
3 changes: 1 addition & 2 deletions 07.label_semantic_roles/index.cn.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@
```python
import math
import numpy as np
import gzip
import paddle.v2 as paddle
import paddle.v2.dataset.conll05 as conll05
import paddle.v2.evaluator as evaluator
Expand Down Expand Up @@ -490,7 +489,7 @@

if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=reader, feeding=feeding)
Expand Down
3 changes: 1 addition & 2 deletions 07.label_semantic_roles/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@
```python
import math
import numpy as np
import gzip
import paddle.v2 as paddle
import paddle.v2.dataset.conll05 as conll05
import paddle.v2.evaluator as evaluator
Expand Down Expand Up @@ -508,7 +507,7 @@

if isinstance(event, paddle.event.EndPass):
# save parameters
with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)

result = trainer.test(reader=reader, feeding=feeding)
Expand Down
Loading