iamstarlee / Multi-label-Sewer-Classification

This repository is based on sewer-ml dataset
https://vap.aau.dk/sewer-ml/
MIT License
17 stars 1 forks source link

验证问题 #8

Closed qianmeng19 closed 6 months ago

qianmeng19 commented 6 months ago

请问我修改了网络结构后,inference.py验证会出现错误,这种情况应该怎样解决

iamstarlee commented 6 months ago

报的啥错呢

---- 回复的原邮件 ---- | 发件人 | @.> | | 发送日期 | 2024年4月26日 21:54 | | 收件人 | @.> | | 抄送人 | @.***> | | 主题 | [iamstarlee/Multi-label-Sewer-Classification] 验证问题 (Issue #8) |

请问我修改了网络结构后,inference.py验证会出现错误,这种情况应该怎样解决

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

qianmeng19 commented 6 months ago

Traceback (most recent call last): File "E:\Multi-label-Sewer-Classification-main\inference.py", line 186, in run_inference(args) File "E:\Multi-label-Sewer-Classification-main\inference.py", line 128, in run_inference model.load_state_dict(updated_state_dict) File "C:\ProgramData\anaconda3\envs\torch\lib\site-packages\torch\nn\modules\module.py", line 2152, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for Xie2019: Missing key(s) in state_dict: "features.5.weight", "features.5.bias", "features.8.weight", "features.8.bias". Unexpected key(s) in state_dict: "features.3.weight", "features.3.bias", "features.6.weight", "features.6.bias". size mismatch for features.0.weight: copying a param with shape torch.Size([64, 3, 11, 11]) from checkpoint, the shape in current model is torch.Size([64, 11, 11, 11]).

qianmeng19 commented 6 months ago

还有就是训练好的模型是不是都是ckpt格式的,但是我的输出是名称是events.out.tfevents.1714136754.PC-202310272034,导致加载模型时报错:Traceback (most recent call last): File "E:\Multi-label-Sewer-Classification-main\inference.py", line 186, in run_inference(args) File "E:\Multi-label-Sewer-Classification-main\inference.py", line 111, in run_inference updated_state_dict, model_name, num_classes, training_mode, br_defect = load_model(model_path, best_weights) File "E:\Multi-label-Sewer-Classification-main\inference.py", line 69, in load_model model_last_ckpt = torch.load(last_ckpt_path) File "C:\ProgramData\anaconda3\envs\torch\lib\site-packages\torch\serialization.py", line 1028, in load return _legacy_load(opened_file, map_location, pickle_module, pickle_load_args) File "C:\ProgramData\anaconda3\envs\torch\lib\site-packages\torch\serialization.py", line 1246, in _legacy_load magic_number = pickle_module.load(f, pickle_load_args) _pickle.UnpicklingError: invalid load key, '\x18'.

iamstarlee commented 6 months ago

看上去是参数没对齐,就是你加载的模型参数不是inference.py代码里调用的模型训出来的

---- 回复的原邮件 ---- | 发件人 | @.> | | 发送日期 | 2024年4月26日 21:54 | | 收件人 | @.> | | 抄送人 | @.***> | | 主题 | [iamstarlee/Multi-label-Sewer-Classification] 验证问题 (Issue #8) |

请问我修改了网络结构后,inference.py验证会出现错误,这种情况应该怎样解决

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

iamstarlee commented 6 months ago

模型保存的格式除了ckpt还有pt,events.out.tfevents格式应该是tensorboard可视化的文件格式

---- 回复的原邮件 ---- | 发件人 | @.> | | 发送日期 | 2024年4月26日 22:14 | | 收件人 | @.> | | 抄送人 | Xinxin @.>, @.> | | 主题 | Re: [iamstarlee/Multi-label-Sewer-Classification] 验证问题 (Issue #8) |

还有就是训练好的模型是不是都是ckpt格式的,但是我的输出是名称是events.out.tfevents.1714136754.PC-202310272034,导致加载模型时报错:Traceback (most recent call last): File "E:\Multi-label-Sewer-Classification-main\inference.py", line 186, in run_inference(args) File "E:\Multi-label-Sewer-Classification-main\inference.py", line 111, in run_inference updated_state_dict, model_name, num_classes, training_mode, br_defect = load_model(model_path, best_weights) File "E:\Multi-label-Sewer-Classification-main\inference.py", line 69, in load_model model_last_ckpt = torch.load(last_ckpt_path) File "C:\ProgramData\anaconda3\envs\torch\lib\site-packages\torch\serialization.py", line 1028, in load return _legacy_load(opened_file, map_location, pickle_module, pickle_load_args) File "C:\ProgramData\anaconda3\envs\torch\lib\site-packages\torch\serialization.py", line 1246, in _legacy_load magic_number = pickle_module.load(f, pickle_load_args) _pickle.UnpicklingError: invalid load key, '\x18'.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

qianmeng19 commented 6 months ago

请问那这两个问题应该怎样解决呢

iamstarlee commented 6 months ago

你把你的模型结构代码和推理代码贴出来,我瞅瞅

qianmeng19 commented 6 months ago

可以给一下邮箱,通过邮箱发送吗

qianmeng19 commented 6 months ago

已发送谢谢

qianmeng19 commented 6 months ago

请问收到邮件了吗

iamstarlee commented 6 months ago

image image

  1. 模型应该加载你保存的ckpt
  2. 前向传播这可以直接add
  3. 你修改的模型是放在sewer_models.py或者ml_models.py里的吗?因为我没看到你的调用
qianmeng19 commented 6 months ago

1.加载events.out.tfevents格式的还是会报错:Traceback (most recent call last): File "E:\Multi-label-Sewer-Classification-main\inference.py", line 187, in run_inference(args) File "E:\Multi-label-Sewer-Classification-main\inference.py", line 112, in run_inference updated_state_dict, model_name, num_classes, training_mode, br_defect = load_model(model_path, best_weights) File "E:\Multi-label-Sewer-Classification-main\inference.py", line 70, in load_model model_last_ckpt = torch.load(last_ckpt_path) File "C:\ProgramData\anaconda3\envs\torch\lib\site-packages\torch\serialization.py", line 1028, in load return _legacy_load(opened_file, map_location, pickle_module, pickle_load_args) File "C:\ProgramData\anaconda3\envs\torch\lib\site-packages\torch\serialization.py", line 1246, in _legacy_load magic_number = pickle_module.load(f, pickle_load_args) _pickle.UnpicklingError: invalid load key, '\x18'. 但是测试ckpt的文件却能成功 2.前向传播是之前像用注意力机制融合但是没成功所以用的add 3.你是说训练完成events.out.tfevents格式的模型文件吗

qianmeng19 commented 6 months ago

我可以给你我的模型文件请问能帮我解决吗