问题遇到的现象和发生背景
您好,在应用您的代码进行特征图可视化的时候,在加载模型之后报错,模型是自己构建的模型。
问题相关代码,请勿粘贴截图
def get_feature():
# 输入数据
root_path = 'M:\\uent_source\\unet-pytorch-main\\unet-pytorch-main\\unet-pytorch-main\\img\\'
pic_dir = '2_15.jpg'
rgb_path = root_path + pic_dir
img_rgb = get_picture(rgb_path, transform)
# 插入维度
img_rgb = img_rgb.unsqueeze(0)
img_rgb = img_rgb.to(device)
# 插入维度
# 加载模型,模型路径
num_classes = 2
pretrained = False
model = Unet(num_classes=num_classes, pretrained=pretrained).train()
# model_dict和model有什么格式上的区别
model.load_state_dict(torch.load(
'M:\\uent_source\\unet-pytorch-main\\unet-pytorch-main\\unet-pytorch-main\logs\ep100-loss0.041-val_loss0.072.pth'))
model.to(device)
exact_list = ["vgg1","vgg2","vgg3","vgg4","vgg5","up4_att","up4","up3_att","up3","up2_att","up2","up1_att","up1"]
# myexactor = FeatureExtractor(model, exact_list)
img1 = {'rgb': img_rgb}
result, all_dict = model(img_rgb)
outputs = []
运行结果及报错内容
我的解答思路和尝试过的方法
查看了加载的model字典的组成结构,问题出在result,all_dict=model(img_rgb)上,我不知道这里是不是指的是Unet模型返回的是两个参数,一个预测结果和一个字典格式,字典格式存放的又是什么呢?我是不是需要在网络结构类里返回这个字典呢?我的模型加载方式是否有问题呢?谢谢您的解答。
我想要达到的结果
能得到各个层的特征图的可视化。