
上QQ阅读APP看书,第一时间看更新
1.6 EfficientNetV2建模
参照EfficientNetV2论文公布的源码,本节完成EfficientNetV2-S/M/L三个模型的编程。官方程序用列表描述模型的参数结构,以EfficientNetV2-S模型为例,其结构描述如下。
v2_s_block = [ 'r2_k3_s1_e1_i24_o24_c1' 'r4_k3_s2_e4_i24_o48_c1' 'r4_k3_s2_e4_i48_o64_c1' 'r6_k3_s2_e4_i64_o128_se0 25' 'r9_k3_s1_e6_i128_o160_se0 25' 'r15_k3_s2_e6_i160_o256_se0 25' ]
参照表1.9对EfficientNetV2-S模型的定义,v2_s_block中的参数符号解读如下。
r:当前Stage中Operator重复的次数repeats。
k:卷积核尺寸kernel_size。
s:步长stride。
e:升维倍率因子expansion ratio。
i:当前Stage的输入通道数input channels。
o:当前Stage的输出通道数output channels。
c:卷积类型,0表示Fused-MBConv,1表示MBConv。
se:表示SE模块第一个全连接层的通道压缩因子se_ratio。
打开PyCharm,新建项目TensorFlow_to_Android,按照本节视频教程提示,配置项目虚拟环境,安装TensorFlow和相关库。新建文件夹EfficientNetV2,在其中创建model.py程序,完成程序源码P1.1的编程与测试工作。








程序model.py编码有些长,其中包含了EfficientNetV2-S/M/L三种模型的实现逻辑,该逻辑极其容易扩展到其他模型,包括EfficientNetV1的系列模型。
程序model.py编码优雅,面向对象的结构化设计,层层递进,值得学习和模仿。
程序设计细节、运行测试结果及详细解析参见本节微课视频。