Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Conversation

@jetfuel
Copy link
Contributor

@jetfuel jetfuel commented Jun 8, 2018

Update the English and Chinese Image Classification tutorial with high level fluid API

@jetfuel jetfuel self-assigned this Jun 8, 2018
Copy link
Contributor

@daming-lu daming-lu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some tiny comments 😬

global step
if isinstance(event, paddle.event.EndIteration):
if isinstance(event, fluid.EndStepEvent):
if step % 1 == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should change step % 1 == 0 to something more meaningful, say step % 10

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we remove this line? Looks like we should draw it no matter what.

cost_ploter.plot()
step += 1
if isinstance(event, paddle.event.EndPass):
if isinstance(event, fluid.EndEpochEvent):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious at the last step of an epoch, will Fluid trigger both EndStepEvent and EndEpochEvent ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the order is
EndStepEvent, and then EndEpochEvent

# 而PIL打开图片默认通道顺序为RGB,因为需要交换通道。
im = im[(2, 1, 0),:,:] # BGR
im = im.flatten()
# The storage order of the loaded image is W(widht),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W(width)

# the CHW order, so transpose them.
im = im.transpose((2, 0, 1)) # CHW
# In the training phase, the channel order of CIFAR
# image is B(Blue), G(green), R(Red). But PIL open
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PIL opens

lab = np.argsort(-probs) # probs and lab are the results of one batch data
print "Label of image/dog.png is: %d" % lab[0][0]
```
`Inferencer` 需要一个 `infer_func``param_path` 来设置网络和经过训练的参数。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind of weird that we call the param name param_path but use params_dirname as the variable name 😭

param_path=params_dirname

But let's keep it as-is for now.

Firstly, we create the model parameters according to the previous model configuration `cost`.
In the context of supervised learning, labels of training images are defined in `fluid.layers.data` as well. During training, the cross-entropy loss function is used and the loss is the output of the network. During testing, the outputs are the probabilities calculated in the classifier.

**NOTE:** A train program should return an array and the first return argument has to be `avg_cost`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first returned ; The trainer always implicitly uses

global step
if isinstance(event, paddle.event.EndIteration):
if isinstance(event, fluid.EndStepEvent):
if step % 1 == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. step %10 might make more sense 😆


### Generate input data for inferring

`dog.png` is an example image of a dog. Turn it into an numpy array to match the data feeder format.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a numpy array

im = im.resize((32, 32), Image.ANTIALIAS)

im = np.array(im).astype(np.float32)
# The storage order of the loaded image is W(widht),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

width

@jetfuel jetfuel merged commit e5e810c into PaddlePaddle:high-level-api-branch Jun 8, 2018
@jetfuel jetfuel deleted the image_classification_new_api_markdown branch June 8, 2018 21:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants