GithubHelp home page GithubHelp logo

mxnet.cpp's Introduction

Distributed Machine Learning Common Codebase

Build Status Documentation Status GitHub license

DMLC-Core is the backbone library to support all DMLC projects, offers the bricks to build efficient and scalable distributed machine learning libraries.

Developer Channel Join the chat at https://gitter.im/dmlc/dmlc-core

What's New

Contents

Known Issues

  • RecordIO format is not portable across different processor endians. So it is not possible to save RecordIO file on a x86 machine and then load it on a SPARC machine, because x86 is little endian while SPARC is big endian.

Contributing

Contributing to dmlc-core is welcomed! dmlc-core follows google's C style guide. If you are interested in contributing, take a look at feature wishlist and open a new issue if you like to add something.

  • DMLC-Core uses C++11 standard. Ensure that your C++ compiler supports C++11.
  • Try to introduce minimum dependency when possible

CheckList before submit code

  • Type make lint and fix all the style problems.
  • Type make doc and fix all the warnings.

NOTE

deps:

libcurl4-openssl-dev

mxnet.cpp's People

Contributors

craftit avatar hjk41 avatar kotaweav avatar loofahcus avatar mz24cn avatar stereomatchingkiss avatar zhangchen-qinyinghua 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mxnet.cpp's Issues

Output abnormal when I applying MXNet.cpp to implement Multi-label task

I use MXNet.cpp(@hjk41 ) to implement Multi-label(4 labels,33 classes per label)task,but the output is always the same【0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0】 whenever I change the input.
The define net structure:

        .........

                Symbol fc2 = FullyConnected("fc2", relu4, fc2_w, fc2_b, 256);
        Symbol relu5 = Activation("relu5", fc2, ActivationActType::relu);
        //Symbol drop2 = Dropout("drop2",relu5,0.3);

        Symbol fc31 = FullyConnected("fc31", relu5, fc31_w, fc31_b, 33);
        Symbol fc32 = FullyConnected("fc32", relu5, fc32_w, fc32_b, 33);
        Symbol fc33 = FullyConnected("fc33", relu5, fc33_w, fc33_b, 33);
        Symbol fc34 = FullyConnected("fc34", relu5, fc34_w, fc34_b, 33);

        vector<Symbol> fcVector;
        fcVector.push_back(fc31);
        fcVector.push_back(fc32);
        fcVector.push_back(fc33);
        fcVector.push_back(fc34);

        Symbol conc = Concat("concat",fcVector, 4, 1);

        Symbol captchaNet = SoftmaxOutput("softmax", conc, data_label); 

Is there any errors to the defined net structure?

FCN can run but accuracy is poor

I'm writting a FCN example,the program can run ,but accuracy is very poor, always about 0.33
Here is the code i write, to find the problem, I change the code so the program just train one image for 10000 times.
This code mainly refer to caffee model and FCN of mxnet python version

#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include <stdint.h>
#include <vector>
#include "MxNetCpp.h"
#include "readmnist.h"
#include "opencv2/opencv.hpp"

using namespace std;
using namespace mxnet::cpp;
using namespace cv;

