dmlc / MXNet.cpp

C++ interface for mxnet
Other
114 stars 115 forks source link

How to use Crop #16

Closed zhubuntu closed 8 years ago

zhubuntu commented 8 years ago

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
hjk41 commented 8 years ago

sorry for late reply. It should be usable using something like this:

Symbol cropped = Crop("cropped", 1, offset, h_w)(to_be_cropped_symbol)

or

Symbol cropped = Crop("cropped", 2)(to_be_cropped_symbol, shape_symbol)
zhubuntu commented 8 years ago

@hjk41 Thanks,I try what you say ,but it reports

错误  33  error C2064: 项不会计算为接受 2 个参数的函数  
and
错误  39  IntelliSense:  在没有适当 operator() 的情况下调用类类型的对象或将函数转换到指向函数的类

So I change the

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);
}

to

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);
}

for a temporary solution.

hjk41 commented 8 years ago

Great move. Let me see why the code I posted does not work and fix it.

On Mon, Mar 28, 2016 at 6:35 PM, zhubuntu notifications@github.com wrote:

@hjk41 https://github.com/hjk41 Thanks,I try what you say ,but it reports

错误 33 error C2064: 项不会计算为接受 2 个参数的函数 and 错误 39 IntelliSense: 在没有适当 operator() 的情况下调用类类型的对象或将函数转换到指向函数的类

So I change the

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); }

to

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); }

for a temporary solution.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/dmlc/MXNet.cpp/issues/16#issuecomment-202336346

HONG Chuntao System Research Group Microsoft Research Asia