Variations-of-SFANet-for-Crowd-Counting代码复现

前文对Variations-of-SFANet-for-Crowd-Counting做了一点基础梳理,并对开源框架的可视化代码进行了验证,链接如下:

Variations-of-SFANet-for-Crowd-Counting记录-CSDN博客

Variations-of-SFANet-for-Crowd-Counting可视化代码-CSDN博客

这里对训练和测试代码进行相关复现。

train.py代码测试

(1)预训练权重

由于训练代码有预训练权重,来自:GitHub - ZhihengCV/Bayesian-Crowd-Counting: Official Implement of ICCV 2019 oral paper Bayesian Loss for Crowd Count Estimation with Point Supervision

根据文献Bayesian Loss for Crowd Count Estimation with Point Supervision:https://arxiv.org/abs/1908.03684所述

预训练是在ImageNet 上进行的

(2)训练模型

由于本文改进了SegNet和SFA两个模型,因此在训练的时候要选择不同的模型

regression_trainer.py中,注意选择不同的模型

<1>M_SFANet_UCF_QNRF

注意模型选择和路径的选择

UCF_QNRF数据集经过贝叶斯处理的流程同前文记录

预训练权重在前文链接中可以下载

处理好了就可以开始训练

训练报错记录

RuntimeError: Error(s) in loading state_dict for Model:

详细报错如下

python 复制代码
RuntimeError: Error(s) in loading state_dict for Model:
        Missing key(s) in state_dict: "vgg.conv1_1.conv.weight", "vgg.conv1_1.conv.bias", "vgg.conv1_2.conv.weight", "vgg.conv1_2.conv.bias", "vgg.conv2_1.conv.weight", "vgg.conv2_1.conv.bias", "vgg.conv2_2.conv.weight", "vgg.conv2_2.conv.bias", "vgg.conv3_1.conv.weight", "vgg.conv3_1.conv.bias", "vgg.conv3_2.conv.weight", "vgg.conv3_2.conv.bias", "vgg.conv3_3.conv.weight", "vgg.conv3_3.conv.bias", "vgg.conv3_4.conv.weight", "vgg.conv3_4.conv.bias", "vgg.conv4_1.conv.weight", "vgg.conv4_1.conv.bias", "vgg.conv4_2.conv.weight", "vgg.conv4_2.conv.bias", "vgg.conv4_3.conv.weight", "vgg.conv4_3.conv.bias", "vgg.conv4_4.conv.weight", "vgg.conv4_4.conv.bias", "vgg.conv5_1.conv.weight", "vgg.conv5_1.conv.bias", "vgg.conv5_2.conv.weight", "vgg.conv5_2.conv.bias", "vgg.conv5_3.conv.weight", "vgg.conv5_3.conv.bias", "vgg.conv5_4.conv.weight", "vgg.conv5_4.conv.bias", "spm.assp.aspp1.atrous_conv.weight", "spm.assp.aspp2.atrous_conv.weight", "spm.assp.aspp3.atrous_conv.weight", "spm.assp.aspp4.atrous_conv.weight", "spm.assp.global_avg_pool.1.weight", "spm.assp.conv1.weight", "spm.can.scales.0.1.weight", "spm.can.scales.1.1.weight", "spm.can.scales.2.1.weight", "spm.can.scales.3.1.weight", "spm.can.bottleneck.weight", "spm.can.bottleneck.bias", "spm.can.weight_net.weight", "spm.can.weight_net.bias", "spm.reg_layer.0.weight", "spm.reg_layer.0.bias", "spm.reg_layer.2.weight", "spm.reg_layer.2.bias", "dmp.conv1.conv.weight", "dmp.conv1.conv.bias", "dmp.conv2.conv.weight", "dmp.conv2.conv.bias", "dmp.conv3.conv.weight", "dmp.conv3.conv.bias", "dmp.conv4.conv.weight", "dmp.conv4.conv.bias", "dmp.conv5.conv.weight", "dmp.conv5.conv.bias", "dmp.conv6.conv.weight", "dmp.conv6.conv.bias", "dmp.conv7.conv.weight", "dmp.conv7.conv.bias", "conv_out.conv.weight", "conv_out.conv.bias".
        Unexpected key(s) in state_dict: "features.0.weight", "features.0.bias", "features.2.weight", "features.2.bias", "features.5.weight", "features.5.bias", "features.7.weight", "features.7.bias", "features.10.weight", "features.10.bias", "features.12.weight", "features.12.bias", "features.14.weight", "features.14.bias", "features.16.weight", "features.16.bias", "features.19.weight", "features.19.bias", "features.21.weight", "features.21.bias", "features.23.weight", "features.23.bias", "features.25.weight", "features.25.bias", "features.28.weight", "features.28.bias", "features.30.weight", "features.30.bias", "features.32.weight", "features.32.bias", "features.34.weight", "features.34.bias", "reg_layer.0.weight", "reg_layer.0.bias", "reg_layer.2.weight", "reg_layer.2.bias", "reg_layer.4.weight", "reg_layer.4.bias".

网上查的都不好使,这里注意预训练权重的文件里不要放多个权重文件,只放UCF_QNRF对应的预训练权重就好

这里用了5个epoch,训练集和测试集各用了5张图片数据来验证网络能否跑通,训练日志如下。不要在意指标大小。

<2>M_SFANet_UCF_QNRF

注意模型选择和路径的选择

输出日志

其他的效仿上述代码就好了

test.py代码测试

这里直接用仓库提供的权重进行测试,然后改改路径,同样用了5张图片数据测试

这里只用M_SFANet_UCF_QNRF测试,输出如下,其他同理,就不再赘述

相关推荐
leoZ2312 小时前
本地跑大模型实战(七):llama.cpp 性能调优,让推理更快更省
java·人工智能·spring·生成对抗网络·语言模型·自然语言处理·llama
To_OC2 小时前
我把《天龙八部》塞进向量数据库后,终于搞懂了 RAG 到底是个啥
人工智能·llm·agent
蜡台2 小时前
AI Agent(智能体)入门基础教程
人工智能
Akir.weiwen3 小时前
Token 层差异:从颜色值到语义状态的三层跃迁
人工智能·设计规范
迷迭香yy3 小时前
集合竞价数据挖掘实战:用Python构建开盘信号识别系统
人工智能·python·数据挖掘
大模型momo4 小时前
Spring AI 实战:多 Agent 协作实战 —— 分工拆解复杂旅游行程任务
人工智能·spring·ai·agent·旅游
小程故事多_804 小时前
从A2C、TRPO、PPO到GRPO,强化学习策略梯度算法完整演进与大模型落地实战解析
人工智能·算法
冬奇Lab4 小时前
开源项目第176期:Better Harness — 不审查 diff,审查工作流本身,给 AI 编程 Agent 的五维评估框架
人工智能·开源·agent
冬奇Lab4 小时前
代码库知识库系列(07):混合检索 BM25 + 向量——Q8 还是失败,而且总分退步了
人工智能
ajassi20004 小时前
AI语音智能体开发日记(十一)为智能设备“声”临其境——详解音频资源自动化生成流程
人工智能·ai·ai编程