class Lenet {
public:
    Lenet()
        : ctx_cpu(Context(DeviceType::kCPU, 0)),
        ctx_dev(Context(DeviceType::kGPU, 0)) {}
    void Run() {
        /*
        * LeCun, Yann, Leon Bottou, Yoshua Bengio, and Patrick Haffner.
        * "Gradient-based learning applied to document recognition."
        * Proceedings of the IEEE (1998)
        * */

        /*define the symbolic net*/


        Symbol data = Symbol::Variable("data");
        Symbol data_label = Symbol::Variable("data_label");
        Symbol conv1_1_w = Symbol::Variable("conv1_1_w");
        Symbol conv1_1_b = Symbol::Variable("conv1_1_b");
        Symbol conv1_2_w = Symbol::Variable("conv1_2_w");
        Symbol conv1_2_b = Symbol::Variable("conv1_2_b");
        Symbol conv2_1_w = Symbol::Variable("conv2_1_w");
        Symbol conv2_1_b = Symbol::Variable("conv2_1_b");
        Symbol conv2_2_w = Symbol::Variable("conv2_2_w");
        Symbol conv2_2_b = Symbol::Variable("conv2_2_b");
        Symbol conv3_1_w = Symbol::Variable("conv3_1_w");
        Symbol conv3_1_b = Symbol::Variable("conv3_1_b");
        Symbol conv3_2_w = Symbol::Variable("conv3_2_w");
        Symbol conv3_2_b = Symbol::Variable("conv3_2_b");
        Symbol conv4_1_w = Symbol::Variable("conv4_1_w");
        Symbol conv4_1_b = Symbol::Variable("conv4_1_b");
        Symbol conv4_2_w = Symbol::Variable("conv4_2_w");
        Symbol conv4_2_b = Symbol::Variable("conv4_2_b");
        Symbol conv4_3_w = Symbol::Variable("conv4_3_w");
        Symbol conv4_3_b = Symbol::Variable("conv4_3_b");
        Symbol conv5_1_w = Symbol::Variable("conv5_1_w");
        Symbol conv5_1_b = Symbol::Variable("conv5_1_b");
        Symbol conv5_2_w = Symbol::Variable("conv5_2_w");
        Symbol conv5_2_b = Symbol::Variable("conv5_2_b");
        Symbol conv5_3_w = Symbol::Variable("conv5_3_w");
        Symbol conv5_3_b = Symbol::Variable("conv5_3_b");
        Symbol fc6_w = Symbol::Variable("fc6_w");
        Symbol fc6_b = Symbol::Variable("fc6_b");
        Symbol fc7_b = Symbol::Variable("fc7_b");
        Symbol fc7_w = Symbol::Variable("fc7_w");
        Symbol score_fr_b = Symbol::Variable("score_fr_b");
        Symbol score_fr_w = Symbol::Variable("score_fr_w");
        Symbol bigscore_b = Symbol::Variable("bigscore_b");
        Symbol bigscore_w = Symbol::Variable("bigscore_w");

        Symbol conv1_1 =
            Convolution("conv1_1", data, conv1_1_w, conv1_1_b, Shape(3, 3), 64, Shape(1, 1), Shape(1, 1), Shape(100, 100));
        Symbol tanh1_1 = Activation("tanh1_1", conv1_1, ActivationActType::sigmoid);
        Symbol conv1_2 =
            Convolution("conv1_2", tanh1_1, conv1_2_w, conv1_2_b, Shape(3, 3), 64, Shape(1, 1), Shape(1, 1), Shape(1, 1));
        Symbol tanh1_2 = Activation("tanh1_2", conv1_2, ActivationActType::sigmoid);
        Symbol pool1 = Pooling("pool1", tanh1_2, Shape(2, 2),
            PoolingPoolType::max, Shape(2, 2));

        Symbol conv2_1 =
            Convolution("conv2_1", pool1, conv2_1_w, conv2_1_b, Shape(3, 3), 128, Shape(1, 1), Shape(1, 1), Shape(1, 1));
        Symbol tanh2_1 = Activation("tanh2_1", conv2_1, ActivationActType::sigmoid);
        Symbol conv2_2 =
            Convolution("conv2_2", tanh2_1, conv2_2_w, conv2_2_b, Shape(3, 3), 128, Shape(1, 1), Shape(1, 1), Shape(1, 1));
        Symbol tanh2_2 = Activation("tanh2_2", conv2_2, ActivationActType::sigmoid);
        Symbol pool2 = Pooling("pool2", tanh2_2, Shape(2, 2),
            PoolingPoolType::max, Shape(2, 2));


        Symbol conv3_1 =
            Convolution("conv3_1", pool2, conv3_1_w, conv3_1_b, Shape(3, 3), 256, Shape(1, 1), Shape(1, 1), Shape(1, 1));
        Symbol tanh3_1 = Activation("tanh3_1", conv3_1, ActivationActType::sigmoid);
        Symbol conv3_2 =
            Convolution("conv3_2", tanh3_1, conv3_2_w, conv3_2_b, Shape(3, 3), 256, Shape(1, 1), Shape(1, 1), Shape(1, 1));
        Symbol tanh3_2 = Activation("tanh3_2", conv3_2, ActivationActType::sigmoid);
        Symbol pool3 = Pooling("pool3", tanh3_2, Shape(2, 2),
            PoolingPoolType::max, Shape(2, 2));


        Symbol conv4_1 =
            Convolution("conv4_1", pool3, conv4_1_w, conv4_1_b, Shape(3, 3), 512, Shape(1, 1), Shape(1, 1), Shape(1, 1));
        Symbol tanh4_1 = Activation("tanh4_1", conv4_1, ActivationActType::sigmoid);
        Symbol conv4_2 =
            Convolution("conv4_2", tanh4_1, conv4_2_w, conv4_2_b, Shape(3, 3), 512, Shape(1, 1), Shape(1, 1), Shape(1, 1));
        Symbol tanh4_2 = Activation("tanh4_2", conv4_2, ActivationActType::sigmoid);
        Symbol conv4_3 =
            Convolution("conv4_3", tanh4_2, conv4_3_w, conv4_3_b, Shape(3, 3), 512, Shape(1, 1), Shape(1, 1), Shape(1, 1));
        Symbol tanh4_3 = Activation("tanh4_3", conv4_3, ActivationActType::sigmoid);
        Symbol pool4 = Pooling("pool4", tanh4_3, Shape(2, 2),
            PoolingPoolType::max, Shape(2, 2));


        Symbol conv5_1 =
            Convolution("conv5_1", pool4, conv5_1_w, conv5_1_b, Shape(3, 3), 512, Shape(1, 1), Shape(1, 1), Shape(1, 1));
        Symbol tanh5_1 = Activation("tanh5_1", conv5_1, ActivationActType::sigmoid);
        Symbol conv5_2 =
            Convolution("conv5_2", tanh5_1, conv5_2_w, conv5_2_b, Shape(3, 3), 512, Shape(1, 1), Shape(1, 1), Shape(1, 1));
        Symbol tanh5_2 = Activation("tanh5_2", conv5_2, ActivationActType::sigmoid);
        Symbol conv5_3 =
            Convolution("conv5_3", tanh5_2, conv5_3_w, conv5_3_b, Shape(3, 3), 512, Shape(1, 1), Shape(1, 1), Shape(1, 1));
        Symbol tanh5_3 = Activation("tanh5_3", conv5_3, ActivationActType::sigmoid);
        Symbol pool5 = Pooling("pool5", tanh5_3, Shape(2, 2),
            PoolingPoolType::max, Shape(2, 2));

        Symbol fc6 =
            Convolution("fc6", pool5, fc6_w, fc6_b, Shape(7, 7), 4096);
        Symbol tanh6 = Activation("tanh6", fc6, ActivationActType::sigmoid);
        Symbol drop6 = Dropout("drop6", tanh6, 0.5);
        Symbol fc7 =
            Convolution("fc7", drop6, fc7_w, fc7_b, Shape(1, 1), 4096);
        Symbol tanh7 = Activation("tanh7", fc7, ActivationActType::sigmoid);
        Symbol drop7 = Dropout("drop7", tanh7, 0.5);
        Symbol score_fr =
            Convolution("score_fr", drop7, score_fr_w, score_fr_b, Shape(1, 1), 3);

        Symbol bigscore = Deconvolution("bigscore", score_fr, bigscore_w, bigscore_b, Shape(64, 64), 3, Shape(32, 32));
        Symbol upscore = Crop("upscore", 2,bigscore, data);
        /*Crop函数暂将op.h文件中的Crop定义改为了
        inline Symbol Crop(const std::string& symbol_name,
        int num_args,
        Symbol data,
        Symbol crop_like,
        Shape offset = Shape(0, 0),
        Shape h_w = Shape(0, 0),
        bool center_crop = false) {
        return Operator("Crop")
        .SetParam("num_args", num_args)
        .SetParam("offset", offset)
        .SetParam("h_w", h_w)
        .SetParam("center_crop", center_crop)
        .SetInput("arg0", data)
        .SetInput("arg1", crop_like)
        .CreateSymbol(symbol_name);
        }   */
        Symbol lenet = SoftmaxOutput("lenet",upscore, data_label,1,255,true,true);

        for (auto s : lenet.ListArguments()) {
            LG << s;
        }

        /*setup basic configs*/


        int batch_size = 1;
        int max_epoch = 100;
        float learning_rate = 1e-10;
        float weight_decay = 0.0005;


        vector<float> data_vec, label_vec;

        size_t data_count = getData(data_vec, label_vec);
        const float *dptr = data_vec.data();
        const float *lptr = label_vec.data();
        NDArray data_array = NDArray(Shape(data_count, 1,W,H), ctx_cpu,
            false);  // store in main memory, and copy to
        // device memory while training

        NDArray label_array =
            NDArray(Shape(data_count,1*W*H), ctx_cpu,
            false);  // it's also ok if just store them all in device memory
        data_array.SyncCopyFromCPU(dptr, data_count * W * H);
        label_array.SyncCopyFromCPU(lptr, data_count * W * H);
        data_array.WaitToRead();
        label_array.WaitToRead();

        size_t train_num = 1;
        train_data = data_array.Slice(0, train_num);
        train_label = label_array.Slice(0, train_num);
        val_data = data_array.Slice(0, 1);
        val_label = label_array.Slice(0, 1);

        LG << "here read fin";


        args_map["data"] =
            NDArray(Shape(batch_size, 1, W, H), ctx_dev, false);

        lenet.InferArgsMap(ctx_dev, &args_map, args_map);

        NDArray::WaitAll();

        LG << "here slice fin";

        Optimizer opt("ccsgd", learning_rate, weight_decay);
        opt.SetParam("momentum", 0.99)
            .SetParam("rescale_grad", 1.0)
            .SetParam("clip_gradient", 10);
        for (int m = 0; m < 100; m++)
        {
            for (int ITER = 0; ITER < max_epoch; ++ITER) {

                    args_map["data"] =
                        train_data.Slice(0, 1)
                        .Copy(ctx_dev);
                    args_map["data_label"] = train_label.Slice(0, 1)
                        .Copy(ctx_dev);             
                    NDArray::WaitAll();
                    Executor *exe = lenet.SimpleBind(ctx_dev, args_map);
                    exe->Forward(true);

                    const auto &out = exe->outputs;
                    NDArray out_cpu = out[0].Copy(ctx_cpu);
                    vector<mx_uint> shape_out = out_cpu.GetShape();
                    exe->Backward();
                    exe->UpdateAll(&opt, learning_rate, weight_decay);

                    delete exe;

            }

            LG <<"Iter"<<  m <<", accuracy: " << ValAccuracy(batch_size, lenet);

        }
    }

private:
    Context ctx_cpu;
    Context ctx_dev;
    map<string, NDArray> args_map;
    NDArray train_data;
    NDArray train_label;
    NDArray val_data;
    NDArray val_label;

