Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'tuple' object has no attribute 'shape' #197

Open
sonnystalin opened this issue Oct 19, 2024 · 0 comments
Open

AttributeError: 'tuple' object has no attribute 'shape' #197

sonnystalin opened this issue Oct 19, 2024 · 0 comments

Comments

@sonnystalin
Copy link

Hi, I'm having trouble using the code to train on my own dataset. The problem occurs with the Gaussian_Diffusion module.

The question is as follows:

Traceback (most recent call last):
File "scripts/segmentation_train.py", line 118, in
main()
File "scripts/segmentation_train.py", line 70, in main
TrainLoop(
File "E:\MedSegDiff-Spine-main.\guided_diffusion\train_util.py", line 180, in run_loop
self.run_step(batch, cond)
File "E:\MedSegDiff-Spine-main.\guided_diffusion\train_util.py", line 201, in run_step
sample = self.forward_backward(batch, cond)
File "E:\MedSegDiff-Spine-main.\guided_diffusion\train_util.py", line 231, in forward_backward
losses1 = compute_losses()
File "E:\MedSegDiff-Spine-main.\guided_diffusion\gaussian_diffusion.py", line 650, in training_losses_segmentation
terms["loss"] = self._vb_terms_bpd(
File "E:\MedSegDiff-Spine-main.\guided_diffusion\gaussian_diffusion.py", line 614, in _vb_terms_bpd
out = self.p_mean_variance(
File "E:\MedSegDiff-Spine-main.\guided_diffusion\respace.py", line 90, in p_mean_variance
return super().p_mean_variance(self._wrap_model(model), *args, **kwargs)
File "E:\MedSegDiff-Spine-main.\guided_diffusion\gaussian_diffusion.py", line 267, in p_mean_variance
model_mean = self.q_posterior_mean_variance(
File "E:\MedSegDiff-Spine-main.\guided_diffusion\gaussian_diffusion.py", line 212, in q_posterior_mean_variance
assert x_start.shape == x_t.shape
AttributeError: 'tuple' object has no attribute 'shape'

The format of x_start is:
x_start type: <class 'tuple'>, value: (tensor([[[[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.],
      ...,
      [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.]],

     [[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.],
      ...,
      [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.]]],


    [[[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.]]]], device='cuda:0',
   grad_fn=<ConvolutionBackward0>), tensor([[[[0.5846, 0.4764, 0.4932,  ..., 0.5746, 0.5637, 0.5700],
      [0.5851, 0.6393, 0.7173,  ..., 0.5075, 0.5434, 0.4702],
      [0.5372, 0.5826, 0.8107,  ..., 0.5443, 0.6231, 0.4982],
      ...,
      [0.6365, 0.5709, 0.5678,  ..., 0.4498, 0.5057, 0.4866],
      [0.5337, 0.5445, 0.4393,  ..., 0.3687, 0.5252, 0.5495],
      [0.6406, 0.6942, 0.6227,  ..., 0.6035, 0.6418, 0.6114]]],


    [[[0.5541, 0.5860, 0.6421,  ..., 0.6785, 0.6934, 0.6377],
      [0.5828, 0.5905, 0.5781,  ..., 0.6483, 0.6696, 0.6074],
      [0.6532, 0.5950, 0.5979,  ..., 0.6306, 0.6737, 0.6274],
      ...,
      [0.6714, 0.6825, 0.6744,  ..., 0.5590, 0.5939, 0.5054],
      [0.6674, 0.6215, 0.6316,  ..., 0.4703, 0.4789, 0.4470],
      [0.6571, 0.6312, 0.6461,  ..., 0.5525, 0.5777, 0.5481]]],


    [[[0.5368, 0.5429, 0.5488,  ..., 0.4852, 0.4854, 0.4710],
      [0.5555, 0.5635, 0.6236,  ..., 0.5658, 0.5751, 0.4788],
      [0.5509, 0.5510, 0.6257,  ..., 0.5238, 0.5754, 0.5233],
      ...,
      [0.7045, 0.6531, 0.5366,  ..., 0.5109, 0.5114, 0.4738],
      [0.6715, 0.6297, 0.3976,  ..., 0.4826, 0.4157, 0.4372],
      [0.6479, 0.6427, 0.5018,  ..., 0.5952, 0.4995, 0.5293]]],


    ...,


    [[[0.5558, 0.5454, 0.6055,  ..., 0.5731, 0.5199, 0.5411],
      [0.5262, 0.6009, 0.7195,  ..., 0.5634, 0.5865, 0.5473],
      [0.5882, 0.6384, 0.6448,  ..., 0.4815, 0.6975, 0.4595],
      ...,
      [0.4299, 0.8450, 0.5439,  ..., 0.5943, 0.4213, 0.3321],
      [0.4318, 0.6034, 0.6760,  ..., 0.6217, 0.4202, 0.5185],
      [0.7269, 0.6352, 0.6566,  ..., 0.6751, 0.4266, 0.6503]]],


    [[[0.3344, 0.4871, 0.4382,  ..., 0.6347, 0.6236, 0.5605],
      [0.4082, 0.6057, 0.2145,  ..., 0.5594, 0.7679, 0.4599],
      [0.5393, 0.1673, 0.9391,  ..., 0.4425, 0.6835, 0.6310],
      ...,
      [0.7584, 0.6826, 0.5471,  ..., 0.8120, 0.3843, 0.5641],
      [0.5432, 0.5330, 0.3213,  ..., 0.4990, 0.4184, 0.5196],
      [0.6815, 0.6538, 0.7469,  ..., 0.7142, 0.5969, 0.6261]]],


    [[[0.6194, 0.7726, 0.6500,  ..., 0.6507, 0.5600, 0.5233],
      [0.7337, 0.6887, 0.3808,  ..., 0.7279, 0.5641, 0.5267],
      [0.5793, 0.3779, 0.3818,  ..., 0.9037, 0.8900, 0.2796],
      ...,
      [0.7714, 0.9128, 0.7506,  ..., 0.6294, 0.4318, 0.4752],
      [0.7695, 0.6399, 0.5966,  ..., 0.6750, 0.3901, 0.4319],
      [0.6037, 0.6148, 0.6483,  ..., 0.5312, 0.5273, 0.5470]]]],
   device='cuda:0', grad_fn=<SigmoidBackward0>))

Would you please help me solve this problem?Thank you! @WuJunde

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant