import numpy as np
import torch
import torch.nn as nn
import matplotlib.pyplot as plt
from PIL import Image
myim = Image.open("D:/Lenna.png")
myimgray=np.array(myim.convert("L"),dtype=np.float32)
imh,imw=myimgray.shape
myimgray_t=torch.from_numpy(myimgray.reshape(1,1,imh,imw))
myimgray_t.shape
kersize=5
ker=torch.ones(kersize,kersize,dtype=torch.float32)*-1
ker[2,2]=24
ker=ker.reshape((1,1,kersize,kersize))
conv2d=nn.Conv2d(1,2,(kersize,kersize),bias=False)
conv2d.weight.data[0]=ker
imconv2dout=conv2d(myimgray_t)
imconv2dout_im=imconv2dout.data.squeeze()
print("卷积后尺寸:",imconv2dout_im.shape)
plt.figure(figsize=(12,6))
plt.subplot(1,2,1)
plt.imshow(imconv2dout_im[0],camp=plt.cm.gray)
plt.axis("off")
plt.subplot(1,2,2)
plt.imshow(imconv2dout_im[1],camp=plt.cm.gray)
plt.axis("off")
plt.show()
请问为什么会出现以下报错?
environment:vsc