How to add my parameters (weight, bias) to arguments in symbol?
I am trying to modify the weight of convolution like this.
To do this, I make, initialize my parameters(weight, bias), convolute input image using them.
But, it shows an error because my parameters are not arguments in symbol.
How to add my parameters to arguments in symbol?
If you let me know, I would be very grateful.
arguments symbols mxnet
add a comment |
I am trying to modify the weight of convolution like this.
To do this, I make, initialize my parameters(weight, bias), convolute input image using them.
But, it shows an error because my parameters are not arguments in symbol.
How to add my parameters to arguments in symbol?
If you let me know, I would be very grateful.
arguments symbols mxnet
1
Hey, could you give more info about the type of error and also the code you are currently using. I will be able to help out in a better way. Thanks
– Chaitanya Bapat
Nov 15 '18 at 19:36
add a comment |
I am trying to modify the weight of convolution like this.
To do this, I make, initialize my parameters(weight, bias), convolute input image using them.
But, it shows an error because my parameters are not arguments in symbol.
How to add my parameters to arguments in symbol?
If you let me know, I would be very grateful.
arguments symbols mxnet
I am trying to modify the weight of convolution like this.
To do this, I make, initialize my parameters(weight, bias), convolute input image using them.
But, it shows an error because my parameters are not arguments in symbol.
How to add my parameters to arguments in symbol?
If you let me know, I would be very grateful.
arguments symbols mxnet
arguments symbols mxnet
asked Nov 13 '18 at 2:02
EunSeop Lee
61
61
1
Hey, could you give more info about the type of error and also the code you are currently using. I will be able to help out in a better way. Thanks
– Chaitanya Bapat
Nov 15 '18 at 19:36
add a comment |
1
Hey, could you give more info about the type of error and also the code you are currently using. I will be able to help out in a better way. Thanks
– Chaitanya Bapat
Nov 15 '18 at 19:36
1
1
Hey, could you give more info about the type of error and also the code you are currently using. I will be able to help out in a better way. Thanks
– Chaitanya Bapat
Nov 15 '18 at 19:36
Hey, could you give more info about the type of error and also the code you are currently using. I will be able to help out in a better way. Thanks
– Chaitanya Bapat
Nov 15 '18 at 19:36
add a comment |
1 Answer
1
active
oldest
votes
If you want to pass in arguments to a Custom Operator you have to do so via the init method.
From https://github.com/apache/incubator-mxnet/issues/5580 here's a snippet illustrating what you need:
class Softmax(mx.operator.CustomOp):
def __init__(self, xxx, yyy): # arguments xxx, and yyy
self.xxx = xxx
self.yyy = yyy
def forward(self, is_train, req, in_data, out_data, aux):
x = in_data[0].asnumpy()
y = np.exp(x - x.max(axis=1).reshape((x.shape[0], 1)))
y /= y.sum(axis=1).reshape((x.shape[0], 1))
print self.xxx, self.yyy
self.assign(out_data[0], req[0], mx.nd.array(y))
def backward(self, req, out_grad, in_data, out_data, in_grad, aux):
l = in_data[1].asnumpy().ravel().astype(np.int)
y = out_data[0].asnumpy()
y[np.arange(l.shape[0]), l] -= 1.0
self.assign(in_grad[0], req[0], mx.nd.array(y))
@mx.operator.register("softmax")
class SoftmaxProp(mx.operator.CustomOpProp):
def __init__(self, xxx, yyy):
super(SoftmaxProp, self).__init__(need_top_grad=False)
# add parameter
self.xxx = xxx
self.yyy = yyy
def list_arguments(self):
return ['data', 'label', 'xxx', 'yyy']
def list_outputs(self):
return ['output']
def infer_shape(self, in_shape):
data_shape = in_shape[0]
label_shape = (in_shape[0][0],)
output_shape = in_shape[0]
return [data_shape, label_shape], [output_shape],
def create_operator(self, ctx, shapes, dtypes):
return Softmax(xxx=self.xxx, yyy=self.yyy)
Take a look at https://mxnet.incubator.apache.org/faq/new_op.html for full info.
Vishaal
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272705%2fhow-to-add-my-parameters-weight-bias-to-arguments-in-symbol%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to pass in arguments to a Custom Operator you have to do so via the init method.
From https://github.com/apache/incubator-mxnet/issues/5580 here's a snippet illustrating what you need:
class Softmax(mx.operator.CustomOp):
def __init__(self, xxx, yyy): # arguments xxx, and yyy
self.xxx = xxx
self.yyy = yyy
def forward(self, is_train, req, in_data, out_data, aux):
x = in_data[0].asnumpy()
y = np.exp(x - x.max(axis=1).reshape((x.shape[0], 1)))
y /= y.sum(axis=1).reshape((x.shape[0], 1))
print self.xxx, self.yyy
self.assign(out_data[0], req[0], mx.nd.array(y))
def backward(self, req, out_grad, in_data, out_data, in_grad, aux):
l = in_data[1].asnumpy().ravel().astype(np.int)
y = out_data[0].asnumpy()
y[np.arange(l.shape[0]), l] -= 1.0
self.assign(in_grad[0], req[0], mx.nd.array(y))
@mx.operator.register("softmax")
class SoftmaxProp(mx.operator.CustomOpProp):
def __init__(self, xxx, yyy):
super(SoftmaxProp, self).__init__(need_top_grad=False)
# add parameter
self.xxx = xxx
self.yyy = yyy
def list_arguments(self):
return ['data', 'label', 'xxx', 'yyy']
def list_outputs(self):
return ['output']
def infer_shape(self, in_shape):
data_shape = in_shape[0]
label_shape = (in_shape[0][0],)
output_shape = in_shape[0]
return [data_shape, label_shape], [output_shape],
def create_operator(self, ctx, shapes, dtypes):
return Softmax(xxx=self.xxx, yyy=self.yyy)
Take a look at https://mxnet.incubator.apache.org/faq/new_op.html for full info.
Vishaal
add a comment |
If you want to pass in arguments to a Custom Operator you have to do so via the init method.
From https://github.com/apache/incubator-mxnet/issues/5580 here's a snippet illustrating what you need:
class Softmax(mx.operator.CustomOp):
def __init__(self, xxx, yyy): # arguments xxx, and yyy
self.xxx = xxx
self.yyy = yyy
def forward(self, is_train, req, in_data, out_data, aux):
x = in_data[0].asnumpy()
y = np.exp(x - x.max(axis=1).reshape((x.shape[0], 1)))
y /= y.sum(axis=1).reshape((x.shape[0], 1))
print self.xxx, self.yyy
self.assign(out_data[0], req[0], mx.nd.array(y))
def backward(self, req, out_grad, in_data, out_data, in_grad, aux):
l = in_data[1].asnumpy().ravel().astype(np.int)
y = out_data[0].asnumpy()
y[np.arange(l.shape[0]), l] -= 1.0
self.assign(in_grad[0], req[0], mx.nd.array(y))
@mx.operator.register("softmax")
class SoftmaxProp(mx.operator.CustomOpProp):
def __init__(self, xxx, yyy):
super(SoftmaxProp, self).__init__(need_top_grad=False)
# add parameter
self.xxx = xxx
self.yyy = yyy
def list_arguments(self):
return ['data', 'label', 'xxx', 'yyy']
def list_outputs(self):
return ['output']
def infer_shape(self, in_shape):
data_shape = in_shape[0]
label_shape = (in_shape[0][0],)
output_shape = in_shape[0]
return [data_shape, label_shape], [output_shape],
def create_operator(self, ctx, shapes, dtypes):
return Softmax(xxx=self.xxx, yyy=self.yyy)
Take a look at https://mxnet.incubator.apache.org/faq/new_op.html for full info.
Vishaal
add a comment |
If you want to pass in arguments to a Custom Operator you have to do so via the init method.
From https://github.com/apache/incubator-mxnet/issues/5580 here's a snippet illustrating what you need:
class Softmax(mx.operator.CustomOp):
def __init__(self, xxx, yyy): # arguments xxx, and yyy
self.xxx = xxx
self.yyy = yyy
def forward(self, is_train, req, in_data, out_data, aux):
x = in_data[0].asnumpy()
y = np.exp(x - x.max(axis=1).reshape((x.shape[0], 1)))
y /= y.sum(axis=1).reshape((x.shape[0], 1))
print self.xxx, self.yyy
self.assign(out_data[0], req[0], mx.nd.array(y))
def backward(self, req, out_grad, in_data, out_data, in_grad, aux):
l = in_data[1].asnumpy().ravel().astype(np.int)
y = out_data[0].asnumpy()
y[np.arange(l.shape[0]), l] -= 1.0
self.assign(in_grad[0], req[0], mx.nd.array(y))
@mx.operator.register("softmax")
class SoftmaxProp(mx.operator.CustomOpProp):
def __init__(self, xxx, yyy):
super(SoftmaxProp, self).__init__(need_top_grad=False)
# add parameter
self.xxx = xxx
self.yyy = yyy
def list_arguments(self):
return ['data', 'label', 'xxx', 'yyy']
def list_outputs(self):
return ['output']
def infer_shape(self, in_shape):
data_shape = in_shape[0]
label_shape = (in_shape[0][0],)
output_shape = in_shape[0]
return [data_shape, label_shape], [output_shape],
def create_operator(self, ctx, shapes, dtypes):
return Softmax(xxx=self.xxx, yyy=self.yyy)
Take a look at https://mxnet.incubator.apache.org/faq/new_op.html for full info.
Vishaal
If you want to pass in arguments to a Custom Operator you have to do so via the init method.
From https://github.com/apache/incubator-mxnet/issues/5580 here's a snippet illustrating what you need:
class Softmax(mx.operator.CustomOp):
def __init__(self, xxx, yyy): # arguments xxx, and yyy
self.xxx = xxx
self.yyy = yyy
def forward(self, is_train, req, in_data, out_data, aux):
x = in_data[0].asnumpy()
y = np.exp(x - x.max(axis=1).reshape((x.shape[0], 1)))
y /= y.sum(axis=1).reshape((x.shape[0], 1))
print self.xxx, self.yyy
self.assign(out_data[0], req[0], mx.nd.array(y))
def backward(self, req, out_grad, in_data, out_data, in_grad, aux):
l = in_data[1].asnumpy().ravel().astype(np.int)
y = out_data[0].asnumpy()
y[np.arange(l.shape[0]), l] -= 1.0
self.assign(in_grad[0], req[0], mx.nd.array(y))
@mx.operator.register("softmax")
class SoftmaxProp(mx.operator.CustomOpProp):
def __init__(self, xxx, yyy):
super(SoftmaxProp, self).__init__(need_top_grad=False)
# add parameter
self.xxx = xxx
self.yyy = yyy
def list_arguments(self):
return ['data', 'label', 'xxx', 'yyy']
def list_outputs(self):
return ['output']
def infer_shape(self, in_shape):
data_shape = in_shape[0]
label_shape = (in_shape[0][0],)
output_shape = in_shape[0]
return [data_shape, label_shape], [output_shape],
def create_operator(self, ctx, shapes, dtypes):
return Softmax(xxx=self.xxx, yyy=self.yyy)
Take a look at https://mxnet.incubator.apache.org/faq/new_op.html for full info.
Vishaal
answered Nov 20 '18 at 21:42
Vishaal Kapoor
844
844
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272705%2fhow-to-add-my-parameters-weight-bias-to-arguments-in-symbol%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Hey, could you give more info about the type of error and also the code you are currently using. I will be able to help out in a better way. Thanks
– Chaitanya Bapat
Nov 15 '18 at 19:36