    int W = 200;
    int H = 200;
    size_t getData(vector<float> &vec, vector<float> &vecl)
    {
        int number_of_images = 0;
        Mat I = cv::imread("1.jpg", 0);//读取灰度图
        uchar* p = I.data;
        for (unsigned int j = 0; j < 40000; ++j)
        {
            vec.push_back(*p);
            p++;
        }

        //分割之后图像背景像素值为0,其他为38,飞机为220,分别用0,1,2来表示
        I = cv::imread("1.png", 0);
        p = I.data;
        for (unsigned int j = 0; j <40000; ++j)
        {
            if (*p == 220)
                vecl.push_back(2);
            else if (*p == 38)
                vecl.push_back(1);
            else
                vecl.push_back(0);
            p++;
        }

        number_of_images++;

    return number_of_images;
    }

    float ValAccuracy(int batch_size, Symbol lenet) {
        size_t val_num = val_data.GetShape()[0];

        size_t correct_count = 0;
        size_t all_count = 0;

        size_t start_index = 0;
        while (start_index < val_num) {
            if (start_index + batch_size > val_num) {
                start_index = val_num - batch_size;
            }
            args_map["data"] =
                val_data.Slice(start_index, start_index + batch_size).Copy(ctx_dev);
            args_map["data_label"] =
                val_label.Slice(start_index, start_index + batch_size).Copy(ctx_dev);
            start_index += batch_size;
            NDArray::WaitAll();

            Executor *exe = lenet.SimpleBind(ctx_dev, args_map);
            exe->Forward(false);

            const auto &out = exe->outputs;
            NDArray out_cpu = out[0].Copy(ctx_cpu);
            NDArray label_cpu =
                val_label.Slice(start_index - batch_size, start_index).Copy(ctx_cpu);

            NDArray::WaitAll();
            const mx_float *dptr_label = label_cpu.GetData();
            float *dptr = new float[120000];
            float *dptr1 = new float[40000];
            NDArray save_cpu = out_cpu.Copy(ctx_cpu);
            NDArray::WaitAll();

            save_cpu.SyncCopyToCPU(dptr, 120000);

            //判断每个像素点的类别
            for (int i = 0; i < 40000;i++)
            {
                float p = 0;
                if (dptr[i + 40000] > dptr[i])
                {
                    p = 1;
                    if (dptr[i + 80000] > dptr[i + 40000])
                        p = 2;
                }
                else
                    if (dptr[i + 80000] > dptr[i])
                        p = 2;
                dptr1[i] = p;

            }


            for (int i = 0; i < 40000; i++)
            {
                if (dptr1[i] == dptr_label[i])
                    correct_count++;
            }
            all_count +=40000;

            delete exe;
        }
        return correct_count * 1.0 / all_count;
    }
};

