AttributeError: 'Parameter' object has no attribute '_ivar'
Created by: leonleeldc
我在用dygraph写动态图为基础的gan模型,我的generator是这样写的,
class generator(fluid.dygraph.Layer): # Network Architecture is exactly same as in infoGAN (https://arxiv.org/abs/1606.03657) # Architecture : FC1024_BR-FC7x7x128_BR-(64)4dc2s_BR-(1)4dc2s_S # from the main, we can see that input_dim=62, input_size=32 and output_dim=1 def init(self, name_scope, input_dim=62, output_dim=1, input_size=32, norm=True): super(generator, self).init(name_scope) self.input_dim = input_dim self.output_dim = output_dim self.input_size = input_size
self.fc = Linear(name_scope=name_scope + '_fc', input_size=self.input_dim,
output_size=128 * (self.input_size // 8) * (self.input_size // 8))
##128 * (self.input_size // 8) * (self.input_size // 8)
if norm:
self.bn = BatchNorm(self.full_name(),
num_channels=128 * (self.input_size // 8) * (self.input_size // 8),
param_attr=fluid.ParamAttr(
name="scale",
initializer=fluid.initializer.NormalInitializer(1.0,0.02)),
bias_attr=fluid.ParamAttr(
name="bias",
initializer=fluid.initializer.Constant(0.0)),
trainable_statistics=True
)
self.deconv = DeConv2D(self.full_name(),
num_filters=128,
filter_size=4,
stride=2,
stddev=0.02,
padding=[1, 1],
outpadding=[0, 1, 0, 1]
)
def forward(self, input):
x = self.fc(input)
x = self.bn(x)
x = fluid.layers.relu(x)
x = fluid.layers.reshape(x, [-1, 128, (self.input_size // 8), (self.input_size // 8)])
x = self.deconv(x)
#print('size of x in forward discriminator:{}'.format(x.shape))
return x
在call它的时候如下: with fluid.dygraph.guard(): z_ = np.random.normal(scale=1, size=[self.opt.batch_size, self.opt.z_dim]).astype("float32") z_ = fluid.dygraph.to_variable(z_) z_ = fluid.layers.gaussian_random(shape=[self.opt.batch_size, self.opt.z_dim]) G_ = self.G(z_) D_fake = self.D(G_) D_fake_loss = fluid.layers.softmax_with_cross_entropy(D_fake, self.y_fake_)
但是报错为: File "/media/data2/dingcheng/workspace/baidu/ccl/Likelihood_Gan/mnist_model_paddle/utils_paddle.py", line 79, in forward output_ = fluid.layers.matmul(input_, fluid.layers.transpose(self.W, perm=[1, 0])) File "/home/dingcheng/anaconda3/lib/python3.6/site-packages/paddle/fluid/layers/nn.py", line 7971, in transpose if convert_dtype(x.dtype) not in [ File "/home/dingcheng/anaconda3/lib/python3.6/site-packages/paddle/fluid/framework.py", line 1185, in dtype return self._ivar.dtype AttributeError: 'Parameter' object has no attribute '_ivar'
Not sure how I can fix this?
Thanks,