使用CNTK 2.1.0 GPU,VS 2015更新3,C ++,Window进行学习速率设置

时间:2017-08-31 05:50:32

标签: c++ cntk

我提到了“https://github.com/Microsoft/CNTK/blob/master/Tests/UnitTests/V2LibraryTests/FeedForwardTests.cpp

在“TestFeedForwardNetworkCreation”功能中,我找不到设置学习率的方法。

    std::vector<float> inputData(inputDim * numSamples);
    for (size_t i2 = 0; i2 < inputData.size(); ++i2)
        inputData[i2] = ((float)rand()) / RAND_MAX;

    NDShape inputShape = inputVar.Shape().AppendShape({ 1, numSamples });
    ValuePtr inputValue = MakeSharedObject<Value>(MakeSharedObject<NDArrayView>(inputShape, inputData.data(), inputData.size(), DeviceDescriptor::CPUDevice(), true));

    std::vector<float> labelData(numOutputClasses * numSamples, 0);
    for (size_t i3 = 0; i3 < numSamples; ++i3)
        labelData[(i3*numOutputClasses) + (rand() % numOutputClasses)] = 1;

    NDShape labelShape = labelsVar.Shape().AppendShape({ 1, numSamples });
    ValuePtr labelValue = MakeSharedObject<Value>(MakeSharedObject<NDArrayView>(labelShape, labelData.data(), labelData.size(), DeviceDescriptor::CPUDevice(), true));

    ValuePtr outputValue, predictionErrorValue;
    std::unordered_map<Variable, ValuePtr> outputs = { { classifierOutput, outputValue }, { prediction, predictionErrorValue } };
    auto backpropState = ffNet->Forward({ { inputVar, inputValue }, { labelsVar, labelValue } }, outputs, device, { trainingLoss });

    // Perform backprop
    NDShape outputShape = trainingLoss->Output().Shape();
    std::vector<float> rootGradientsData(outputShape.TotalSize(), 1);
    ValuePtr rootGradientValue = MakeSharedObject<Value>(MakeSharedObject<NDArrayView>(outputShape, rootGradientsData.data(), rootGradientsData.size(), DeviceDescriptor::CPUDevice(), true));
    std::unordered_map<Variable, ValuePtr> paramGradients;
    auto allParams = ffNet->Parameters();
    for (auto iter = allParams.begin(); iter != allParams.end(); ++iter)
        paramGradients[*iter] = nullptr;
    ffNet->Backward(backpropState, { { trainingLoss, rootGradientValue } }, paramGradients);

1 个答案:

答案 0 :(得分:0)

学习率或学习率计划是在学习者的构造者中指定的。例如,请参阅here