# Cannot set output_size in ConvTranspose2d

I’ve been trying to use ConvTranspose2d with the following code.

``````upsample = nn.ConvTranspose2d(1024, 512, kernel_size=2)
e4=torch.randn(2, 512, 56, 56)
b=torch.randn(2, 1024, 28, 28)
b_1=upsample(b, output_size=e4.size())
``````

It is giving the error
ValueError: requested an output size of torch.Size([56, 56]), but valid sizes range from [29, 29] to [29, 29] (for an input of torch.Size([28, 28]))

I am confused with this and not able to solve. Can anyone help me on this. Thanks in advance!!!

``````upsample = nn.ConvTranspose2d(1024, 512, 3, stride=2, padding=1)
``````

Why not use this?

Thank you. This works. I get the intuition behind adding padding but why is stride needed for this?
{"ft_lang_label":"__label__en","ft_lang_prob":0.8435578,"math_prob":0.89966285,"size":489,"snap":"2020-10-2020-16","text_gpt3_token_len":156,"char_repetition_ratio":0.09072165,"word_repetition_ratio":0.0,"special_character_ratio":0.36605316,"punctuation_ratio":0.23076923,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9793659,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-04-05T04:14:04Z\",\"WARC-Record-ID\":\"<urn:uuid:b555feb9-ff30-4206-bc4c-712e32351890>\",\"Content-Length\":\"15268\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:22c8fc89-92d0-4ddc-8ec9-f5b3e153d5d2>\",\"WARC-Concurrent-To\":\"<urn:uuid:55f21744-326e-4fd1-919d-06fc70261b5e>\",\"WARC-IP-Address\":\"159.203.172.63\",\"WARC-Target-URI\":\"https://discuss.pytorch.org/t/cannot-set-output-size-in-convtranspose2d/74189\",\"WARC-Payload-Digest\":\"sha1:EJTKXNN4YTUFNMELYPH3MV6V5ZJFTQHE\",\"WARC-Block-Digest\":\"sha1:ESOEXBOW657WCJZTDOW7GIWEOTWQVWC5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-16/CC-MAIN-2020-16_segments_1585370528224.61_warc_CC-MAIN-20200405022138-20200405052138-00555.warc.gz\"}"}