使用CNTK 2.1.0 GPU的学习率设置,vs 2015 Update 3,C ,窗口

learning rate setting with CNTK 2.1.0 GPU, VS 2015 update 3, C++, Window

本文关键字:2015 vs Update 窗口 设置 学习率 CNTK GPU 使用      更新时间:2023-10-16

i转介" https://github.com/microsoft/cntk/cntk/blob/master/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);

在学习者的构造师中指定学习率或学习率表。请参阅此处。