(formerly) The training process of torch

Source: Internet
Author: User

Reprint please specify the source:

Http://www.cnblogs.com/darkknightzh/p/6221622.html

Reference URL:

http://ju.outofmemory.cn/entry/284587

Https://github.com/torch/nn/blob/master/doc/criterion.md

Assuming that you have Model=setupmodel (a model of your own), and that you have your own training data input, the actual output outreal, and the loss function criterion (see the second URL), use the torch training process as follows:

1 -- given model, criterion, input, outreal 2 model:training () 3 model:zerogradparameters () 4 outpredict = model:forward (input)5 err= criterion:forward (outpredict, Outreal)  6 grad_criterion = Criterion:backward (outpredict, outreal)7Model: Backward (input, grad_criterion)8 model:updateparameters (learningrate)

The 1th line above assumes that the known parameters

Line 2nd is set to training mode

The 3rd row will save the gradient of each module in model 0 (prevent the previous interference this iteration)

The 4th line inputs input through model to get the predicted output outpredict

The 5th line calculates the error of the predicted output outpredict and the actual output outreal of the model under the current parameter by the loss function err

The 6th line calculates the gradient of the loss function by predicting the output outpredict and the actual output outreal grad_criterion

Line 7th Reverse calculates the gradient of each module in the model

Line 8th updates the parameters for each module of the model

Rows 3rd through 8th are required for each iteration.

(formerly) The training process of torch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.