TypeError: new(): argument 'size' must be tuple of ints, but found element of type float at pos 2

TypeError: new(): argument 'size' must be tuple of ints, but found element of type float at pos 2

如上,這個bug是我用python3跑python2程序的時候出現的bug

# Down-Sampling
        curr_dim = conv_dim
        for i in range(repeat_num):
            layers.append(nn.Conv2d(curr_dim, int(curr_dim/2), kernel_size=4, stride=2, padding=1, bias=False))#int(curr_dim/2)
            layers.append(nn.InstanceNorm2d(int(curr_dim/2), affine=True))
            layers.append(nn.ReLU(inplace=True))
            curr_dim = curr_dim / 2

我在如上的地方,第四行報錯。但是明明已經將pos2 的參數改成了int還是報錯。後來發現

這個pos 2 指的不是 nn.Conv2d()函數。而是更底層的一個輸入(N, C_in,H,W) 。其參數C_in 在第二個位置。也即是我此處的第一個參數應該設置成int。因爲是for循環中循環的賦值了float。所以很容易錯誤的當做是第二個參數見了鬼了。啊 搞定

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章