int main(int argc, char const *argv[]) {

    Lenet lenet;
    lenet.Run();
    return 0;
}

This is the image file i use to test.
1
1

How to setup???

I don't know how to setup it. Is this ok if we make it directly?

GPU NDarray memory

請問 MXNet.cpp 有free 掉 或者 delete NDarray的api嗎?
因為 架構還要 繼續用 所以不想del Executor,重新load model;

saving/loading models

Guys,

could you point to the example on how to save/restore model state (weights, not structure)

thanks

merging into mxnet repo

I propose to merge mxnet.cpp into mxnet project.

  1. It will attract more attention to mxnet.cpp.
  2. It will enable integrated test with mxnet, so that future checkins to mxnet will not break mxnet.cpp

inline function “_MinusScalar” fails to work.

When writing the gru unit, I need to use "1-update" matrix. Following is my source code:
Symbol gruLayer::step(Symbol &input)
{
Symbol reset_i = FullyConnected("reset_i", input, inputWeights[0], biases[0], layerSize);
Symbol reset = Activation("reset_act", reset_i + FullyConnected("reset_h", previousHidden, hiddenWeights[0], biases[0], layerSize, true), ActivationActType::sigmoid);
Symbol update_i = FullyConnected("update_i", input, inputWeights[1], biases[1], layerSize);
Symbol update = Activation("update_act", update_i + FullyConnected("update_h", previousHidden, hiddenWeights[1], biases[1], layerSize, true), ActivationActType::sigmoid);
Symbol fake_hidden_i = FullyConnected("cell_i", input, inputWeights[2], biases[2], layerSize);
Symbol fake_hidden_h = FullyConnected("cell_h", previousHidden_reset, hiddenWeights[2], biases[2], layerSize, true);
Symbol fake_hidden = Activation("cell_act", fake_hidden_h + fake_hidden_i, ActivationActType::tanh);
//Symbol tmp = update - (mx_float)1.9f;
hidden = update_previousHidden - (update - (mx_float)1.0f)* fake_hidden;
hidden = update*previousHidden;
previousHidden = hidden;
return hidden;
}

