Giter Club home page Giter Club logo

dnn_tensorflow_cpp's People

Contributors

gmorenz avatar pinkysan avatar theflofly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dnn_tensorflow_cpp's Issues

error when run the exe

i just build the program well
when the program run to the line 90:
TF_CHECK_OK(session.Run({{x, x_data}, {y, y_data}}, {apply_w1, apply_w2, apply_w3, apply_b1, apply_b2, apply_b3}, nullptr));
the system always told me two error:
some time is Allocator (GPU_0_bfc) ran out of memory trying to allocate 3.92GiB. Current allocation summary follows.
another time is Non-OK-status: session.Run({ { x, x_data },{ y, y_data } }, { apply_w1, apply_w2, apply_w3, apply_b1, apply_b2, apply_b3, layer_3 }, nullptr) status: Invalid argument: Incompatible shapes: [2] vs. [0]
I'm not sure which error is right.
So what should i do ?

Tensorflow C++ - DNN

Hey there,
I am implementing a multilayer perceptron with the AddSymbolicGradients, for the or and x-or it works with multiclass but for mnist data it doesnt train the loss for the same image each epoch has the loss for the output with shape 10
Loss: 0.875 0.84375 0.9375 0.90625 0.96875 0.9375 0.875 0.875 0.875 0.90625
Loss: 0.96875 0.8125 0.90625 0.875 0.90625 0.875 0.90625 0.96875 0.9375 0.84375
Loss: 0.9375 0.8125 0.90625 0.875 0.9375 0.96875 0.875 0.8125 0.96875 0.90625
Loss: 0.875 0.84375 0.9375 0.90625 0.96875 0.9375 0.875 0.875 0.875 0.90625
Loss: 0.96875 0.8125 0.90625 0.875 0.90625 0.875 0.90625 0.96875 0.9375 0.84375
Loss: 0.9375 0.8125 0.90625 0.875 0.9375 0.96875 0.875 0.8125 0.96875 0.90625
...

My code looks

void Model::train(Tensor imageTensor, Tensor labelTensor, int maxEpochs, float learningRate, int batchSize) {
    if (imageTensor.dim_size(0) != labelTensor.dim_size(0)) {
        std::cerr << "Image und label dataset size must fit together";
        std::exit(EXIT_FAILURE);
    }
    Tensor imageBatches, labelBatches;
    std::tie(imageBatches, labelBatches) = getBatches(batchSize, imageTensor, labelTensor);
    Scope lossScope = scope.NewSubScope("Training");
    auto loss = Mean(lossScope.WithOpName("Loss"), SquaredDifference(lossScope.WithOpName("Sigmoid-Cross-Entropy"), model, *this->labels), {0});
    std::cout << "Image batches size: " << imageBatches.shape() << std::endl;
    std::vector<Output> apply_gradients = this->backpropagation(lossScope,learningRate, loss);

    std::cout << "Training started" << std::endl;
    int dataSize = imageBatches.dim_size(0);
    std::vector<Tensor> outputs;
    for (int i = 1; i <= maxEpochs; i++) {
        auto lossValue = 0;
        for (int64_t num = 0; num < dataSize; num++) {
            vector<Tensor> output1;
            //auto d1 = DeepCopy(scope, imageBatches.SubSlice(num));
            //auto d2 = DeepCopy(scope, labelBatches.SubSlice(num));
            //TF_CHECK_OK(session->Run({d1, d2}, &output1));
            Tensor imageBatch(imageBatches.SubSlice(num));
            Tensor labelBatch(labelBatches.SubSlice(num));
            TF_CHECK_OK(session->Run({{*features, imageBatch}, {*this->labels, labelBatch}}, apply_gradients, {}, nullptr));
            if (num % 1000 == 0) {
                //TF_CHECK_OK(session->Run({{*features, inputFeatures[num]}, {*this->labels, labels[num]}}, {loss}, &outputs));
                TF_CHECK_OK(session->Run({{*features, imageBatch}, {*this->labels, labelBatch}}, {loss}, &outputs));
                std::cout << "Loss: " << outputs[0].flat<float>() << std::endl;
            }
        }
        if (i % 100 == 0) {
            std::cout << "Epoch " << i << " Loss: " << lossValue << std::endl;
            std::cout << " " << std::endl;
        }
    }
    printWeightForNumber(0);
}

std::vector<Output> Model::backpropagation(Scope lossScope, float learningRate, Output loss) {
    std::vector<std::shared_ptr<Variable>> weights = getAllLayerWeights();
    std::vector<Output> gradients;
    TF_CHECK_OK(AddSymbolicGradients(scope.WithOpName("Gradients"), {loss}, {*weights[0]}, &gradients));

    std::vector<Output> apply_gradients;
    for (int i = 0; i < weights.size(); i++) {
        Output apply_gradient = ApplyGradientDescent(lossScope.WithOpName("Apply-Gradients-" + std::to_string(i)), *weights[i], Cast(scope, learningRate,  DT_FLOAT), gradients[i]);
        apply_gradients.push_back(apply_gradient);
    }
    return apply_gradients;
}

I would appreciate it if you could help me as soon as possible.

error when run this model in tensorflow2.0

@theflofly Hello, I compiled tensorflow 2.0, and then run this code. The program reported an error. I didn't find the problem. Can you help solve this problem? My Operating environment is Linux.
ERROR:
2020-10-24 14:42:57.130012: F tensorflow/core/framework/tensor.cc:693] Check failed: dtype() == expected_dtype (3 vs. 1) float expected, got int32

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.