Solved: I made mistake from other code.
Error from
conv1.weight=nn.Parameter(a.float().unsqueeze(0).unsqueeze(0))
# RuntimeError: Given groups=1, weight of size [1, 1, 3, 3], expected input[2, 3, 250, 250] to have 1 channels, but got 3 channels instead

can be resolved by
conv1.weight=nn.Parameter(a.float().unsqueeze(0).unsqueeze(0).repeat(1,3,1,1))


Hi, I have torch.Size([2, 3, 250, 250]) image
And I want to use following 2 custom sobel filters
a=torch.Tensor(
    [[1,0,-1],
     [2,0,-2],
     [1,0,-1]]).cuda()
b=torch.Tensor(
    [[1,2,1],
     [0,0,0],
     [-1,-2,-1]]).cuda()

print("ten",ten.shape)
# one_b_gt_imgs torch.Size([2, 3, 250, 250])

conv1=nn.Conv2d(3,3,kernel_size=3,stride=1,padding=1,bias=False)

# But I got following errors
# It looks like it's because kernel depth is not 3
conv1.weight=nn.Parameter(a.float().unsqueeze(0).unsqueeze(0))
# RuntimeError: Given groups=1, weight of size [1, 1, 3, 3], expected input[2, 3, 250, 250] to have 1 channels, but got 3 channels instead

# So, I used repeat()
# And I checked 
that "a.float().unsqueeze(0).unsqueeze(0).repeat(1,3,1,1)" converts tensor shape into (1,3,3,3)
conv1.weight=nn.Parameter(a.float().unsqueeze(0).unsqueeze(0).repeat(1,3,1,1))
# But I still have error and weight size is (1,1,3,3)
# RuntimeError: Given groups=1, weight of size [1, 1, 3, 3], expected input[2, 3, 250, 250] to have 1 channels, but got 3 channels instead

G_x=conv1(ten)

How to fix this?