But the "update - (mx_float)1.0f" fails at:

Symbol Operator::CreateSymbol(const std::string &name) {
const char *pname = name == "" ? nullptr : name.c_str();

SymbolHandle symbol_handle;
std::vector<const char *> input_keys;
std::vector<const char *> param_keys;
std::vector<const char *> param_values;

for (auto &data : params_) {
param_keys.push_back(data.first.c_str());
param_values.push_back(data.second.c_str());
}
for (auto &data : this->input_keys) {
input_keys.push_back(data.c_str());
}
const char **input_keys_p =
(input_keys.size() > 0) ? input_keys.data() : nullptr;

MXSymbolCreateAtomicSymbol(handle_, param_keys.size(), param_keys.data(),
param_values.data(), &symbol_handle);
MXSymbolCompose(symbol_handle, pname, input_values.size(), input_keys_p,
input_values.data());
return Symbol(symbol_handle);
}

at MXSymbolCreateAtomicSymbol(handle_, param_keys.size(), param_keys.data(),
param_values.data(), &symbol_handle);
It can't get a symbol_handle from this function.
Do any one meet the same problem with me and find the solution?

Missing input validation can cause memory corruption.

I have some code that can vary the batch size as I process the data. I have been trying it with mxnet, and ran into memory corruptions and crashes. I traced the problem to an wrongly sized array, code to reproduce the problem is attached. Ideally mxnet should report the array is of an unexpected size and abort.

testMXNet.zip

The lenet.cpp example run error

I am trying to run lenet.cpp sample. An error occurred at the first line with "Convolution" function.
However, when we tried mlp.cpp, it ran to end normally.

default

My development environment:
OS: windows10
visual studio 2013
GPU: geforce GTX 780

by the way, I noticed that the same error occurred in #2.
but I don't get the solution from it.

get error when run charRNN with vs2013update5

1>..\..\..\example\charRNN.cpp(101): error C2661: 'mxnet::cpp::transpose' : no overloaded function takes 1 arguments
1>..\..\..\example\charRNN.cpp(149): warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
1>..\..\..\example\charRNN.cpp(153): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
1>..\..\..\example\charRNN.cpp(202): warning C4267: 'return' : conversion from 'size_t' to 'int', possible loss of data
1>..\..\..\example\charRNN.cpp(288): error C2664: 'std::tuple<std::unordered_map<wchar_t,mx_float,std::hash<wchar_t>,std::equal_to<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>,std::vector<wchar_t,std::allocator<wchar_t>>>::tuple(const std::tuple<std::unordered_map<_Kty,_Ty,std::hash<wchar_t>,std::equal_to<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>,std::vector<wchar_t,std::allocator<wchar_t>>> &)' : cannot convert argument 1 from 'std::unordered_map<wchar_t,mx_float,std::hash<wchar_t>,std::equal_to<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>' to 'std::allocator_arg_t'
1>          with
1>          [
1>              _Kty=wchar_t
1>  ,            _Ty=mx_float
1>          ]
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>..\..\..\example\charRNN.cpp(349): warning C4305: 'initializing' : truncation from 'double' to 'mx_float'
1>..\..\..\example\charRNN.cpp(372): warning C4305: 'argument' : truncation from 'double' to 'float'
1>..\..\..\example\charRNN.cpp(376): warning C4305: 'initializing' : truncation from 'double' to 'mx_float'
1>..\..\..\example\charRNN.cpp(377): warning C4305: 'initializing' : truncation from 'double' to 'mx_float'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

maybe the transpose op should add a arg about axes?
how can fixed it?

or maybe vs2015 don't have this problem...?
but i can't find a transpose function with only one arg exactly

Enable Travis and AppVeyor checking

MxNet has Travis and AppVeyor, it checks lint formatting and make sure tests are passed before a PR is merged. We should also enable that.

No output for MxnetTestCpp program

I can successfully build the given MxnetTestCpp propram, but when I execute it no output is generated, does anyone have similar issue?

Problem with MNIST iterator

I run MXNet with MXNet.cpp on Windows 10. The mlp.cpp example runs ok for both GPU and CPU. But running the mnist / lenet example with dataiter, creating the MNIST dataIter throws an error.

