question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dimensionality issue in testing TPN

See original GitHub issue
Torch - 0.4.1
scikit-image - 0.13.1
Python - 3.5.2

When running python3 main.py --mode test_TPN, I get the following error using the above mentioned configurations:

Traceback (most recent call last):
  File "main.py", line 79, in <module>
    main(args)
  File "main.py", line 31, in main
    solver.test_TPN()
  File "/home/mohsin/Text2Colors/solver.py", line 404, in test_TPN
    i)
  File "/home/mohsin/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/mohsin/Text2Colors/model/TPN.py", line 86, in forward
    gru_input = torch.cat((last_palette, context.squeeze(1)), 1)
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 11 and 32 in dimension 0 at /pytorch/aten/src/THC/generic/THCTensorMath.cu:87

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
FloatingFowlcommented, Feb 15, 2019

In model/TPN.py, change AttnDecoderRNN::forward() to this:

    def forward(self, last_palette, last_decoder_hidden, encoder_outputs, each_input_size, i):

        # Compute context vector.
        if i == 0:
            context = torch.mean(encoder_outputs, dim=0, keepdim=True)
            # Compute gru output.
            gru_input = torch.cat((last_palette, context.squeeze(0)), 1)
            gru_hidden = self.gru(gru_input, last_decoder_hidden)

            # Generate palette color.
            #palette = self.out(gru_hidden.squeeze(0))
            palette = self.out(gru_hidden.squeeze(1))
            return palette, context.unsqueeze(0), gru_hidden#, attn_weights

        else:
            attn_weights = self.attn(last_decoder_hidden.squeeze(0), encoder_outputs, each_input_size)
            context = torch.bmm(attn_weights, encoder_outputs.transpose(0,1))

            # Compute gru output.
            gru_input = torch.cat((last_palette, context.squeeze(1)), 1)
            gru_hidden = self.gru(gru_input, last_decoder_hidden)

            # Generate palette color.
            #palette = self.out(gru_hidden.squeeze(0))
            palette = self.out(gru_hidden.squeeze(1))
            return palette, context.unsqueeze(0), gru_hidden#, attn_weights

and remove the fourth receiving parameter whenever this is invoked.

As for the colourization network, I still haven’t got that to work.

0reactions
zhangbanxian123commented, Jul 23, 2020

In model/TPN.py, change AttnDecoderRNN::forward() to this:

    def forward(self, last_palette, last_decoder_hidden, encoder_outputs, each_input_size, i):

        # Compute context vector.
        if i == 0:
            context = torch.mean(encoder_outputs, dim=0, keepdim=True)
            # Compute gru output.
            gru_input = torch.cat((last_palette, context.squeeze(0)), 1)
            gru_hidden = self.gru(gru_input, last_decoder_hidden)

            # Generate palette color.
            #palette = self.out(gru_hidden.squeeze(0))
            palette = self.out(gru_hidden.squeeze(1))
            return palette, context.unsqueeze(0), gru_hidden#, attn_weights

        else:
            attn_weights = self.attn(last_decoder_hidden.squeeze(0), encoder_outputs, each_input_size)
            context = torch.bmm(attn_weights, encoder_outputs.transpose(0,1))

            # Compute gru output.
            gru_input = torch.cat((last_palette, context.squeeze(1)), 1)
            gru_hidden = self.gru(gru_input, last_decoder_hidden)

            # Generate palette color.
            #palette = self.out(gru_hidden.squeeze(0))
            palette = self.out(gru_hidden.squeeze(1))
            return palette, context.unsqueeze(0), gru_hidden#, attn_weights

and remove the fourth receiving parameter whenever this is invoked. As for the colourization network, I still haven’t got that to work.

Hi, thank you @FloatingFowl for solving the problem. However, the color is not good as expected. There is always like a red filter that covers the prediction. Is anything wrong? 14_color2

I have also reached your stage. There will also be a red mask. How did you solve it in the end? thank you very much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TPN Calculations | How to Solve these 5 Exam Type Questions
TPN Calculations Pharmacy | How to Solve these 5 Exam Type Questions. ... but ace every test as well as passing your board...
Read more >
How to solve 5 different TPN Calculations Questions - YouTube
This video illustrates step-b-step how to solve 5 different types of total parenteral nutrition ( TPN ) calculations practice problems.
Read more >
Total Parenteral Nutrition (TPN) - Calculations and ... - YouTube
Classroom lecture over the calculations and formulation of total parenteral nutrition ( TPN ).
Read more >
[1709.04418] Power in High-Dimensional Testing Problems
We study under which conditions this method can be applied and show the following: In asymptotic regimes where the dimensionality of the parameter...
Read more >
Total parenteral nutrition adversely affects gut barrier function ...
Unlike the former study, the latter experiment was not designed to test TPN vs. enteral nutrition. The authors also speculated that this may...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found