You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@mxnet.apache.org by pan via MXNet Forum <mx...@discoursemail.com.INVALID> on 2020/08/01 16:41:01 UTC

[MXNet Forum] Parameter initialization error in customization of conv2D kernel with ndarray tensor


I insert a customized variant of conv2D into the stem of a net with  initialization of  filter kernel  and then  following error occurs.

> All Parameters must be initialized on the same set of contexts, but Parameter sonicnet0_firstconv_weight is initialized on [gpu(0), gpu(1)] while previous Parameters are initialized on [cpu(0)].

```python

class MeanShift(nn.Conv2D):
    def __init__(
        self, rgb_range,
        rgb_mean=(0.4488, 0.4371, 0.4040), rgb_std=(1.0, 1.0, 1.0), sign=-1):
        super(MeanShift, self).__init__(3,kernel_size=1,in_channels=3)
        std = nd.array(rgb_std)
#         conv = mx.gluon.nn.Conv2D(channels=1, kernel_size=(3,3), padding=(1,1))
#         conv.initialize()
#         conv.weight.set_data(weight)
        self.initialize()
        self.weight.set_data(nd.eye(3).reshape(3, 3, 1, 1) / std.reshape(3, 1, 1, 1))
        self.bias.set_data(sign * rgb_range * nd.array(rgb_mean) / std)
        self.params.setattr('grad_req','null')
```
as loading model on two GPU, specifically how could I do for the purpose of initializing the block.
I would like to could use net.initialize() without cover the parameters  before.





---
[Visit Topic](https://discuss.mxnet.io/t/parameter-initialization-error-in-customization-of-conv2d-kernel-with-ndarray-tensor/6452/1) or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.mxnet.io/email/unsubscribe/a3753c629182f61e7c0366af44546a86a89647c51fe6caf78614ba9892da376f).