int main(int argc, char const *argv[]) {
/setup basic configs/
int W = 28;
int H = 28;
int batch_size = 128;
int max_epoch = 100;
float learning_rate = 1e-4;
float weight_decay = 1e-4;

/char cwd[1024];
if (_getcwd(cwd, sizeof(cwd)) != NULL)
fprintf(stdout, "Current working dir: %s\n", cwd);
else
perror("getcwd() error");
/

auto lenet = LenetSymbol();
std::map<string, NDArray> args_map;

args_map["data"] = NDArray(Shape(batch_size, 1, W, H), Context::cpu());
args_map["data_label"] = NDArray(Shape(batch_size), Context::cpu());
lenet.InferArgsMap(Context::cpu(), &args_map, args_map);

args_map["fc1_w"] = NDArray(Shape(500, 4 * 4 * 50), Context::cpu());
NDArray::SampleGaussian(0, 1, &args_map["fc1_w"]);
args_map["fc2_b"] = NDArray(Shape(10), Context::cpu());
args_map["fc2_b"] = 0;

auto train_iter = MXDataIter("MNISTIter")
//.SetParam("image", "C:\Temp\MXNet-DataSets\MNIST\train-images-idx3-ubyte")
//.SetParam("label", "C:\Temp\MXNet-DataSets\MNIST\train-labels-idx1-ubyte")
.SetParam("image", "./MNIST/train-images-idx3-ubyte")
.SetParam("label", "./MNIST/train-labels-idx1-ubyte")
.SetParam("batch_size", batch_size)
.SetParam("shuffle", 1)
.SetParam("flat", 0)
.CreateDataIter();
auto val_iter = MXDataIter("MNISTIter")
// .SetParam("image", "C:\Temp\MXNet-DataSets\MNIST\t10k-images-idx3-ubyte")
// .SetParam("label", "C:\Temp\MXNet-DataSets\MNIST\t10k-labels-idx1-ubyte")
.SetParam("image", "./MNIST/t10k-images-idx3-ubyte")
.SetParam("label", "./MNIST/t10k-labels-idx1-ubyte")
.CreateDataIter();

I do not know how the file path on a Windows should be set but I tried both the \ and / folder separator and relative as absolute paths. I always see in the output of the debugger the message:
"Exception thrown at 0x00007FFECDE27788 in MxnetTestApp.exe: Microsoft C++ exception: dmlc::Error at memory location 0x000000B0E0AFD9D8"

The error is the same (including the memeory address) for both the training and validation DataIter.

Any help? Is there a log file generated and if so, where can I find it?

CUDA: out of memory

when I ran ./feature_extract repeatedly with hundreds of images, I encounter the following error.
I find that when the program is running ,the memory grows rapidly, and finally overflow.
Could someone kindly tell me why? Thanks~

`[17:46:08] ./dmlc-core/include/dmlc/././logging.h:241: [17:46:08] src/storage/./gpu_device_storage.h:39: Check failed: e == cudaSuccess || e == cudaErrorCudartUnloading CUDA: out of memory

[17:46:08] ../../include/executor.hpp:48: Check failed: (MXExecutorBind(symbol.GetHandle(), context.GetDeviceType(), context.GetDeviceId(), arg_handles.size(), arg_handles.data(), grad_handles.data(), grad_reqs_uint.data(), aux_handles.size(), aux_handles.data(), &handle_)) == (0) `

Train.csv

Hi, where can I get the data sets-'train.csv'?

The lenet.cpp example runs ok ,but accuracy does not improve

I'm trying to use the lenet.cpp example.It can runs,But the accuracy always remain 0.0980952.
qq 20160223102919

I did make some changes about the lenet.cpp
from

    Symbol conv1_w("conv1_w"), conv1_b("conv1_b");
    Symbol conv2_w("conv2_w"), conv2_b("conv2_b");
    Symbol conv3_w("conv3_w"), conv3_b("conv3_b");
    Symbol fc1_w("fc1_w"), fc1_b("fc1_b");
    Symbol fc2_w("fc2_w"), fc2_b("fc2_b");

to

    Symbol conv1_w = Symbol::Variable("conv1_w");
    Symbol conv1_b = Symbol::Variable("conv1_b");
    Symbol conv2_w = Symbol::Variable("conv2_w");
    Symbol conv2_b = Symbol::Variable("conv2_b");
    Symbol conv3_w = Symbol::Variable("conv3_w");
    Symbol conv3_b = Symbol::Variable("conv3_b");
    Symbol fc1_w = Symbol::Variable("fc1_w");
    Symbol fc1_b = Symbol::Variable("fc1_b");
    Symbol fc2_w = Symbol::Variable("fc2_w");
    Symbol fc2_b = Symbol::Variable("fc2_b");

Because I found It will report error with the former code
Microsoft C++ 异常: std::length_error,位于内存位置 0x0000009D1AAFE3F0 处。

And I also refer the https://github.com/hjk41/MxNet.cpp/issues/12,change the code
from
args_map["data"] = NDArray(Shape(batch_size, 1, W, H), ctx_dev, false);
to

args_map["data"] =
      NDArray(Shape(batch_size, 1, W, H), ctx_dev, false);
args_map["data_label"] =
        NDArray(Shape(batch_size), ctx_dev, false);

Params interface question

NDArray::LoadToMap() can load params by file name.Is there any interface that can load params by raw bytes?

batch scoring in cpp

I am trying to load a pre-built model and do batch scoring, I tried the following two ways, the first one can produce some results, and the second one compiles successfully but runs with segmentation fault. Could you please let me know which way I should follow, and why the second way doesn't work? Thanks!
method 1:

/* Image size and channels */
int width = 224;
int height = 224;
int channels = 3;
int batch_size = 5;

Context ctx_dev(DeviceType::kCPU, 0);
map<string, NDArray> args_map;
map<string, NDArray> aux_map;
map<string, NDArray> parameters;

NDArray::Load("../Resnet/resnet-152-0000.params", 0, &parameters);

for (const auto &k : parameters) {
  if (k.first.substr(0, 4) == "aux:") {
    auto name = k.first.substr(4, k.first.size() - 4);
    aux_map[name] = k.second.Copy(ctx_dev);
  }
  if (k.first.substr(0, 4) == "arg:") {
    auto name = k.first.substr(4, k.first.size() - 4);
    args_map[name] = k.second.Copy(ctx_dev);
  }
}

auto net = Symbol::Load("../Resnet/resnet-152-symbol.json");

auto data_iter = MXDataIter("ImageRecordIter")
.SetParam("path_imglist","../caltech_256/caltech-256-60-train.lst")
.SetParam("path_imgrec","../caltech_256/caltech-256-60-train.rec")
.SetParam("data_shape", Shape(3, 224, 224))
.SetParam("batch_size", batch_size)
.SetParam("shuffle", 1)
.CreateDataIter();

while(data_iter.Next()){
auto batch = data_iter.GetData();
args_map["data"] = batch;
auto *exec = net.SimpleBind(ctx_dev, args_map);
exec->Forward(false);
auto outputs = exec->outputs[0].Copy(Context(kCPU, 0));
NDArray::WaitAll();
for (int i = 0; i <2; i++) {
cout << outputs.At(0, i) <<",";
}
cout << endl;
}
MXNotifyShutdown();

method 2:

int width = 224;
int height = 224;
int channels = 3;
int batch_size = 5;

Context ctx_dev(DeviceType::kCPU, 0);

map<string, NDArray> args_map;
map<string, NDArray> aux_map;

args_map["data"] = NDArray(Shape(batch_size, channels, width, height), ctx_dev);
args_map["label"] = NDArray(Shape(batch_size), ctx_dev);

auto net = Symbol::Load("../Resnet/resnet-152-symbol.json");

auto *exec = net.SimpleBind(ctx_dev, args_map);

NDArray::Load("../Resnet/resnet-152-0000.params", 0, &args_map);

auto data_iter = MXDataIter("ImageRecordIter")
  .SetParam("path_imglist","../caltech_256/caltech-256-60-train.lst")
  .SetParam("path_imgrec","../caltech_256/caltech-256-60-train.rec")
  .SetParam("data_shape", Shape(3, 224, 224))
  .SetParam("batch_size", batch_size)
  .SetParam("shuffle", 1)
  .CreateDataIter();

while(data_iter.Next()){
auto batch = data_iter.GetDataBatch();
batch.data.CopyTo(&args_map["data"]);
batch.label.CopyTo(&args_map["label"]);
exec->Forward(false);
NDArray::WaitAll();
}

delete exec;
MXNotifyShutdown();

can't use dmlc::Stream::Create

I'm trying use dmlc::Stream::Create to save the ndarray,but VS reports unresolved external symbol.

Will this function be added to MXNet.cpp

Implement Executor::Reshape() to allow for varying batch sizes

In include/mxnet-cpp/executor.h there is a comment to implement the Executor::Reshape() method. I am interested in using different batch sizes during my network's training.

It would be great if someone could please take a look and implement the Executor::Reshape() method and provide a code example of how to use this method to change the batch size during training.

Thank you very much! I'd be happy to test.

What's the problem that "Segmentation fault "

When I run the example mlp, I get the message that "Segmentation fault".
And I debug with the gdb, the message is as follow

(gdb) r
Starting program: /home/wsy/MXNet.cpp/example/mlp 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff791b772 in std::__shared_ptr<mxnet::Symbol::Node, (__gnu_cxx::_Lock_policy)2>::operator-> (this=0x6c6562616c)
at /usr/include/c++/4.9/bits/shared_ptr_base.h:1048
1048 return _M_ptr;
(gdb) 

feature_extract failed to compile

g++ -c -std=c++0x  -I ../../include -Wall -O3 -msse3 -funroll-loops -Wno-unused-parameter -Wno-unknown-pragmas -fopenmp  feature_extract.cpp
g++ -c -std=c++0x `pkg-config --cflags opencv` prepare_data_with_opencv.cpp
feature_extract.cpp: In function ‘mxnet::cpp::NDArray Data2NDArray()’:
feature_extract.cpp:102:36: error: expected ‘(’ before ‘data’
   inf.read(reinterpret_cast<char *>data.data(), 2 * 3 * 224 * 224 * sizeof(float));
                                    ^
feature_extract.cpp:102:83: error: expected ‘)’ before ‘;’ token
   inf.read(reinterpret_cast<char *>data.data(), 2 * 3 * 224 * 224 * sizeof(float));
                                                                                   ^
prepare_data_with_opencv.cpp: In function ‘void Mat2Array()’:
prepare_data_with_opencv.cpp:30:38: error: expected ‘(’ before ‘array’
   outf.write(reinterpret_cast<char *>array.data(), array.size() * sizeof(float));
                                      ^
prepare_data_with_opencv.cpp:30:81: error: expected ‘)’ before ‘;’ token
   outf.write(reinterpret_cast<char *>array.data(), array.size() * sizeof(float));
                                                                                 ^
Makefile:20: recipe for target 'prepare_data_with_opencv' failed
make: *** [prepare_data_with_opencv] Error 1
make: *** Waiting for unfinished jobs....
In file included from ../../include/mxnet-cpp/executor.hpp:15:0,
                 from ../../include/mxnet-cpp/MxNetCpp.h:11,
                 from feature_extract.cpp:9:
../../include/mxnet-cpp/optimizer.hpp: At global scope:
../../include/mxnet-cpp/optimizer.h:102:14: warning: ‘mxnet::cpp::__make_SGDOptimizer_sgd__’ defined but not used [-Wunused-variable]
   static int __make_ ## OptimizerType ## _ ## Name ## __ = \
              ^
../../include/mxnet-cpp/optimizer.hpp:28:1: note: in expansion of macro ‘MXNETCPP_REGISTER_OPTIMIZER’
 MXNETCPP_REGISTER_OPTIMIZER(sgd, SGDOptimizer);
 ^
../../include/mxnet-cpp/optimizer.h:102:14: warning: ‘mxnet::cpp::__make_SGDOptimizer_ccsgd__’ defined but not used [-Wunused-variable]
   static int __make_ ## OptimizerType ## _ ## Name ## __ = \
              ^
../../include/mxnet-cpp/optimizer.hpp:29:1: note: in expansion of macro ‘MXNETCPP_REGISTER_OPTIMIZER’
 MXNETCPP_REGISTER_OPTIMIZER(ccsgd, SGDOptimizer);  // For backward compatibility
 ^
Makefile:15: recipe for target 'feature_extract' failed
make: *** [feature_extract] Error 1

how to use train_ads.cpp example

I compiled train_ads.cpp example in Windows directory. To execute it I need to pass a parameter (apparently some data file name), but I can't find any information what it is supposed to be.

How to use Crop

I have found the C++ wrapper of crop at here,but I don't know how to use it.
In caffe model,the crop has two input and one output,but in this c++ wrapper,it shows

inline Symbol Crop(const std::string& symbol_name,
                   int num_args,
                   Shape offset = Shape(0, 0),
                   Shape h_w = Shape(0, 0),
                   bool center_crop = false) {
  return Operator("Crop")
           .SetParam("num_args", num_args)
           .SetParam("offset", offset)
           .SetParam("h_w", h_w)
           .SetParam("center_crop", center_crop)
           .CreateSymbol(symbol_name);
}

I don't know where to define the input symbol,and in the comment ,it also says

 * \param num_args Number of inputs for crop, if equals one, then we will use
 *        the h_wfor crop heihgt and width, else if equals two, then we will
 *        use the heightand width of the second input symbol, we name crop_like here

Why are the .h files in MXNet.cpp different from the .h files in MXNet?

The .h files in MXNet.cpp/include/mxnet-cpp are not all the same as the .h files in mxnet/include/mxnet. For example, the bash.h in mxnet/include/mxnet define the Context as a struct:

struct Context {
  /*! \brief Type of device */
  enum DeviceType {
    kCPU = cpu::kDevMask,
    kGPU = gpu::kDevMask,
    kCPUPinned = 3
...

but the bash.h in MXNet.cpp/include/mxnet-cpp doesn't write the Context, but in the ndarray.h file define the Context as a class.

class Context {
 public:
  /*!
  * \brief Context constructor
  * \param type type of the device
  * \param id id of the device
  */
  Context(const DeviceType &type, int id) : type_(type), id_(id) {}
...

Can you tell me the reason? Thank you!

Accuracy is low

Basically we are using the same logic with python, forward->backward->update.

It seems a little weired after 100 epoch, we only get 0.91 with lenet.

[14:35:18] ./lenet_with_mxdataiter.cxx:51: Epoch: 99
[14:35:21] ./lenet_with_mxdataiter.cxx:78: Accuracy: 0.916166

Is this expected or I have done something wrong?

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.