├── .gitignore ├── LICENSE ├── README.md ├── docs ├── dataset.md ├── index.md └── squeezenet │ ├── imgs │ ├── figure-2.png │ ├── loss.png │ ├── table-1.png │ ├── top-1-acc.png │ └── top-5-acc.png │ ├── index.md │ ├── log.md │ └── log2.md ├── mkdocs.yml ├── py ├── lib │ ├── __init__.py │ ├── data │ │ ├── __init__.py │ │ ├── create_train_val.py │ │ └── pascal_voc.py │ ├── models │ │ ├── __init__.py │ │ ├── mobilenet │ │ │ ├── __init__.py │ │ │ ├── conv_bn_relu.py │ │ │ ├── depthwise_separable_conv.py │ │ │ └── mobilenet.py │ │ ├── mobilenet_v2 │ │ │ ├── __init__.py │ │ │ ├── conv_bn_relu.py │ │ │ ├── inverted_residual.py │ │ │ └── mobilenet_v2.py │ │ ├── shufflenet │ │ │ ├── __init__.py │ │ │ ├── channel_shuffle.py │ │ │ ├── shufflenet.py │ │ │ └── shufflenet_unit.py │ │ ├── shufflenet_v2 │ │ │ ├── __init__.py │ │ │ ├── inverted_residual.py │ │ │ └── shufflenet_v2.py │ │ └── squeezenet │ │ │ ├── __init__.py │ │ │ ├── basic_conv2d.py │ │ │ ├── fire.py │ │ │ ├── fire_bypass.py │ │ │ ├── squeeze_net.py │ │ │ └── squeeze_net_bypass.py │ ├── test │ │ ├── __init__.py │ │ ├── test_basic_conv2d.py │ │ ├── test_fire.py │ │ ├── test_mobilenet.py │ │ ├── test_mobilenet_v2.py │ │ ├── test_shufflenet.py │ │ ├── test_shufflenet_v2.py │ │ ├── test_squeeze_net.py │ │ └── test_squeezenet_bypass.py │ └── utils │ │ ├── __init__.py │ │ ├── metrics.py │ │ └── util.py └── squeezenet │ └── train.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | py/lib/__pycache__/ 2 | 3 | py/.idea 4 | 5 | py/data 6 | 7 | py/__pycache__/ 8 | 9 | py/lib/models/__pycache__/ 10 | 11 | py/lib/utils/__pycache__/ 12 | 13 | py/data/ 14 | 15 | py/models/ 16 | 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LightWeightCNN 2 | 3 | [![Documentation Status](https://readthedocs.org/projects/lightweightcnn/badge/?version=latest)](https://lightweightcnn.readthedocs.io/zh_CN/latest/?badge=latest) [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) 4 | 5 | >轻量化卷积神经网络实现 6 | 7 | | CNN Architecture | Data Type (bit) | Model Size (MB) | GFlops (1080Ti) | Top-1 Acc(VOC 07+12) | Top-5 Acc(VOC 07+12) | 8 | |:----------------:|:---------------:|:---------------:|:-----------------:|:--------------------:|:--------------------:| 9 | | AlexNet | 32 | 233.081 | 1.429 | 68.24% | 94.22% | 10 | | SqueezeNet | 32 | 4.793 | 1.692 | 75.46% | 96.78% | 11 | | SqueezeNetBypass | 32 | 4.793 | 1.692 | 77.54% | 97.41% | 12 | 13 | ## 内容列表 14 | 15 | - [LightWeightCNN](#lightweightcnn) 16 | - [内容列表](#内容列表) 17 | - [背景](#背景) 18 | - [安装](#安装) 19 | - [文档工具安装](#文档工具安装) 20 | - [Python库依赖](#python库依赖) 21 | - [用法](#用法) 22 | - [文档浏览](#文档浏览) 23 | - [主要维护人员](#主要维护人员) 24 | - [致谢](#致谢) 25 | - [引用](#引用) 26 | - [参与贡献方式](#参与贡献方式) 27 | - [许可证](#许可证) 28 | 29 | ## 背景 30 | 31 | * [SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size](https://arxiv.org/abs/1602.07360) 32 | * [MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications](https://arxiv.org/abs/1704.04861) 33 | * [MobileNetV2: Inverted Residuals and Linear Bottlenecks](https://arxiv.org/abs/1801.04381) 34 | * [ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile](https://arxiv.org/abs/1707.01083) 35 | * [ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design](https://arxiv.org/abs/1807.11164) 36 | 37 | ## 安装 38 | 39 | ### 文档工具安装 40 | 41 | ``` 42 | $ pip install -r requirements.txt 43 | ``` 44 | 45 | ### Python库依赖 46 | 47 | ``` 48 | $ cd py 49 | $ pip install -r requirements.txt 50 | ``` 51 | 52 | ## 用法 53 | 54 | ### 文档浏览 55 | 56 | 有两种使用方式 57 | 58 | 1. 在线浏览文档:[LightWeightCNN](https://lightweightcnn.readthedocs.io/zh_CN/latest/) 59 | 60 | 2. 本地浏览文档,实现如下: 61 | 62 | ``` 63 | $ git clone https://github.com/zjZSTU/LightWeightCNN.git 64 | $ cd LightWeightCNN 65 | $ mkdocs serve 66 | ``` 67 | 启动本地服务器后即可登录浏览器`localhost:8000` 68 | 69 | ## 主要维护人员 70 | 71 | * zhujian - *Initial work* - [zjZSTU](https://github.com/zjZSTU) 72 | 73 | ## 致谢 74 | 75 | ### 引用 76 | 77 | ``` 78 | @misc{i2016squeezenet, 79 | title={SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size}, 80 | author={Forrest N. Iandola and Song Han and Matthew W. Moskewicz and Khalid Ashraf and William J. Dally and Kurt Keutzer}, 81 | year={2016}, 82 | eprint={1602.07360}, 83 | archivePrefix={arXiv}, 84 | primaryClass={cs.CV} 85 | } 86 | 87 | @misc{howard2017mobilenets, 88 | title={MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications}, 89 | author={Andrew G. Howard and Menglong Zhu and Bo Chen and Dmitry Kalenichenko and Weijun Wang and Tobias Weyand and Marco Andreetto and Hartwig Adam}, 90 | year={2017}, 91 | eprint={1704.04861}, 92 | archivePrefix={arXiv}, 93 | primaryClass={cs.CV} 94 | } 95 | 96 | @misc{s2018mobilenetv2, 97 | title={MobileNetV2: Inverted Residuals and Linear Bottlenecks}, 98 | author={Mark Sandler and Andrew Howard and Menglong Zhu and Andrey Zhmoginov and Liang-Chieh Chen}, 99 | year={2018}, 100 | eprint={1801.04381}, 101 | archivePrefix={arXiv}, 102 | primaryClass={cs.CV} 103 | } 104 | 105 | @misc{zhang2017shufflenet, 106 | title={ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices}, 107 | author={Xiangyu Zhang and Xinyu Zhou and Mengxiao Lin and Jian Sun}, 108 | year={2017}, 109 | eprint={1707.01083}, 110 | archivePrefix={arXiv}, 111 | primaryClass={cs.CV} 112 | } 113 | 114 | @misc{ma2018shufflenet, 115 | title={ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design}, 116 | author={Ningning Ma and Xiangyu Zhang and Hai-Tao Zheng and Jian Sun}, 117 | year={2018}, 118 | eprint={1807.11164}, 119 | archivePrefix={arXiv}, 120 | primaryClass={cs.CV} 121 | } 122 | 123 | @misc{pascal-voc-2007, 124 | author = "Everingham, M. and Van~Gool, L. and Williams, C. K. I. and Winn, J. and Zisserman, A.", 125 | title = "The {PASCAL} {V}isual {O}bject {C}lasses {C}hallenge 2007 {(VOC2007)} {R}esults", 126 | howpublished = "http://www.pascal-network.org/challenges/VOC/voc2007/workshop/index.html"} 127 | 128 | @misc{pascal-voc-2012, 129 | author = "Everingham, M. and Van~Gool, L. and Williams, C. K. I. and Winn, J. and Zisserman, A.", 130 | title = "The {PASCAL} {V}isual {O}bject {C}lasses {C}hallenge 2012 {(VOC2012)} {R}esults", 131 | howpublished = "http://www.pascal-network.org/challenges/VOC/voc2012/workshop/index.html"} 132 | ``` 133 | 134 | ## 参与贡献方式 135 | 136 | 欢迎任何人的参与!打开[issue](https://github.com/zjZSTU/LightWeightCNN/issues)或提交合并请求。 137 | 138 | 注意: 139 | 140 | * `GIT`提交,请遵守[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0-beta.4/)规范 141 | * 语义版本化,请遵守[Semantic Versioning 2.0.0](https://semver.org)规范 142 | * `README`编写,请遵守[standard-readme](https://github.com/RichardLitt/standard-readme)规范 143 | 144 | ## 许可证 145 | 146 | [Apache License 2.0](LICENSE) © 2020 zjZSTU 147 | -------------------------------------------------------------------------------- /docs/dataset.md: -------------------------------------------------------------------------------- 1 | 2 | # 数据集 3 | 4 | 参考:[[数据集][PASCAL VOC]07+12](https://blog.zhujian.life/posts/db93f7d2.html) 5 | 6 | 本仓库使用`PASCAL VOC 07 + 12`作为分类数据集 7 | 8 | ## 简介 9 | 10 | `PASCAL VOC`数据集包含了`20`类 11 | 12 | * `Person: person` 13 | * `Animal: bird, cat, cow(奶牛), dog, horse, sheep(绵羊)` 14 | * `Vehicle(交通工具): aeroplane(飞机), bicycle, boat(小船), bus(公共汽车), car(轿车), motorbike(摩托车), train(火车)` 15 | * `Indoor(室内): bottle(瓶子), chair(椅子), dining table(餐桌), potted plant(盆栽植物), sofa, tv/monitor(电视/显示器)` 16 | 17 | ## 07+12 18 | 19 | `07 + 12`数据集合并后,共得到如下数据: 20 | 21 | 1. 训练数据:`16551`张图像,共`40058`个目标 22 | 2. 测试素据:`4952`张图像,共`12032`个目标 23 | 24 | ## 实现 25 | 26 | * `py/lib/data/pascal_voc.py` 27 | * `py/lib/data/create_train_val.py` -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # LightWeightCNN 2 | 3 | 学习和使用轻量化卷积神经网络模型 4 | 5 | ## 概述 6 | 7 | 如何在保证检测精度的前提下,尽可能的减少模型大小,这也是研究`CNN`的一大热点问题。学习轻量化`CNN`模型发展中的重要节点: 8 | 9 | * [SqueezeNet](./squeezenet/index.md) 10 | 11 | ## 相关文档 12 | 13 | * [SQUEEZENET](https://blog.zhujian.life/posts/a2419158.html) -------------------------------------------------------------------------------- /docs/squeezenet/imgs/figure-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-learning-algorithm/LightWeightCNN/b3bed250520971c80bbc170958ff7f5b698be7cc/docs/squeezenet/imgs/figure-2.png -------------------------------------------------------------------------------- /docs/squeezenet/imgs/loss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-learning-algorithm/LightWeightCNN/b3bed250520971c80bbc170958ff7f5b698be7cc/docs/squeezenet/imgs/loss.png -------------------------------------------------------------------------------- /docs/squeezenet/imgs/table-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-learning-algorithm/LightWeightCNN/b3bed250520971c80bbc170958ff7f5b698be7cc/docs/squeezenet/imgs/table-1.png -------------------------------------------------------------------------------- /docs/squeezenet/imgs/top-1-acc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-learning-algorithm/LightWeightCNN/b3bed250520971c80bbc170958ff7f5b698be7cc/docs/squeezenet/imgs/top-1-acc.png -------------------------------------------------------------------------------- /docs/squeezenet/imgs/top-5-acc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-learning-algorithm/LightWeightCNN/b3bed250520971c80bbc170958ff7f5b698be7cc/docs/squeezenet/imgs/top-5-acc.png -------------------------------------------------------------------------------- /docs/squeezenet/index.md: -------------------------------------------------------------------------------- 1 | 2 | # SQUEEZENET 3 | 4 | 论文学习:[SQUEEZENET](https://blog.zhujian.life/posts/a2419158.html) 5 | 6 | ## 定义 7 | 8 | `SqueezeNet`包含了`2`个卷积层、`8`个`Fire`模块以及`1`个平均池化层。其实现如下 9 | 10 | ![](./imgs/table-1.png) 11 | 12 | 文章同时介绍了`SqueezeNet+ByPass`模型,也就是在`SqueezeNet`上添加残差连接,其实现如下 13 | 14 | ![](./imgs/figure-2.png) 15 | 16 | ## 实现 17 | 18 | 参考:[squeezenet.py ](https://github.com/pytorch/vision/blob/master/torchvision/models/squeezenet.py) 19 | 20 | 实现了`Fire`模块和`SqueezeNet`模型 21 | 22 | * `py/lib/models/fire.py` 23 | * `py/lib/models/squeeze_net.py` 24 | 25 | 同时结合残差连接实现`SqueezeNetBypass(SqueezeNet + simply bypass)` 26 | 27 | * `py/lib/models/fire_bypass.py` 28 | * `py/lib/models/squeeze_net_bypass.py` 29 | 30 | ## 训练 31 | 32 | 比较`AlexNet、SqueezeNet、SqueezeNetBypass` 33 | 34 | * 数据集:`voc 07+12` 35 | * 损失函数:交叉熵损失 36 | * 优化器:`Adam`,学习率`1e-3`,权重衰减`1e-4` 37 | * 随步长衰减:每隔`7`轮衰减`4%`,学习因子`0.96` 38 | * 迭代次数:`50` 39 | 40 | ## 训练结果 41 | 42 | ![](./imgs/loss.png) 43 | 44 | ![](./imgs/top-1-acc.png) 45 | 46 | ![](./imgs/top-5-acc.png) 47 | 48 | 训练日志参考[训练日志](./log2.md) 49 | 50 | ### 检测精度 51 | 52 | * `Top-1 Accuracy` 53 | * `SqueezeNetByPass: 77.54%` 54 | * `SqueezeNet: 75.46%` 55 | * `AlexNet: 68.24%` 56 | * `Top-1 Accuracy` 57 | * `SqueezeNetByPass: 97.41%` 58 | * `SqueezeNet: 96.78%` 59 | * `AlexNet: 94.22%` 60 | 61 | ### Flops和参数数目 62 | 63 | ``` 64 | alexnet: 1.429 GFlops - 233.081 MB 65 | squeezenet: 1.692 GFlops - 4.793 MB 66 | squeezenet-bypass: 1.692 GFlops - 4.793 MB 67 | ``` 68 | 69 | ## 小结 70 | 71 | | CNN Architecture | Data Type (bit) | Model Size (MB) | GFlops (1080Ti) | Top-1 Acc(VOC 07+12) | Top-5 Acc(VOC 07+12) | 72 | |:----------------:|:---------------:|:---------------:|:-----------------:|:--------------------:|:--------------------:| 73 | | AlexNet | 32 | 233.081 | 1.429 | 68.24% | 94.22% | 74 | | SqueezeNet | 32 | 4.793 | 1.692 | 75.46% | 96.78% | 75 | | SqueezeNetBypass | 32 | 4.793 | 1.692 | 77.54% | 97.41% | -------------------------------------------------------------------------------- /docs/squeezenet/log.md: -------------------------------------------------------------------------------- 1 | 2 | # 训练日志 3 | 4 | ``` 5 | $ python train.py 6 | {'train': , 'test': } 7 | {'train': 40058, 'test': 12032} 8 | SqueezeNetBypass - Epoch 0/49 9 | ---------- 10 | train Loss: 2.5084 Acc: 0.3273 11 | test Loss: 2.5926 Acc: 0.2758 12 | SqueezeNetBypass - Epoch 1/49 13 | ---------- 14 | train Loss: 2.1547 Acc: 0.4433 15 | test Loss: 2.2057 Acc: 0.4036 16 | SqueezeNetBypass - Epoch 2/49 17 | ---------- 18 | train Loss: 1.9113 Acc: 0.4943 19 | test Loss: 1.9772 Acc: 0.4516 20 | SqueezeNetBypass - Epoch 3/49 21 | ---------- 22 | train Loss: 1.7436 Acc: 0.5325 23 | test Loss: 1.7610 Acc: 0.5183 24 | SqueezeNetBypass - Epoch 4/49 25 | ---------- 26 | train Loss: 1.6061 Acc: 0.5595 27 | test Loss: 1.6200 Acc: 0.5646 28 | SqueezeNetBypass - Epoch 5/49 29 | ---------- 30 | train Loss: 1.5020 Acc: 0.5815 31 | test Loss: 1.5262 Acc: 0.5814 32 | SqueezeNetBypass - Epoch 6/49 33 | ---------- 34 | train Loss: 1.4193 Acc: 0.6002 35 | test Loss: 1.3986 Acc: 0.6144 36 | SqueezeNetBypass - Epoch 7/49 37 | ---------- 38 | train Loss: 1.3467 Acc: 0.6154 39 | test Loss: 1.3064 Acc: 0.6282 40 | SqueezeNetBypass - Epoch 8/49 41 | ---------- 42 | train Loss: 1.2972 Acc: 0.6247 43 | test Loss: 1.2744 Acc: 0.6462 44 | SqueezeNetBypass - Epoch 9/49 45 | ---------- 46 | train Loss: 1.2563 Acc: 0.6328 47 | test Loss: 1.2900 Acc: 0.6307 48 | SqueezeNetBypass - Epoch 10/49 49 | ---------- 50 | train Loss: 1.2065 Acc: 0.6445 51 | test Loss: 1.3188 Acc: 0.6195 52 | SqueezeNetBypass - Epoch 11/49 53 | ---------- 54 | train Loss: 1.1743 Acc: 0.6549 55 | test Loss: 1.1211 Acc: 0.6774 56 | SqueezeNetBypass - Epoch 12/49 57 | ---------- 58 | train Loss: 1.1408 Acc: 0.6611 59 | test Loss: 1.1875 Acc: 0.6518 60 | SqueezeNetBypass - Epoch 13/49 61 | ---------- 62 | train Loss: 1.1172 Acc: 0.6677 63 | test Loss: 1.0545 Acc: 0.6944 64 | SqueezeNetBypass - Epoch 14/49 65 | ---------- 66 | train Loss: 1.0744 Acc: 0.6804 67 | test Loss: 1.0657 Acc: 0.6874 68 | SqueezeNetBypass - Epoch 15/49 69 | ---------- 70 | train Loss: 1.0505 Acc: 0.6849 71 | test Loss: 1.0601 Acc: 0.6826 72 | SqueezeNetBypass - Epoch 16/49 73 | ---------- 74 | train Loss: 1.0322 Acc: 0.6908 75 | test Loss: 1.0591 Acc: 0.6862 76 | SqueezeNetBypass - Epoch 17/49 77 | ---------- 78 | train Loss: 1.0099 Acc: 0.6969 79 | test Loss: 1.2338 Acc: 0.6348 80 | SqueezeNetBypass - Epoch 18/49 81 | ---------- 82 | train Loss: 0.9964 Acc: 0.6982 83 | test Loss: 1.0125 Acc: 0.6961 84 | SqueezeNetBypass - Epoch 19/49 85 | ---------- 86 | train Loss: 0.9771 Acc: 0.7052 87 | test Loss: 0.9823 Acc: 0.7032 88 | SqueezeNetBypass - Epoch 20/49 89 | ---------- 90 | train Loss: 0.9572 Acc: 0.7107 91 | test Loss: 0.9810 Acc: 0.7025 92 | SqueezeNetBypass - Epoch 21/49 93 | ---------- 94 | train Loss: 0.9373 Acc: 0.7155 95 | test Loss: 1.0086 Acc: 0.6950 96 | SqueezeNetBypass - Epoch 22/49 97 | ---------- 98 | train Loss: 0.9204 Acc: 0.7199 99 | test Loss: 0.8952 Acc: 0.7275 100 | SqueezeNetBypass - Epoch 23/49 101 | ---------- 102 | train Loss: 0.9116 Acc: 0.7217 103 | test Loss: 0.9108 Acc: 0.7266 104 | SqueezeNetBypass - Epoch 24/49 105 | ---------- 106 | train Loss: 0.8965 Acc: 0.7262 107 | test Loss: 0.9044 Acc: 0.7237 108 | SqueezeNetBypass - Epoch 25/49 109 | ---------- 110 | train Loss: 0.8791 Acc: 0.7319 111 | test Loss: 0.8890 Acc: 0.7320 112 | SqueezeNetBypass - Epoch 26/49 113 | ---------- 114 | train Loss: 0.8692 Acc: 0.7354 115 | test Loss: 0.9075 Acc: 0.7270 116 | SqueezeNetBypass - Epoch 27/49 117 | ---------- 118 | train Loss: 0.8571 Acc: 0.7379 119 | test Loss: 0.8573 Acc: 0.7377 120 | SqueezeNetBypass - Epoch 28/49 121 | ---------- 122 | train Loss: 0.8347 Acc: 0.7435 123 | test Loss: 0.9733 Acc: 0.7032 124 | SqueezeNetBypass - Epoch 29/49 125 | ---------- 126 | train Loss: 0.8292 Acc: 0.7451 127 | test Loss: 0.8254 Acc: 0.7502 128 | SqueezeNetBypass - Epoch 30/49 129 | ---------- 130 | train Loss: 0.8136 Acc: 0.7502 131 | test Loss: 0.8532 Acc: 0.7368 132 | SqueezeNetBypass - Epoch 31/49 133 | ---------- 134 | train Loss: 0.8087 Acc: 0.7525 135 | test Loss: 0.8667 Acc: 0.7309 136 | SqueezeNetBypass - Epoch 32/49 137 | ---------- 138 | train Loss: 0.7959 Acc: 0.7564 139 | test Loss: 0.8570 Acc: 0.7344 140 | SqueezeNetBypass - Epoch 33/49 141 | ---------- 142 | train Loss: 0.7804 Acc: 0.7598 143 | test Loss: 0.7873 Acc: 0.7640 144 | SqueezeNetBypass - Epoch 34/49 145 | ---------- 146 | train Loss: 0.7780 Acc: 0.7584 147 | test Loss: 0.8719 Acc: 0.7391 148 | SqueezeNetBypass - Epoch 35/49 149 | ---------- 150 | train Loss: 0.7594 Acc: 0.7660 151 | test Loss: 0.8263 Acc: 0.7461 152 | SqueezeNetBypass - Epoch 36/49 153 | ---------- 154 | train Loss: 0.7539 Acc: 0.7673 155 | test Loss: 0.8178 Acc: 0.7453 156 | SqueezeNetBypass - Epoch 37/49 157 | ---------- 158 | train Loss: 0.7515 Acc: 0.7675 159 | test Loss: 0.7593 Acc: 0.7674 160 | SqueezeNetBypass - Epoch 38/49 161 | ---------- 162 | train Loss: 0.7308 Acc: 0.7752 163 | test Loss: 0.7917 Acc: 0.7546 164 | SqueezeNetBypass - Epoch 39/49 165 | ---------- 166 | train Loss: 0.7296 Acc: 0.7755 167 | test Loss: 0.8026 Acc: 0.7576 168 | SqueezeNetBypass - Epoch 40/49 169 | ---------- 170 | train Loss: 0.7169 Acc: 0.7816 171 | test Loss: 0.8378 Acc: 0.7419 172 | SqueezeNetBypass - Epoch 41/49 173 | ---------- 174 | train Loss: 0.7142 Acc: 0.7795 175 | test Loss: 0.8071 Acc: 0.7465 176 | SqueezeNetBypass - Epoch 42/49 177 | ---------- 178 | train Loss: 0.6974 Acc: 0.7844 179 | test Loss: 0.7682 Acc: 0.7631 180 | SqueezeNetBypass - Epoch 43/49 181 | ---------- 182 | train Loss: 0.6900 Acc: 0.7889 183 | test Loss: 0.7668 Acc: 0.7669 184 | SqueezeNetBypass - Epoch 44/49 185 | ---------- 186 | train Loss: 0.6846 Acc: 0.7882 187 | test Loss: 0.8049 Acc: 0.7478 188 | SqueezeNetBypass - Epoch 45/49 189 | ---------- 190 | train Loss: 0.6823 Acc: 0.7865 191 | test Loss: 0.7713 Acc: 0.7596 192 | SqueezeNetBypass - Epoch 46/49 193 | ---------- 194 | train Loss: 0.6741 Acc: 0.7907 195 | test Loss: 0.7822 Acc: 0.7584 196 | SqueezeNetBypass - Epoch 47/49 197 | ---------- 198 | train Loss: 0.6713 Acc: 0.7921 199 | test Loss: 0.8577 Acc: 0.7369 200 | SqueezeNetBypass - Epoch 48/49 201 | ---------- 202 | train Loss: 0.6559 Acc: 0.7963 203 | test Loss: 0.7478 Acc: 0.7694 204 | SqueezeNetBypass - Epoch 49/49 205 | ---------- 206 | train Loss: 0.6486 Acc: 0.7977 207 | test Loss: 0.8259 Acc: 0.7443 208 | Training SqueezeNetBypass complete in 96m 21s 209 | Best test Acc: 0.769365 210 | train SqueezeNetBypass done 211 | 212 | SqueezeNet - Epoch 0/49 213 | ---------- 214 | train Loss: 2.5148 Acc: 0.3288 215 | test Loss: 2.4962 Acc: 0.3223 216 | SqueezeNet - Epoch 1/49 217 | ---------- 218 | train Loss: 2.1876 Acc: 0.4269 219 | test Loss: 2.0729 Acc: 0.4646 220 | SqueezeNet - Epoch 2/49 221 | ---------- 222 | train Loss: 1.9591 Acc: 0.4822 223 | test Loss: 1.8296 Acc: 0.5127 224 | SqueezeNet - Epoch 3/49 225 | ---------- 226 | train Loss: 1.7898 Acc: 0.5160 227 | test Loss: 1.6819 Acc: 0.5333 228 | SqueezeNet - Epoch 4/49 229 | ---------- 230 | train Loss: 1.6473 Acc: 0.5455 231 | test Loss: 1.7200 Acc: 0.5155 232 | SqueezeNet - Epoch 5/49 233 | ---------- 234 | train Loss: 1.5435 Acc: 0.5708 235 | test Loss: 1.5075 Acc: 0.5897 236 | SqueezeNet - Epoch 6/49 237 | ---------- 238 | train Loss: 1.4610 Acc: 0.5853 239 | test Loss: 1.5257 Acc: 0.5572 240 | SqueezeNet - Epoch 7/49 241 | ---------- 242 | train Loss: 1.3881 Acc: 0.6024 243 | test Loss: 1.5355 Acc: 0.5672 244 | SqueezeNet - Epoch 8/49 245 | ---------- 246 | train Loss: 1.3312 Acc: 0.6134 247 | test Loss: 1.4117 Acc: 0.6045 248 | SqueezeNet - Epoch 9/49 249 | ---------- 250 | train Loss: 1.2917 Acc: 0.6227 251 | test Loss: 1.3569 Acc: 0.6184 252 | SqueezeNet - Epoch 10/49 253 | ---------- 254 | train Loss: 1.2448 Acc: 0.6334 255 | test Loss: 1.1867 Acc: 0.6574 256 | SqueezeNet - Epoch 11/49 257 | ---------- 258 | train Loss: 1.2143 Acc: 0.6407 259 | test Loss: 1.1527 Acc: 0.6658 260 | SqueezeNet - Epoch 12/49 261 | ---------- 262 | train Loss: 1.1717 Acc: 0.6513 263 | test Loss: 1.1283 Acc: 0.6681 264 | SqueezeNet - Epoch 13/49 265 | ---------- 266 | train Loss: 1.1452 Acc: 0.6585 267 | test Loss: 1.1221 Acc: 0.6621 268 | SqueezeNet - Epoch 14/49 269 | ---------- 270 | train Loss: 1.1222 Acc: 0.6636 271 | test Loss: 1.0849 Acc: 0.6772 272 | SqueezeNet - Epoch 15/49 273 | ---------- 274 | train Loss: 1.0940 Acc: 0.6714 275 | test Loss: 1.2034 Acc: 0.6439 276 | SqueezeNet - Epoch 16/49 277 | ---------- 278 | train Loss: 1.0739 Acc: 0.6778 279 | test Loss: 1.0126 Acc: 0.6984 280 | SqueezeNet - Epoch 17/49 281 | ---------- 282 | train Loss: 1.0492 Acc: 0.6834 283 | test Loss: 1.0827 Acc: 0.6735 284 | SqueezeNet - Epoch 18/49 285 | ---------- 286 | train Loss: 1.0306 Acc: 0.6886 287 | test Loss: 0.9800 Acc: 0.7051 288 | SqueezeNet - Epoch 19/49 289 | ---------- 290 | train Loss: 1.0195 Acc: 0.6926 291 | test Loss: 1.0237 Acc: 0.6883 292 | SqueezeNet - Epoch 20/49 293 | ---------- 294 | train Loss: 1.0070 Acc: 0.6950 295 | test Loss: 1.0059 Acc: 0.6937 296 | SqueezeNet - Epoch 21/49 297 | ---------- 298 | train Loss: 0.9753 Acc: 0.7038 299 | test Loss: 1.0064 Acc: 0.6987 300 | SqueezeNet - Epoch 22/49 301 | ---------- 302 | train Loss: 0.9701 Acc: 0.7036 303 | test Loss: 1.0386 Acc: 0.6800 304 | SqueezeNet - Epoch 23/49 305 | ---------- 306 | train Loss: 0.9527 Acc: 0.7094 307 | test Loss: 0.9486 Acc: 0.7172 308 | SqueezeNet - Epoch 24/49 309 | ---------- 310 | train Loss: 0.9404 Acc: 0.7150 311 | test Loss: 0.9049 Acc: 0.7235 312 | SqueezeNet - Epoch 25/49 313 | ---------- 314 | train Loss: 0.9353 Acc: 0.7147 315 | test Loss: 0.9444 Acc: 0.7094 316 | SqueezeNet - Epoch 26/49 317 | ---------- 318 | train Loss: 0.9212 Acc: 0.7193 319 | test Loss: 0.9309 Acc: 0.7150 320 | SqueezeNet - Epoch 27/49 321 | ---------- 322 | train Loss: 0.9031 Acc: 0.7237 323 | test Loss: 0.9096 Acc: 0.7212 324 | SqueezeNet - Epoch 28/49 325 | ---------- 326 | train Loss: 0.8902 Acc: 0.7288 327 | test Loss: 0.8558 Acc: 0.7405 328 | SqueezeNet - Epoch 29/49 329 | ---------- 330 | train Loss: 0.8852 Acc: 0.7275 331 | test Loss: 0.8695 Acc: 0.7342 332 | SqueezeNet - Epoch 30/49 333 | ---------- 334 | train Loss: 0.8750 Acc: 0.7309 335 | test Loss: 0.9280 Acc: 0.7211 336 | SqueezeNet - Epoch 31/49 337 | ---------- 338 | train Loss: 0.8554 Acc: 0.7376 339 | test Loss: 0.8960 Acc: 0.7276 340 | SqueezeNet - Epoch 32/49 341 | ---------- 342 | train Loss: 0.8481 Acc: 0.7397 343 | test Loss: 0.8596 Acc: 0.7369 344 | SqueezeNet - Epoch 33/49 345 | ---------- 346 | train Loss: 0.8423 Acc: 0.7388 347 | test Loss: 1.0105 Acc: 0.6932 348 | SqueezeNet - Epoch 34/49 349 | ---------- 350 | train Loss: 0.8352 Acc: 0.7421 351 | test Loss: 0.8282 Acc: 0.7459 352 | SqueezeNet - Epoch 35/49 353 | ---------- 354 | train Loss: 0.8224 Acc: 0.7460 355 | test Loss: 0.8422 Acc: 0.7405 356 | SqueezeNet - Epoch 36/49 357 | ---------- 358 | train Loss: 0.8132 Acc: 0.7499 359 | test Loss: 0.8385 Acc: 0.7421 360 | SqueezeNet - Epoch 37/49 361 | ---------- 362 | train Loss: 0.8050 Acc: 0.7525 363 | test Loss: 0.8047 Acc: 0.7559 364 | SqueezeNet - Epoch 38/49 365 | ---------- 366 | train Loss: 0.7981 Acc: 0.7522 367 | test Loss: 0.8336 Acc: 0.7399 368 | SqueezeNet - Epoch 39/49 369 | ---------- 370 | train Loss: 0.7887 Acc: 0.7562 371 | test Loss: 0.8146 Acc: 0.7471 372 | SqueezeNet - Epoch 40/49 373 | ---------- 374 | train Loss: 0.7819 Acc: 0.7602 375 | test Loss: 0.8227 Acc: 0.7463 376 | SqueezeNet - Epoch 41/49 377 | ---------- 378 | train Loss: 0.7726 Acc: 0.7607 379 | test Loss: 0.9496 Acc: 0.7112 380 | SqueezeNet - Epoch 42/49 381 | ---------- 382 | train Loss: 0.7621 Acc: 0.7648 383 | test Loss: 0.7967 Acc: 0.7519 384 | SqueezeNet - Epoch 43/49 385 | ---------- 386 | train Loss: 0.7574 Acc: 0.7663 387 | test Loss: 0.8003 Acc: 0.7545 388 | SqueezeNet - Epoch 44/49 389 | ---------- 390 | train Loss: 0.7490 Acc: 0.7677 391 | test Loss: 0.8497 Acc: 0.7384 392 | SqueezeNet - Epoch 45/49 393 | ---------- 394 | train Loss: 0.7434 Acc: 0.7706 395 | test Loss: 0.7976 Acc: 0.7575 396 | SqueezeNet - Epoch 46/49 397 | ---------- 398 | train Loss: 0.7458 Acc: 0.7688 399 | test Loss: 0.7760 Acc: 0.7639 400 | SqueezeNet - Epoch 47/49 401 | ---------- 402 | train Loss: 0.7265 Acc: 0.7769 403 | test Loss: 0.7954 Acc: 0.7551 404 | SqueezeNet - Epoch 48/49 405 | ---------- 406 | train Loss: 0.7222 Acc: 0.7764 407 | test Loss: 0.7835 Acc: 0.7539 408 | SqueezeNet - Epoch 49/49 409 | ---------- 410 | train Loss: 0.7152 Acc: 0.7753 411 | test Loss: 0.8050 Acc: 0.7506 412 | Training SqueezeNet complete in 95m 21s 413 | Best test Acc: 0.763880 414 | train SqueezeNet done 415 | 416 | AlexNet - Epoch 0/49 417 | ---------- 418 | train Loss: 2.4749 Acc: 0.3362 419 | test Loss: 2.1536 Acc: 0.4237 420 | AlexNet - Epoch 1/49 421 | ---------- 422 | train Loss: 2.2373 Acc: 0.3685 423 | test Loss: 1.9758 Acc: 0.4516 424 | AlexNet - Epoch 2/49 425 | ---------- 426 | train Loss: 2.0695 Acc: 0.4013 427 | test Loss: 1.8472 Acc: 0.4723 428 | AlexNet - Epoch 3/49 429 | ---------- 430 | train Loss: 1.9734 Acc: 0.4211 431 | test Loss: 1.7389 Acc: 0.5012 432 | AlexNet - Epoch 4/49 433 | ---------- 434 | train Loss: 1.8977 Acc: 0.4385 435 | test Loss: 1.7182 Acc: 0.4958 436 | AlexNet - Epoch 5/49 437 | ---------- 438 | train Loss: 1.8353 Acc: 0.4531 439 | test Loss: 1.6263 Acc: 0.5227 440 | AlexNet - Epoch 6/49 441 | ---------- 442 | train Loss: 1.7873 Acc: 0.4660 443 | test Loss: 1.5870 Acc: 0.5344 444 | AlexNet - Epoch 7/49 445 | ---------- 446 | train Loss: 1.7382 Acc: 0.4785 447 | test Loss: 1.5424 Acc: 0.5450 448 | AlexNet - Epoch 8/49 449 | ---------- 450 | train Loss: 1.7080 Acc: 0.4882 451 | test Loss: 1.5250 Acc: 0.5451 452 | AlexNet - Epoch 9/49 453 | ---------- 454 | train Loss: 1.6713 Acc: 0.4994 455 | test Loss: 1.4550 Acc: 0.5687 456 | AlexNet - Epoch 10/49 457 | ---------- 458 | train Loss: 1.6435 Acc: 0.5054 459 | test Loss: 1.4327 Acc: 0.5747 460 | AlexNet - Epoch 11/49 461 | ---------- 462 | train Loss: 1.6282 Acc: 0.5067 463 | test Loss: 1.4287 Acc: 0.5746 464 | AlexNet - Epoch 12/49 465 | ---------- 466 | train Loss: 1.6087 Acc: 0.5120 467 | test Loss: 1.4324 Acc: 0.5726 468 | AlexNet - Epoch 13/49 469 | ---------- 470 | train Loss: 1.5947 Acc: 0.5193 471 | test Loss: 1.3868 Acc: 0.5808 472 | AlexNet - Epoch 14/49 473 | ---------- 474 | train Loss: 1.5661 Acc: 0.5251 475 | test Loss: 1.3990 Acc: 0.5818 476 | AlexNet - Epoch 15/49 477 | ---------- 478 | train Loss: 1.5569 Acc: 0.5296 479 | test Loss: 1.3664 Acc: 0.5930 480 | AlexNet - Epoch 16/49 481 | ---------- 482 | train Loss: 1.5384 Acc: 0.5345 483 | test Loss: 1.3218 Acc: 0.6025 484 | AlexNet - Epoch 17/49 485 | ---------- 486 | train Loss: 1.5240 Acc: 0.5376 487 | test Loss: 1.3298 Acc: 0.5994 488 | AlexNet - Epoch 18/49 489 | ---------- 490 | train Loss: 1.5204 Acc: 0.5373 491 | test Loss: 1.3657 Acc: 0.5939 492 | AlexNet - Epoch 19/49 493 | ---------- 494 | train Loss: 1.5034 Acc: 0.5459 495 | test Loss: 1.3236 Acc: 0.5995 496 | AlexNet - Epoch 20/49 497 | ---------- 498 | train Loss: 1.4854 Acc: 0.5490 499 | test Loss: 1.3501 Acc: 0.5949 500 | AlexNet - Epoch 21/49 501 | ---------- 502 | train Loss: 1.4734 Acc: 0.5503 503 | test Loss: 1.3031 Acc: 0.6051 504 | AlexNet - Epoch 22/49 505 | ---------- 506 | train Loss: 1.4620 Acc: 0.5541 507 | test Loss: 1.3068 Acc: 0.6022 508 | AlexNet - Epoch 23/49 509 | ---------- 510 | train Loss: 1.4478 Acc: 0.5590 511 | test Loss: 1.2929 Acc: 0.6090 512 | AlexNet - Epoch 24/49 513 | ---------- 514 | train Loss: 1.4590 Acc: 0.5550 515 | test Loss: 1.3481 Acc: 0.5954 516 | AlexNet - Epoch 25/49 517 | ---------- 518 | train Loss: 1.4356 Acc: 0.5614 519 | test Loss: 1.2789 Acc: 0.6086 520 | AlexNet - Epoch 26/49 521 | ---------- 522 | train Loss: 1.4213 Acc: 0.5672 523 | test Loss: 1.2487 Acc: 0.6165 524 | AlexNet - Epoch 27/49 525 | ---------- 526 | train Loss: 1.4248 Acc: 0.5648 527 | test Loss: 1.2446 Acc: 0.6305 528 | AlexNet - Epoch 28/49 529 | ---------- 530 | train Loss: 1.4025 Acc: 0.5729 531 | test Loss: 1.2861 Acc: 0.6085 532 | AlexNet - Epoch 29/49 533 | ---------- 534 | train Loss: 1.3945 Acc: 0.5756 535 | test Loss: 1.2243 Acc: 0.6231 536 | AlexNet - Epoch 30/49 537 | ---------- 538 | train Loss: 1.4014 Acc: 0.5733 539 | test Loss: 1.2038 Acc: 0.6313 540 | AlexNet - Epoch 31/49 541 | ---------- 542 | train Loss: 1.3828 Acc: 0.5762 543 | test Loss: 1.2550 Acc: 0.6222 544 | AlexNet - Epoch 32/49 545 | ---------- 546 | train Loss: 1.3776 Acc: 0.5766 547 | test Loss: 1.2054 Acc: 0.6352 548 | AlexNet - Epoch 33/49 549 | ---------- 550 | train Loss: 1.3747 Acc: 0.5783 551 | test Loss: 1.2126 Acc: 0.6273 552 | AlexNet - Epoch 34/49 553 | ---------- 554 | train Loss: 1.3701 Acc: 0.5788 555 | test Loss: 1.2195 Acc: 0.6326 556 | AlexNet - Epoch 35/49 557 | ---------- 558 | train Loss: 1.3532 Acc: 0.5867 559 | test Loss: 1.1812 Acc: 0.6384 560 | AlexNet - Epoch 36/49 561 | ---------- 562 | train Loss: 1.3564 Acc: 0.5848 563 | test Loss: 1.2039 Acc: 0.6381 564 | AlexNet - Epoch 37/49 565 | ---------- 566 | train Loss: 1.3401 Acc: 0.5862 567 | test Loss: 1.1876 Acc: 0.6400 568 | AlexNet - Epoch 38/49 569 | ---------- 570 | train Loss: 1.3362 Acc: 0.5884 571 | test Loss: 1.2228 Acc: 0.6312 572 | AlexNet - Epoch 39/49 573 | ---------- 574 | train Loss: 1.3335 Acc: 0.5915 575 | test Loss: 1.1865 Acc: 0.6362 576 | AlexNet - Epoch 40/49 577 | ---------- 578 | train Loss: 1.3231 Acc: 0.5913 579 | test Loss: 1.2232 Acc: 0.6313 580 | AlexNet - Epoch 41/49 581 | ---------- 582 | train Loss: 1.3301 Acc: 0.5903 583 | test Loss: 1.1938 Acc: 0.6405 584 | AlexNet - Epoch 42/49 585 | ---------- 586 | train Loss: 1.3132 Acc: 0.5940 587 | test Loss: 1.2142 Acc: 0.6315 588 | AlexNet - Epoch 43/49 589 | ---------- 590 | train Loss: 1.3007 Acc: 0.5963 591 | test Loss: 1.1624 Acc: 0.6497 592 | AlexNet - Epoch 44/49 593 | ---------- 594 | train Loss: 1.3034 Acc: 0.5984 595 | test Loss: 1.1812 Acc: 0.6409 596 | AlexNet - Epoch 45/49 597 | ---------- 598 | train Loss: 1.3077 Acc: 0.5955 599 | test Loss: 1.2004 Acc: 0.6346 600 | AlexNet - Epoch 46/49 601 | ---------- 602 | train Loss: 1.2958 Acc: 0.6030 603 | test Loss: 1.1739 Acc: 0.6459 604 | AlexNet - Epoch 47/49 605 | ---------- 606 | train Loss: 1.2921 Acc: 0.6023 607 | test Loss: 1.1851 Acc: 0.6406 608 | AlexNet - Epoch 48/49 609 | ---------- 610 | train Loss: 1.2940 Acc: 0.6016 611 | test Loss: 1.1375 Acc: 0.6499 612 | AlexNet - Epoch 49/49 613 | ---------- 614 | train Loss: 1.2735 Acc: 0.6050 615 | test Loss: 1.1603 Acc: 0.6430 616 | Training AlexNet complete in 30m 26s 617 | Best test Acc: 0.649934 618 | train AlexNet done 619 | ``` -------------------------------------------------------------------------------- /docs/squeezenet/log2.md: -------------------------------------------------------------------------------- 1 | 2 | # 训练日志 3 | 4 | ``` 5 | $ python train.py 6 | {'train': , 'test': } 7 | {'train': 40058, 'test': 12032} 8 | SqueezeNetBypass - Epoch 0/49 9 | ---------- 10 | train Loss: 2.4975 Top-1 Acc: 33.5025 Top-5 Acc: 68.8558 11 | test Loss: 2.3326 Top-1 Acc: 37.4584 Top-5 Acc: 76.0638 12 | SqueezeNetBypass - Epoch 1/49 13 | ---------- 14 | train Loss: 2.1441 Top-1 Acc: 43.9573 Top-5 Acc: 79.8525 15 | test Loss: 2.2058 Top-1 Acc: 41.8301 Top-5 Acc: 75.8644 16 | SqueezeNetBypass - Epoch 2/49 17 | ---------- 18 | train Loss: 1.9189 Top-1 Acc: 49.2485 Top-5 Acc: 84.2432 19 | test Loss: 1.8774 Top-1 Acc: 50.3574 Top-5 Acc: 84.6243 20 | SqueezeNetBypass - Epoch 3/49 21 | ---------- 22 | train Loss: 1.7414 Top-1 Acc: 53.1581 Top-5 Acc: 87.2617 23 | test Loss: 1.6702 Top-1 Acc: 54.7540 Top-5 Acc: 87.2340 24 | SqueezeNetBypass - Epoch 4/49 25 | ---------- 26 | train Loss: 1.6044 Top-1 Acc: 55.8716 Top-5 Acc: 89.0657 27 | test Loss: 1.5297 Top-1 Acc: 58.1034 Top-5 Acc: 90.3590 28 | SqueezeNetBypass - Epoch 5/49 29 | ---------- 30 | train Loss: 1.5040 Top-1 Acc: 58.0345 Top-5 Acc: 90.3568 31 | test Loss: 1.4522 Top-1 Acc: 58.9678 Top-5 Acc: 90.3757 32 | SqueezeNetBypass - Epoch 6/49 33 | ---------- 34 | train Loss: 1.4147 Top-1 Acc: 59.9207 Top-5 Acc: 91.3169 35 | test Loss: 1.4671 Top-1 Acc: 57.1725 Top-5 Acc: 91.4312 36 | SqueezeNetBypass - Epoch 7/49 37 | ---------- 38 | train Loss: 1.3551 Top-1 Acc: 61.1519 Top-5 Acc: 91.7022 39 | test Loss: 1.3318 Top-1 Acc: 62.3504 Top-5 Acc: 92.3620 40 | SqueezeNetBypass - Epoch 8/49 41 | ---------- 42 | train Loss: 1.2950 Top-1 Acc: 62.3035 Top-5 Acc: 92.5215 43 | test Loss: 1.2239 Top-1 Acc: 64.1290 Top-5 Acc: 93.0851 44 | SqueezeNetBypass - Epoch 9/49 45 | ---------- 46 | train Loss: 1.2398 Top-1 Acc: 63.6944 Top-5 Acc: 92.9602 47 | test Loss: 1.2265 Top-1 Acc: 64.9518 Top-5 Acc: 93.8414 48 | SqueezeNetBypass - Epoch 10/49 49 | ---------- 50 | train Loss: 1.2013 Top-1 Acc: 64.5343 Top-5 Acc: 93.4698 51 | test Loss: 1.2074 Top-1 Acc: 65.3175 Top-5 Acc: 93.2763 52 | SqueezeNetBypass - Epoch 11/49 53 | ---------- 54 | train Loss: 1.1653 Top-1 Acc: 65.6374 Top-5 Acc: 93.7590 55 | test Loss: 1.1334 Top-1 Acc: 67.2623 Top-5 Acc: 94.3816 56 | SqueezeNetBypass - Epoch 12/49 57 | ---------- 58 | train Loss: 1.1352 Top-1 Acc: 66.4457 Top-5 Acc: 93.8190 59 | test Loss: 1.2011 Top-1 Acc: 64.8354 Top-5 Acc: 92.9771 60 | SqueezeNetBypass - Epoch 13/49 61 | ---------- 62 | train Loss: 1.1055 Top-1 Acc: 66.9644 Top-5 Acc: 94.2682 63 | test Loss: 1.1383 Top-1 Acc: 66.4894 Top-5 Acc: 93.6835 64 | SqueezeNetBypass - Epoch 14/49 65 | ---------- 66 | train Loss: 1.0746 Top-1 Acc: 67.9299 Top-5 Acc: 94.4956 67 | test Loss: 1.0554 Top-1 Acc: 68.6004 Top-5 Acc: 94.8221 68 | SqueezeNetBypass - Epoch 15/49 69 | ---------- 70 | train Loss: 1.0517 Top-1 Acc: 68.5152 Top-5 Acc: 94.6547 71 | test Loss: 1.0318 Top-1 Acc: 69.5977 Top-5 Acc: 94.8969 72 | SqueezeNetBypass - Epoch 16/49 73 | ---------- 74 | train Loss: 1.0277 Top-1 Acc: 69.1350 Top-5 Acc: 94.8628 75 | test Loss: 0.9873 Top-1 Acc: 70.6449 Top-5 Acc: 95.0216 76 | SqueezeNetBypass - Epoch 17/49 77 | ---------- 78 | train Loss: 1.0046 Top-1 Acc: 69.9446 Top-5 Acc: 95.0176 79 | test Loss: 1.0303 Top-1 Acc: 69.3733 Top-5 Acc: 95.0798 80 | SqueezeNetBypass - Epoch 18/49 81 | ---------- 82 | train Loss: 0.9912 Top-1 Acc: 70.0441 Top-5 Acc: 95.2219 83 | test Loss: 0.9527 Top-1 Acc: 71.5675 Top-5 Acc: 95.8029 84 | SqueezeNetBypass - Epoch 19/49 85 | ---------- 86 | train Loss: 0.9689 Top-1 Acc: 70.6621 Top-5 Acc: 95.2792 87 | test Loss: 1.0553 Top-1 Acc: 67.9854 Top-5 Acc: 95.2128 88 | SqueezeNetBypass - Epoch 20/49 89 | ---------- 90 | train Loss: 0.9513 Top-1 Acc: 71.2430 Top-5 Acc: 95.4786 91 | test Loss: 0.9768 Top-1 Acc: 70.0216 Top-5 Acc: 95.9275 92 | SqueezeNetBypass - Epoch 21/49 93 | ---------- 94 | train Loss: 0.9218 Top-1 Acc: 72.1476 Top-5 Acc: 95.8837 95 | test Loss: 0.9796 Top-1 Acc: 69.7640 Top-5 Acc: 95.5535 96 | SqueezeNetBypass - Epoch 22/49 97 | ---------- 98 | train Loss: 0.9190 Top-1 Acc: 72.1845 Top-5 Acc: 95.8637 99 | test Loss: 0.8958 Top-1 Acc: 73.1050 Top-5 Acc: 96.0356 100 | SqueezeNetBypass - Epoch 23/49 101 | ---------- 102 | train Loss: 0.8968 Top-1 Acc: 72.7515 Top-5 Acc: 95.9557 103 | test Loss: 0.8878 Top-1 Acc: 73.4292 Top-5 Acc: 96.4096 104 | SqueezeNetBypass - Epoch 24/49 105 | ---------- 106 | train Loss: 0.8846 Top-1 Acc: 72.9757 Top-5 Acc: 95.9952 107 | test Loss: 0.9984 Top-1 Acc: 69.4398 Top-5 Acc: 94.4980 108 | SqueezeNetBypass - Epoch 25/49 109 | ---------- 110 | train Loss: 0.8721 Top-1 Acc: 73.0418 Top-5 Acc: 96.0956 111 | test Loss: 0.9019 Top-1 Acc: 72.6978 Top-5 Acc: 95.5785 112 | SqueezeNetBypass - Epoch 26/49 113 | ---------- 114 | train Loss: 0.8612 Top-1 Acc: 73.6551 Top-5 Acc: 96.2706 115 | test Loss: 0.8436 Top-1 Acc: 74.6011 Top-5 Acc: 96.4594 116 | SqueezeNetBypass - Epoch 27/49 117 | ---------- 118 | train Loss: 0.8484 Top-1 Acc: 73.9027 Top-5 Acc: 96.3807 119 | test Loss: 0.8602 Top-1 Acc: 73.4624 Top-5 Acc: 95.9774 120 | SqueezeNetBypass - Epoch 28/49 121 | ---------- 122 | train Loss: 0.8321 Top-1 Acc: 74.5643 Top-5 Acc: 96.5274 123 | test Loss: 0.8639 Top-1 Acc: 73.3295 Top-5 Acc: 96.4844 124 | SqueezeNetBypass - Epoch 29/49 125 | ---------- 126 | train Loss: 0.8170 Top-1 Acc: 75.0831 Top-5 Acc: 96.4722 127 | test Loss: 0.8175 Top-1 Acc: 74.6011 Top-5 Acc: 96.5176 128 | SqueezeNetBypass - Epoch 30/49 129 | ---------- 130 | train Loss: 0.8091 Top-1 Acc: 75.1372 Top-5 Acc: 96.7994 131 | test Loss: 0.8670 Top-1 Acc: 73.0884 Top-5 Acc: 96.3846 132 | SqueezeNetBypass - Epoch 31/49 133 | ---------- 134 | train Loss: 0.7984 Top-1 Acc: 75.6112 Top-5 Acc: 96.7150 135 | test Loss: 0.8103 Top-1 Acc: 75.2909 Top-5 Acc: 96.7670 136 | SqueezeNetBypass - Epoch 32/49 137 | ---------- 138 | train Loss: 0.7893 Top-1 Acc: 75.7454 Top-5 Acc: 96.8473 139 | test Loss: 0.9004 Top-1 Acc: 72.4817 Top-5 Acc: 96.0439 140 | SqueezeNetBypass - Epoch 33/49 141 | ---------- 142 | train Loss: 0.7797 Top-1 Acc: 75.9302 Top-5 Acc: 96.8321 143 | test Loss: 0.8214 Top-1 Acc: 74.7756 Top-5 Acc: 96.3846 144 | SqueezeNetBypass - Epoch 34/49 145 | ---------- 146 | train Loss: 0.7733 Top-1 Acc: 76.3760 Top-5 Acc: 97.0493 147 | test Loss: 0.7781 Top-1 Acc: 76.2384 Top-5 Acc: 96.8999 148 | SqueezeNetBypass - Epoch 35/49 149 | ---------- 150 | train Loss: 0.7597 Top-1 Acc: 76.5940 Top-5 Acc: 96.9917 151 | test Loss: 0.7801 Top-1 Acc: 76.0888 Top-5 Acc: 96.9165 152 | SqueezeNetBypass - Epoch 36/49 153 | ---------- 154 | train Loss: 0.7446 Top-1 Acc: 76.9461 Top-5 Acc: 97.1739 155 | test Loss: 0.8194 Top-1 Acc: 74.1938 Top-5 Acc: 96.4927 156 | SqueezeNetBypass - Epoch 37/49 157 | ---------- 158 | train Loss: 0.7452 Top-1 Acc: 76.8747 Top-5 Acc: 97.0571 159 | test Loss: 0.8031 Top-1 Acc: 75.6566 Top-5 Acc: 96.2766 160 | SqueezeNetBypass - Epoch 38/49 161 | ---------- 162 | train Loss: 0.7283 Top-1 Acc: 77.5057 Top-5 Acc: 97.2019 163 | test Loss: 0.7943 Top-1 Acc: 75.5818 Top-5 Acc: 96.8501 164 | SqueezeNetBypass - Epoch 39/49 165 | ---------- 166 | train Loss: 0.7198 Top-1 Acc: 78.1052 Top-5 Acc: 97.2165 167 | test Loss: 0.8173 Top-1 Acc: 74.5013 Top-5 Acc: 96.5592 168 | SqueezeNetBypass - Epoch 40/49 169 | ---------- 170 | train Loss: 0.7173 Top-1 Acc: 77.9275 Top-5 Acc: 97.3112 171 | test Loss: 0.7979 Top-1 Acc: 75.4571 Top-5 Acc: 96.7586 172 | SqueezeNetBypass - Epoch 41/49 173 | ---------- 174 | train Loss: 0.7158 Top-1 Acc: 77.8273 Top-5 Acc: 97.4239 175 | test Loss: 0.7932 Top-1 Acc: 75.6981 Top-5 Acc: 96.3680 176 | SqueezeNetBypass - Epoch 42/49 177 | ---------- 178 | train Loss: 0.6984 Top-1 Acc: 78.5485 Top-5 Acc: 97.4040 179 | test Loss: 0.8421 Top-1 Acc: 74.0525 Top-5 Acc: 96.2932 180 | SqueezeNetBypass - Epoch 43/49 181 | ---------- 182 | train Loss: 0.6815 Top-1 Acc: 78.6779 Top-5 Acc: 97.6384 183 | test Loss: 0.7662 Top-1 Acc: 76.0389 Top-5 Acc: 96.9747 184 | SqueezeNetBypass - Epoch 44/49 185 | ---------- 186 | train Loss: 0.6782 Top-1 Acc: 79.1829 Top-5 Acc: 97.6461 187 | test Loss: 0.8090 Top-1 Acc: 74.9584 Top-5 Acc: 96.5592 188 | SqueezeNetBypass - Epoch 45/49 189 | ---------- 190 | train Loss: 0.6736 Top-1 Acc: 79.0775 Top-5 Acc: 97.6380 191 | test Loss: 0.7650 Top-1 Acc: 76.0888 Top-5 Acc: 96.9165 192 | SqueezeNetBypass - Epoch 46/49 193 | ---------- 194 | train Loss: 0.6741 Top-1 Acc: 79.1313 Top-5 Acc: 97.5528 195 | test Loss: 0.7498 Top-1 Acc: 76.6789 Top-5 Acc: 96.9747 196 | SqueezeNetBypass - Epoch 47/49 197 | ---------- 198 | train Loss: 0.6577 Top-1 Acc: 79.6215 Top-5 Acc: 97.7435 199 | test Loss: 0.7553 Top-1 Acc: 76.3630 Top-5 Acc: 96.9914 200 | SqueezeNetBypass - Epoch 48/49 201 | ---------- 202 | train Loss: 0.6450 Top-1 Acc: 79.9420 Top-5 Acc: 97.7659 203 | test Loss: 0.7592 Top-1 Acc: 76.5708 Top-5 Acc: 97.0412 204 | SqueezeNetBypass - Epoch 49/49 205 | ---------- 206 | train Loss: 0.6492 Top-1 Acc: 79.8792 Top-5 Acc: 97.7658 207 | test Loss: 0.7183 Top-1 Acc: 77.5432 Top-5 Acc: 97.4069 208 | Training SqueezeNetBypass complete in 96m 57s 209 | Best test Top-1 Acc: 77.543213 210 | Best test Top-5 Acc: 97.406914 211 | train SqueezeNetBypass done 212 | 213 | SqueezeNet - Epoch 0/49 214 | ---------- 215 | train Loss: 2.5180 Top-1 Acc: 32.7590 Top-5 Acc: 67.5427 216 | test Loss: 2.6335 Top-1 Acc: 24.8504 Top-5 Acc: 60.4804 217 | SqueezeNet - Epoch 1/49 218 | ---------- 219 | train Loss: 2.1925 Top-1 Acc: 42.5547 Top-5 Acc: 78.1116 220 | test Loss: 2.0045 Top-1 Acc: 50.0083 Top-5 Acc: 82.7460 221 | SqueezeNet - Epoch 2/49 222 | ---------- 223 | train Loss: 1.9805 Top-1 Acc: 47.2686 Top-5 Acc: 82.1583 224 | test Loss: 2.1289 Top-1 Acc: 41.8384 Top-5 Acc: 78.9478 225 | SqueezeNet - Epoch 3/49 226 | ---------- 227 | train Loss: 1.8098 Top-1 Acc: 51.1238 Top-5 Acc: 85.2740 228 | test Loss: 1.8039 Top-1 Acc: 52.3770 Top-5 Acc: 86.2035 229 | SqueezeNet - Epoch 4/49 230 | ---------- 231 | train Loss: 1.6934 Top-1 Acc: 53.2333 Top-5 Acc: 86.7647 232 | test Loss: 1.6206 Top-1 Acc: 56.0339 Top-5 Acc: 87.3836 233 | SqueezeNet - Epoch 5/49 234 | ---------- 235 | train Loss: 1.5869 Top-1 Acc: 55.5117 Top-5 Acc: 88.4345 236 | test Loss: 1.4971 Top-1 Acc: 58.8846 Top-5 Acc: 89.9269 237 | SqueezeNet - Epoch 6/49 238 | ---------- 239 | train Loss: 1.5111 Top-1 Acc: 57.0346 Top-5 Acc: 89.1982 240 | test Loss: 1.5991 Top-1 Acc: 54.0392 Top-5 Acc: 88.6220 241 | SqueezeNet - Epoch 7/49 242 | ---------- 243 | train Loss: 1.4431 Top-1 Acc: 58.4450 Top-5 Acc: 90.2515 244 | test Loss: 1.5550 Top-1 Acc: 56.2001 Top-5 Acc: 88.8381 245 | SqueezeNet - Epoch 8/49 246 | ---------- 247 | train Loss: 1.3798 Top-1 Acc: 60.1616 Top-5 Acc: 91.2254 248 | test Loss: 1.3994 Top-1 Acc: 58.8181 Top-5 Acc: 90.5086 249 | SqueezeNet - Epoch 9/49 250 | ---------- 251 | train Loss: 1.3416 Top-1 Acc: 60.7373 Top-5 Acc: 91.5030 252 | test Loss: 1.3699 Top-1 Acc: 59.9318 Top-5 Acc: 90.7414 253 | SqueezeNet - Epoch 10/49 254 | ---------- 255 | train Loss: 1.2958 Top-1 Acc: 61.9929 Top-5 Acc: 91.7551 256 | test Loss: 1.2568 Top-1 Acc: 64.0209 Top-5 Acc: 92.9521 257 | SqueezeNet - Epoch 11/49 258 | ---------- 259 | train Loss: 1.2551 Top-1 Acc: 62.9953 Top-5 Acc: 92.4331 260 | test Loss: 1.2617 Top-1 Acc: 62.5914 Top-5 Acc: 92.9438 261 | SqueezeNet - Epoch 12/49 262 | ---------- 263 | train Loss: 1.2250 Top-1 Acc: 63.7027 Top-5 Acc: 92.6961 264 | test Loss: 1.1962 Top-1 Acc: 64.6360 Top-5 Acc: 93.4092 265 | SqueezeNet - Epoch 13/49 266 | ---------- 267 | train Loss: 1.1855 Top-1 Acc: 64.8027 Top-5 Acc: 93.1747 268 | test Loss: 1.2325 Top-1 Acc: 63.3560 Top-5 Acc: 92.6695 269 | SqueezeNet - Epoch 14/49 270 | ---------- 271 | train Loss: 1.1615 Top-1 Acc: 65.3105 Top-5 Acc: 93.4501 272 | test Loss: 1.1089 Top-1 Acc: 66.9548 Top-5 Acc: 94.2985 273 | SqueezeNet - Epoch 15/49 274 | ---------- 275 | train Loss: 1.1349 Top-1 Acc: 66.0399 Top-5 Acc: 93.6169 276 | test Loss: 1.2257 Top-1 Acc: 63.1815 Top-5 Acc: 93.3843 277 | SqueezeNet - Epoch 16/49 278 | ---------- 279 | train Loss: 1.1137 Top-1 Acc: 66.6158 Top-5 Acc: 93.7639 280 | test Loss: 1.4182 Top-1 Acc: 59.1506 Top-5 Acc: 91.7387 281 | SqueezeNet - Epoch 17/49 282 | ---------- 283 | train Loss: 1.0964 Top-1 Acc: 66.8756 Top-5 Acc: 94.1711 284 | test Loss: 1.0480 Top-1 Acc: 68.5838 Top-5 Acc: 94.5645 285 | SqueezeNet - Epoch 18/49 286 | ---------- 287 | train Loss: 1.0764 Top-1 Acc: 67.4347 Top-5 Acc: 94.2738 288 | test Loss: 1.1023 Top-1 Acc: 66.7055 Top-5 Acc: 94.0243 289 | SqueezeNet - Epoch 19/49 290 | ---------- 291 | train Loss: 1.0604 Top-1 Acc: 68.2612 Top-5 Acc: 94.3355 292 | test Loss: 1.1024 Top-1 Acc: 66.8800 Top-5 Acc: 94.2320 293 | SqueezeNet - Epoch 20/49 294 | ---------- 295 | train Loss: 1.0458 Top-1 Acc: 68.3734 Top-5 Acc: 94.5459 296 | test Loss: 1.2591 Top-1 Acc: 62.3005 Top-5 Acc: 93.0352 297 | SqueezeNet - Epoch 21/49 298 | ---------- 299 | train Loss: 1.0156 Top-1 Acc: 69.3866 Top-5 Acc: 94.8405 300 | test Loss: 1.0876 Top-1 Acc: 67.1626 Top-5 Acc: 94.3068 301 | SqueezeNet - Epoch 22/49 302 | ---------- 303 | train Loss: 1.0011 Top-1 Acc: 69.5890 Top-5 Acc: 94.9426 304 | test Loss: 0.9803 Top-1 Acc: 70.4205 Top-5 Acc: 95.4372 305 | SqueezeNet - Epoch 23/49 306 | ---------- 307 | train Loss: 0.9977 Top-1 Acc: 69.4740 Top-5 Acc: 95.0572 308 | test Loss: 0.9741 Top-1 Acc: 70.0216 Top-5 Acc: 95.3540 309 | SqueezeNet - Epoch 24/49 310 | ---------- 311 | train Loss: 0.9811 Top-1 Acc: 70.0952 Top-5 Acc: 95.1342 312 | test Loss: 1.0440 Top-1 Acc: 68.7084 Top-5 Acc: 94.6310 313 | SqueezeNet - Epoch 25/49 314 | ---------- 315 | train Loss: 0.9722 Top-1 Acc: 70.1844 Top-5 Acc: 95.3017 316 | test Loss: 0.9670 Top-1 Acc: 70.6948 Top-5 Acc: 95.3624 317 | SqueezeNet - Epoch 26/49 318 | ---------- 319 | train Loss: 0.9518 Top-1 Acc: 71.0162 Top-5 Acc: 95.3239 320 | test Loss: 1.0088 Top-1 Acc: 69.1157 Top-5 Acc: 94.9136 321 | SqueezeNet - Epoch 27/49 322 | ---------- 323 | train Loss: 0.9515 Top-1 Acc: 70.6719 Top-5 Acc: 95.3865 324 | test Loss: 0.8906 Top-1 Acc: 73.0053 Top-5 Acc: 96.0938 325 | SqueezeNet - Epoch 28/49 326 | ---------- 327 | train Loss: 0.9274 Top-1 Acc: 71.4396 Top-5 Acc: 95.6289 328 | test Loss: 0.9498 Top-1 Acc: 71.5425 Top-5 Acc: 95.8693 329 | SqueezeNet - Epoch 29/49 330 | ---------- 331 | train Loss: 0.9193 Top-1 Acc: 71.8479 Top-5 Acc: 95.6658 332 | test Loss: 1.0117 Top-1 Acc: 69.7141 Top-5 Acc: 95.0133 333 | SqueezeNet - Epoch 30/49 334 | ---------- 335 | train Loss: 0.9098 Top-1 Acc: 72.0983 Top-5 Acc: 95.6184 336 | test Loss: 0.8587 Top-1 Acc: 73.3793 Top-5 Acc: 96.2600 337 | SqueezeNet - Epoch 31/49 338 | ---------- 339 | train Loss: 0.8957 Top-1 Acc: 72.6801 Top-5 Acc: 95.8935 340 | test Loss: 1.0524 Top-1 Acc: 68.1100 Top-5 Acc: 94.0824 341 | SqueezeNet - Epoch 32/49 342 | ---------- 343 | train Loss: 0.8967 Top-1 Acc: 72.3206 Top-5 Acc: 95.9036 344 | test Loss: 1.0314 Top-1 Acc: 67.9272 Top-5 Acc: 94.5645 345 | SqueezeNet - Epoch 33/49 346 | ---------- 347 | train Loss: 0.8825 Top-1 Acc: 72.6772 Top-5 Acc: 95.9611 348 | test Loss: 0.9516 Top-1 Acc: 70.6117 Top-5 Acc: 95.3707 349 | SqueezeNet - Epoch 34/49 350 | ---------- 351 | train Loss: 0.8765 Top-1 Acc: 72.9968 Top-5 Acc: 96.0608 352 | test Loss: 0.9686 Top-1 Acc: 70.7862 Top-5 Acc: 95.2959 353 | SqueezeNet - Epoch 35/49 354 | ---------- 355 | train Loss: 0.8641 Top-1 Acc: 73.3596 Top-5 Acc: 96.2405 356 | test Loss: 0.8590 Top-1 Acc: 73.4043 Top-5 Acc: 96.4927 357 | SqueezeNet - Epoch 36/49 358 | ---------- 359 | train Loss: 0.8556 Top-1 Acc: 73.6463 Top-5 Acc: 96.1857 360 | test Loss: 0.8587 Top-1 Acc: 73.3876 Top-5 Acc: 96.3930 361 | SqueezeNet - Epoch 37/49 362 | ---------- 363 | train Loss: 0.8442 Top-1 Acc: 73.9355 Top-5 Acc: 96.3528 364 | test Loss: 0.8419 Top-1 Acc: 74.2686 Top-5 Acc: 96.1187 365 | SqueezeNet - Epoch 38/49 366 | ---------- 367 | train Loss: 0.8338 Top-1 Acc: 74.1001 Top-5 Acc: 96.4301 368 | test Loss: 0.8683 Top-1 Acc: 73.4957 Top-5 Acc: 96.3015 369 | SqueezeNet - Epoch 39/49 370 | ---------- 371 | train Loss: 0.8321 Top-1 Acc: 74.3406 Top-5 Acc: 96.3557 372 | test Loss: 0.9070 Top-1 Acc: 72.4568 Top-5 Acc: 95.9857 373 | SqueezeNet - Epoch 40/49 374 | ---------- 375 | train Loss: 0.8273 Top-1 Acc: 74.4397 Top-5 Acc: 96.4828 376 | test Loss: 0.8482 Top-1 Acc: 74.0359 Top-5 Acc: 96.5924 377 | SqueezeNet - Epoch 41/49 378 | ---------- 379 | train Loss: 0.8169 Top-1 Acc: 74.7889 Top-5 Acc: 96.4927 380 | test Loss: 0.8654 Top-1 Acc: 73.2463 Top-5 Acc: 96.0522 381 | SqueezeNet - Epoch 42/49 382 | ---------- 383 | train Loss: 0.8004 Top-1 Acc: 75.1192 Top-5 Acc: 96.6823 384 | test Loss: 0.8592 Top-1 Acc: 73.5289 Top-5 Acc: 96.4345 385 | SqueezeNet - Epoch 43/49 386 | ---------- 387 | train Loss: 0.8052 Top-1 Acc: 75.1125 Top-5 Acc: 96.5873 388 | test Loss: 0.8383 Top-1 Acc: 74.5761 Top-5 Acc: 96.3098 389 | SqueezeNet - Epoch 44/49 390 | ---------- 391 | train Loss: 0.7877 Top-1 Acc: 75.7350 Top-5 Acc: 96.8343 392 | test Loss: 0.8263 Top-1 Acc: 75.0914 Top-5 Acc: 96.4345 393 | SqueezeNet - Epoch 45/49 394 | ---------- 395 | train Loss: 0.7801 Top-1 Acc: 76.0237 Top-5 Acc: 96.8274 396 | test Loss: 1.0009 Top-1 Acc: 68.6004 Top-5 Acc: 94.8138 397 | SqueezeNet - Epoch 46/49 398 | ---------- 399 | train Loss: 0.7834 Top-1 Acc: 75.5017 Top-5 Acc: 96.9289 400 | test Loss: 0.8271 Top-1 Acc: 74.7839 Top-5 Acc: 96.4179 401 | SqueezeNet - Epoch 47/49 402 | ---------- 403 | train Loss: 0.7755 Top-1 Acc: 75.9919 Top-5 Acc: 96.8344 404 | test Loss: 0.8011 Top-1 Acc: 75.4571 Top-5 Acc: 96.7753 405 | SqueezeNet - Epoch 48/49 406 | ---------- 407 | train Loss: 0.7752 Top-1 Acc: 75.8652 Top-5 Acc: 96.9269 408 | test Loss: 0.8278 Top-1 Acc: 74.3434 Top-5 Acc: 96.4013 409 | SqueezeNet - Epoch 49/49 410 | ---------- 411 | train Loss: 0.7645 Top-1 Acc: 76.2744 Top-5 Acc: 97.0461 412 | test Loss: 0.9688 Top-1 Acc: 70.4455 Top-5 Acc: 95.4205 413 | Training SqueezeNet complete in 95m 6s 414 | Best test Top-1 Acc: 75.457115 415 | Best test Top-5 Acc: 96.775261 416 | train SqueezeNet done 417 | 418 | AlexNet - Epoch 0/49 419 | ---------- 420 | train Loss: 2.5066 Top-1 Acc: 34.1264 Top-5 Acc: 61.4742 421 | test Loss: 2.1114 Top-1 Acc: 42.7693 Top-5 Acc: 69.4149 422 | AlexNet - Epoch 1/49 423 | ---------- 424 | train Loss: 2.1766 Top-1 Acc: 38.2940 Top-5 Acc: 70.9547 425 | test Loss: 1.8835 Top-1 Acc: 46.5758 Top-5 Acc: 78.9561 426 | AlexNet - Epoch 2/49 427 | ---------- 428 | train Loss: 2.0047 Top-1 Acc: 41.8978 Top-5 Acc: 76.7107 429 | test Loss: 1.7703 Top-1 Acc: 49.5595 Top-5 Acc: 81.7736 430 | AlexNet - Epoch 3/49 431 | ---------- 432 | train Loss: 1.8985 Top-1 Acc: 44.0686 Top-5 Acc: 79.4769 433 | test Loss: 1.6977 Top-1 Acc: 50.3989 Top-5 Acc: 83.9428 434 | AlexNet - Epoch 4/49 435 | ---------- 436 | train Loss: 1.8148 Top-1 Acc: 46.2988 Top-5 Acc: 81.6221 437 | test Loss: 1.6016 Top-1 Acc: 52.8092 Top-5 Acc: 85.1562 438 | AlexNet - Epoch 5/49 439 | ---------- 440 | train Loss: 1.7412 Top-1 Acc: 48.0521 Top-5 Acc: 83.1186 441 | test Loss: 1.5448 Top-1 Acc: 54.8454 Top-5 Acc: 86.9016 442 | AlexNet - Epoch 6/49 443 | ---------- 444 | train Loss: 1.6908 Top-1 Acc: 49.6548 Top-5 Acc: 84.0105 445 | test Loss: 1.4808 Top-1 Acc: 56.5492 Top-5 Acc: 88.5389 446 | AlexNet - Epoch 7/49 447 | ---------- 448 | train Loss: 1.6407 Top-1 Acc: 50.6352 Top-5 Acc: 85.2146 449 | test Loss: 1.4503 Top-1 Acc: 57.0811 Top-5 Acc: 88.1150 450 | AlexNet - Epoch 8/49 451 | ---------- 452 | train Loss: 1.6105 Top-1 Acc: 51.8596 Top-5 Acc: 85.7600 453 | test Loss: 1.3936 Top-1 Acc: 58.1117 Top-5 Acc: 89.1789 454 | AlexNet - Epoch 9/49 455 | ---------- 456 | train Loss: 1.5751 Top-1 Acc: 52.6515 Top-5 Acc: 86.3556 457 | test Loss: 1.3947 Top-1 Acc: 58.7018 Top-5 Acc: 89.4199 458 | AlexNet - Epoch 10/49 459 | ---------- 460 | train Loss: 1.5491 Top-1 Acc: 53.3838 Top-5 Acc: 86.9409 461 | test Loss: 1.3627 Top-1 Acc: 58.4275 Top-5 Acc: 90.4505 462 | AlexNet - Epoch 11/49 463 | ---------- 464 | train Loss: 1.5237 Top-1 Acc: 53.8743 Top-5 Acc: 87.0713 465 | test Loss: 1.3596 Top-1 Acc: 58.9844 Top-5 Acc: 89.5861 466 | AlexNet - Epoch 12/49 467 | ---------- 468 | train Loss: 1.5175 Top-1 Acc: 54.0585 Top-5 Acc: 87.4781 469 | test Loss: 1.3409 Top-1 Acc: 59.8570 Top-5 Acc: 89.8105 470 | AlexNet - Epoch 13/49 471 | ---------- 472 | train Loss: 1.4866 Top-1 Acc: 54.8596 Top-5 Acc: 87.8250 473 | test Loss: 1.3078 Top-1 Acc: 60.3973 Top-5 Acc: 90.7497 474 | AlexNet - Epoch 14/49 475 | ---------- 476 | train Loss: 1.4719 Top-1 Acc: 55.2191 Top-5 Acc: 88.1096 477 | test Loss: 1.3207 Top-1 Acc: 60.4555 Top-5 Acc: 90.4006 478 | AlexNet - Epoch 15/49 479 | ---------- 480 | train Loss: 1.4585 Top-1 Acc: 55.4976 Top-5 Acc: 88.2722 481 | test Loss: 1.2766 Top-1 Acc: 61.2201 Top-5 Acc: 90.9741 482 | AlexNet - Epoch 16/49 483 | ---------- 484 | train Loss: 1.4334 Top-1 Acc: 56.2062 Top-5 Acc: 88.9037 485 | test Loss: 1.2329 Top-1 Acc: 61.9265 Top-5 Acc: 91.6805 486 | AlexNet - Epoch 17/49 487 | ---------- 488 | train Loss: 1.4284 Top-1 Acc: 56.5625 Top-5 Acc: 88.7888 489 | test Loss: 1.2611 Top-1 Acc: 61.2035 Top-5 Acc: 91.5891 490 | AlexNet - Epoch 18/49 491 | ---------- 492 | train Loss: 1.4109 Top-1 Acc: 56.9197 Top-5 Acc: 89.0636 493 | test Loss: 1.2924 Top-1 Acc: 60.2310 Top-5 Acc: 91.0239 494 | AlexNet - Epoch 19/49 495 | ---------- 496 | train Loss: 1.3987 Top-1 Acc: 57.4944 Top-5 Acc: 89.5923 497 | test Loss: 1.3004 Top-1 Acc: 61.1453 Top-5 Acc: 91.1154 498 | AlexNet - Epoch 20/49 499 | ---------- 500 | train Loss: 1.3848 Top-1 Acc: 57.7185 Top-5 Acc: 89.5399 501 | test Loss: 1.2113 Top-1 Acc: 63.3145 Top-5 Acc: 92.2290 502 | AlexNet - Epoch 21/49 503 | ---------- 504 | train Loss: 1.3741 Top-1 Acc: 57.9207 Top-5 Acc: 89.4272 505 | test Loss: 1.2116 Top-1 Acc: 62.6912 Top-5 Acc: 91.8883 506 | AlexNet - Epoch 22/49 507 | ---------- 508 | train Loss: 1.3670 Top-1 Acc: 58.0260 Top-5 Acc: 89.7728 509 | test Loss: 1.1874 Top-1 Acc: 63.2148 Top-5 Acc: 91.9049 510 | AlexNet - Epoch 23/49 511 | ---------- 512 | train Loss: 1.3527 Top-1 Acc: 58.3070 Top-5 Acc: 90.0006 513 | test Loss: 1.1974 Top-1 Acc: 62.3670 Top-5 Acc: 92.4867 514 | AlexNet - Epoch 24/49 515 | ---------- 516 | train Loss: 1.3326 Top-1 Acc: 58.8321 Top-5 Acc: 90.5463 517 | test Loss: 1.1863 Top-1 Acc: 64.1373 Top-5 Acc: 92.3122 518 | AlexNet - Epoch 25/49 519 | ---------- 520 | train Loss: 1.3456 Top-1 Acc: 58.6931 Top-5 Acc: 90.2346 521 | test Loss: 1.1700 Top-1 Acc: 64.1456 Top-5 Acc: 92.3454 522 | AlexNet - Epoch 26/49 523 | ---------- 524 | train Loss: 1.3300 Top-1 Acc: 59.1015 Top-5 Acc: 90.3020 525 | test Loss: 1.1797 Top-1 Acc: 63.9794 Top-5 Acc: 92.6612 526 | AlexNet - Epoch 27/49 527 | ---------- 528 | train Loss: 1.3214 Top-1 Acc: 59.5033 Top-5 Acc: 90.5654 529 | test Loss: 1.1799 Top-1 Acc: 64.3617 Top-5 Acc: 92.1709 530 | AlexNet - Epoch 28/49 531 | ---------- 532 | train Loss: 1.3032 Top-1 Acc: 59.8075 Top-5 Acc: 90.7784 533 | test Loss: 1.1671 Top-1 Acc: 64.5196 Top-5 Acc: 92.4451 534 | AlexNet - Epoch 29/49 535 | ---------- 536 | train Loss: 1.3024 Top-1 Acc: 59.9483 Top-5 Acc: 90.7875 537 | test Loss: 1.1440 Top-1 Acc: 65.2842 Top-5 Acc: 93.2763 538 | AlexNet - Epoch 30/49 539 | ---------- 540 | train Loss: 1.2924 Top-1 Acc: 60.2901 Top-5 Acc: 90.7931 541 | test Loss: 1.1843 Top-1 Acc: 63.8630 Top-5 Acc: 92.2041 542 | AlexNet - Epoch 31/49 543 | ---------- 544 | train Loss: 1.2893 Top-1 Acc: 60.3126 Top-5 Acc: 90.8007 545 | test Loss: 1.1638 Top-1 Acc: 64.7191 Top-5 Acc: 92.3953 546 | AlexNet - Epoch 32/49 547 | ---------- 548 | train Loss: 1.2759 Top-1 Acc: 60.7694 Top-5 Acc: 91.1880 549 | test Loss: 1.1472 Top-1 Acc: 64.8354 Top-5 Acc: 92.9771 550 | AlexNet - Epoch 33/49 551 | ---------- 552 | train Loss: 1.2717 Top-1 Acc: 60.7037 Top-5 Acc: 91.3455 553 | test Loss: 1.1660 Top-1 Acc: 64.3783 Top-5 Acc: 92.4535 554 | AlexNet - Epoch 34/49 555 | ---------- 556 | train Loss: 1.2721 Top-1 Acc: 60.7573 Top-5 Acc: 91.1929 557 | test Loss: 1.1446 Top-1 Acc: 65.1097 Top-5 Acc: 93.1599 558 | AlexNet - Epoch 35/49 559 | ---------- 560 | train Loss: 1.2509 Top-1 Acc: 61.2797 Top-5 Acc: 91.5676 561 | test Loss: 1.1344 Top-1 Acc: 65.4338 Top-5 Acc: 93.0269 562 | AlexNet - Epoch 36/49 563 | ---------- 564 | train Loss: 1.2523 Top-1 Acc: 61.3537 Top-5 Acc: 91.6267 565 | test Loss: 1.1379 Top-1 Acc: 65.2759 Top-5 Acc: 93.0851 566 | AlexNet - Epoch 37/49 567 | ---------- 568 | train Loss: 1.2411 Top-1 Acc: 61.6800 Top-5 Acc: 91.7746 569 | test Loss: 1.1044 Top-1 Acc: 66.8467 Top-5 Acc: 93.5090 570 | AlexNet - Epoch 38/49 571 | ---------- 572 | train Loss: 1.2350 Top-1 Acc: 61.7012 Top-5 Acc: 91.8444 573 | test Loss: 1.1332 Top-1 Acc: 65.0765 Top-5 Acc: 93.3261 574 | AlexNet - Epoch 39/49 575 | ---------- 576 | train Loss: 1.2317 Top-1 Acc: 61.6074 Top-5 Acc: 91.8167 577 | test Loss: 1.1001 Top-1 Acc: 65.9408 Top-5 Acc: 93.5755 578 | AlexNet - Epoch 40/49 579 | ---------- 580 | train Loss: 1.2227 Top-1 Acc: 62.2035 Top-5 Acc: 91.7596 581 | test Loss: 1.1170 Top-1 Acc: 66.1652 Top-5 Acc: 93.1682 582 | AlexNet - Epoch 41/49 583 | ---------- 584 | train Loss: 1.2298 Top-1 Acc: 61.9686 Top-5 Acc: 91.8421 585 | test Loss: 1.0737 Top-1 Acc: 66.8634 Top-5 Acc: 93.5422 586 | AlexNet - Epoch 42/49 587 | ---------- 588 | train Loss: 1.2144 Top-1 Acc: 62.4991 Top-5 Acc: 91.9795 589 | test Loss: 1.0707 Top-1 Acc: 67.0462 Top-5 Acc: 93.9328 590 | AlexNet - Epoch 43/49 591 | ---------- 592 | train Loss: 1.2070 Top-1 Acc: 62.7659 Top-5 Acc: 92.0440 593 | test Loss: 1.0793 Top-1 Acc: 67.1958 Top-5 Acc: 93.6336 594 | AlexNet - Epoch 44/49 595 | ---------- 596 | train Loss: 1.2012 Top-1 Acc: 62.6833 Top-5 Acc: 92.1458 597 | test Loss: 1.0910 Top-1 Acc: 66.2566 Top-5 Acc: 93.6004 598 | AlexNet - Epoch 45/49 599 | ---------- 600 | train Loss: 1.2083 Top-1 Acc: 62.5817 Top-5 Acc: 92.1864 601 | test Loss: 1.0762 Top-1 Acc: 67.1210 Top-5 Acc: 93.5339 602 | AlexNet - Epoch 46/49 603 | ---------- 604 | train Loss: 1.1945 Top-1 Acc: 62.8733 Top-5 Acc: 92.2588 605 | test Loss: 1.0752 Top-1 Acc: 67.0047 Top-5 Acc: 93.6918 606 | AlexNet - Epoch 47/49 607 | ---------- 608 | train Loss: 1.1851 Top-1 Acc: 63.1584 Top-5 Acc: 92.4706 609 | test Loss: 1.0844 Top-1 Acc: 66.8384 Top-5 Acc: 93.7666 610 | AlexNet - Epoch 48/49 611 | ---------- 612 | train Loss: 1.1825 Top-1 Acc: 63.0629 Top-5 Acc: 92.5186 613 | test Loss: 1.0695 Top-1 Acc: 67.4119 Top-5 Acc: 93.5588 614 | AlexNet - Epoch 49/49 615 | ---------- 616 | train Loss: 1.1678 Top-1 Acc: 63.6297 Top-5 Acc: 92.6931 617 | test Loss: 1.0263 Top-1 Acc: 68.2846 Top-5 Acc: 94.2154 618 | Training AlexNet complete in 30m 10s 619 | Best test Top-1 Acc: 68.284569 620 | Best test Top-5 Acc: 94.215424 621 | train AlexNet done 622 | ``` -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | # 站点名称 2 | site_name: 'LightWeightCNN' 3 | # 仓库链接 4 | repo_url: https://github.com/zjZSTU/LightWeightCNN.git 5 | # 作者 6 | site_author: 'zhujian' 7 | # 版权信息 8 | copyright: '2020, zhujian' 9 | # 源文件目录 10 | docs_dir: 'docs' 11 | # 生成静态文件目录 12 | site_dir: 'site' 13 | # 额外信息 14 | extra: 15 | # 版本号 16 | version: 0.1.0 17 | # 主题 18 | theme: 19 | # name: 'readthedocs' 20 | # name: 'mkdocs' 21 | name: 'material' 22 | # markdown扩展 23 | markdown_extensions: 24 | - toc: 25 | permalink: true 26 | - pymdownx.arithmatex 27 | 28 | extra_javascript: 29 | - 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML' 30 | # 导航 31 | nav: 32 | - Home: index.md 33 | - 数据集: dataset.md 34 | - SqueezeNet: 35 | 引言: 'squeezenet/index.md' 36 | 训练日志: './squeezenet/log2.md' -------------------------------------------------------------------------------- /py/lib/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午3:32 5 | @file: __init__.py.py 6 | @author: zj 7 | @description: 8 | """ -------------------------------------------------------------------------------- /py/lib/data/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午3:32 5 | @file: __init__.py.py 6 | @author: zj 7 | @description: 8 | """ -------------------------------------------------------------------------------- /py/lib/data/create_train_val.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/3/26 下午2:50 5 | @file: create_train_val.py 6 | @author: zj 7 | @description: 提取分类任务的训练/测试集,分类别保存 8 | """ 9 | 10 | import cv2 11 | import numpy as np 12 | import os 13 | import xmltodict 14 | 15 | #### for train 16 | # aeroplane 1171 17 | # bicycle 1064 18 | # bird 1605 19 | # boat 1140 20 | # bottle 1764 21 | # bus 822 22 | # car 3267 23 | # cat 1593 24 | # chair 3152 25 | # cow 847 26 | # diningtable 824 27 | # dog 2025 28 | # horse 1072 29 | # motorbike 1052 30 | # person 13256 31 | # pottedplant 1487 32 | # sheep 1070 33 | # sofa 814 34 | # train 925 35 | # tvmonitor 1108 36 | # total train num: 40058 37 | #### for test 38 | # aeroplane 285 39 | # bicycle 337 40 | # bird 459 41 | # boat 263 42 | # bottle 469 43 | # bus 213 44 | # car 1201 45 | # cat 358 46 | # chair 756 47 | # cow 244 48 | # diningtable 206 49 | # dog 489 50 | # horse 348 51 | # motorbike 325 52 | # person 4528 53 | # pottedplant 480 54 | # sheep 242 55 | # sofa 239 56 | # train 282 57 | # tvmonitor 308 58 | # total test num: 12032 59 | 60 | alphabets = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 61 | 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'] 62 | 63 | 64 | def check_dir(data_dir): 65 | if not os.path.exists(data_dir): 66 | os.mkdir(data_dir) 67 | 68 | 69 | def find_all_cate_rects(annotation_dir, name_list): 70 | """ 71 | 找出所有的类别的标注框(取消标记为difficult的边界框) 72 | """ 73 | cate_list = list() 74 | for i in range(20): 75 | cate_list.append(list()) 76 | 77 | for name in name_list: 78 | annotation_path = os.path.join(annotation_dir, name + ".xml") 79 | with open(annotation_path, 'rb') as f: 80 | xml_dict = xmltodict.parse(f) 81 | # print(xml_dict) 82 | 83 | objects = xml_dict['annotation']['object'] 84 | if isinstance(objects, list): 85 | for obj in objects: 86 | obj_name = obj['name'] 87 | obj_idx = alphabets.index(obj_name) 88 | 89 | difficult = int(obj['difficult']) 90 | if difficult != 1: 91 | bndbox = obj['bndbox'] 92 | cate_list[obj_idx].append({'img_name': name, 'rect': 93 | (int(bndbox['xmin']), int(bndbox['ymin']), int(bndbox['xmax']), int(bndbox['ymax']))}) 94 | elif isinstance(objects, dict): 95 | obj_name = objects['name'] 96 | obj_idx = alphabets.index(obj_name) 97 | 98 | difficult = int(objects['difficult']) 99 | if difficult != 1: 100 | bndbox = objects['bndbox'] 101 | cate_list[obj_idx].append({'img_name': name, 'rect': 102 | (int(bndbox['xmin']), int(bndbox['ymin']), int(bndbox['xmax']), int(bndbox['ymax']))}) 103 | else: 104 | pass 105 | 106 | return cate_list 107 | 108 | 109 | def save_cate(cate_list, image_dir, res_dir): 110 | """ 111 | 保存裁剪的图像 112 | """ 113 | # 保存image_dir下所有图像,以便后续查询 114 | # 前提条件:足够的内存!!! 115 | # image_dict = dict() 116 | # image_name_list = os.listdir(image_dir) 117 | # for name in image_name_list: 118 | # image_path = os.path.join(image_dir, name) 119 | # img = cv2.imread(image_path) 120 | # 121 | # image_dict[name.split('.')[0]] = img 122 | 123 | # 遍历所有类别,保存标注的图像 124 | for i in range(20): 125 | cate_name = alphabets[i] 126 | cate_dir = os.path.join(res_dir, cate_name) 127 | check_dir(cate_dir) 128 | 129 | for item in cate_list[i]: 130 | img_name = item['img_name'] 131 | xmin, ymin, xmax, ymax = item['rect'] 132 | 133 | image_path = os.path.join(image_dir, img_name+'.jpg') 134 | img = cv2.imread(image_path) 135 | rect_img = img[ymin:ymax, xmin:xmax] 136 | # rect_img = image_dict[img_name][ymin:ymax, xmin:xmax] 137 | img_path = os.path.join(cate_dir, '%s-%d-%d-%d-%d.png' % (img_name, xmin, ymin, xmax, ymax)) 138 | cv2.imwrite(img_path, rect_img) 139 | 140 | 141 | if __name__ == '__main__': 142 | root_dir = '../../data/pascal-voc/' 143 | train_txt_path = '../../data/pascal-voc/train/name.csv' 144 | val_txt_path = '../../data/pascal-voc/test/name.csv' 145 | 146 | for phase in ['train', 'test']: 147 | if phase == 'train': 148 | suffix = 'train_imgs' 149 | else: 150 | suffix = 'test_imgs' 151 | dst_dir = os.path.join(root_dir, suffix) 152 | check_dir(dst_dir) 153 | print(dst_dir) 154 | 155 | name_path = os.path.join(root_dir, phase, 'name.csv') 156 | name_list = np.loadtxt(name_path, dtype=np.str, delimiter=' ') 157 | 158 | annotation_dir = os.path.join(root_dir, phase, 'Annotations') 159 | rects_list = find_all_cate_rects(annotation_dir, name_list) 160 | 161 | total_num = 0 162 | # 打印出每个类别的数据 163 | for i in range(20): 164 | total_num += len(rects_list[i]) 165 | print(alphabets[i], len(rects_list[i])) 166 | print('total {} num: {}'.format(phase, total_num)) 167 | 168 | image_dir = os.path.join(root_dir, phase, 'JPEGImages') 169 | save_cate(rects_list, image_dir, dst_dir) 170 | 171 | print() 172 | print('done') 173 | -------------------------------------------------------------------------------- /py/lib/data/pascal_voc.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/6 下午4:14 5 | @file: pascal_voc.py 6 | @author: zj 7 | @description: 解析07+12数据集 8 | """ 9 | 10 | import os 11 | import cv2 12 | import shutil 13 | import numpy as np 14 | from torchvision.datasets import VOCDetection 15 | 16 | # 2007 trainval 17 | 18 | trainval_07_annotations = '../../data/VOCtrainval_06-Nov-2007/VOCdevkit/VOC2007/Annotations' 19 | trainval_07_image = '../../data/VOCtrainval_06-Nov-2007/VOCdevkit/VOC2007/JPEGImages' 20 | trainval_07_txt = '../../data/VOCtrainval_06-Nov-2007/VOCdevkit/VOC2007/ImageSets/Main/trainval.txt' 21 | 22 | # 2007 test 23 | 24 | test_07_annotations = '../../data/VOCtest_06-Nov-2007/VOCdevkit/VOC2007/Annotations' 25 | test_07_image = '../../data/VOCtest_06-Nov-2007/VOCdevkit/VOC2007/JPEGImages' 26 | test_07_txt = '../../data/VOCtest_06-Nov-2007/VOCdevkit/VOC2007/ImageSets/Main/test.txt' 27 | 28 | # 2012 trainval 29 | 30 | trainval_12_annotations = '../../data/VOCtrainval_11-May-2012/VOCdevkit/VOC2012/Annotations' 31 | trainval_12_image = '../../data/VOCtrainval_11-May-2012/VOCdevkit/VOC2012/JPEGImages' 32 | trainval_12_txt = '../../data/VOCtrainval_11-May-2012/VOCdevkit/VOC2012/ImageSets/Main/trainval.txt' 33 | 34 | 35 | def check_dir(data_dir): 36 | if not os.path.exists(data_dir): 37 | os.mkdir(data_dir) 38 | 39 | 40 | def parse_data(txt_path, annotation_dir, image_dir): 41 | """ 42 | 解析txt文件,返回相应的图像和标注文件 43 | :return: 44 | """ 45 | name_list = np.loadtxt(txt_path, dtype=np.str, delimiter=' ') 46 | print(name_list) 47 | 48 | annotation_list = [os.path.join(annotation_dir, name + ".xml") for name in name_list] 49 | image_list = [os.path.join(image_dir, name + ".jpg") for name in name_list] 50 | 51 | return name_list, annotation_list, image_list 52 | 53 | 54 | if __name__ == '__main__': 55 | data_dir = '../../data/pascal-voc' 56 | check_dir(data_dir) 57 | 58 | txt_list = [trainval_07_txt, trainval_12_txt, test_07_txt] 59 | annotation_list = [trainval_07_annotations, trainval_12_annotations, test_07_annotations] 60 | image_list = [trainval_07_image, trainval_12_image, test_07_image] 61 | 62 | total_train_list = list() 63 | total_test_list = list() 64 | 65 | for txt_path, annotation_dir, image_dir in zip(txt_list, annotation_list, image_list): 66 | print(txt_path, annotation_dir, image_dir) 67 | name_list, annotation_list, image_list = parse_data(txt_path, annotation_dir, image_dir) 68 | 69 | if 'trainval' in txt_path: 70 | suffix = 'train' 71 | total_train_list.extend(name_list) 72 | else: 73 | suffix = 'test' 74 | total_test_list.extend(name_list) 75 | 76 | # 新建结果文件夹 77 | dst_dir = os.path.join(data_dir, suffix) 78 | check_dir(dst_dir) 79 | dst_annotation_dir = os.path.join(dst_dir, 'Annotations') 80 | check_dir(dst_annotation_dir) 81 | dst_image_dir = os.path.join(dst_dir, 'JPEGImages') 82 | check_dir(dst_image_dir) 83 | 84 | # 依次复制标注文件和图像 85 | for name, src_annotation_path, src_image_path in zip(name_list, annotation_list, image_list): 86 | dst_annotation_path = os.path.join(dst_annotation_dir, name + ".xml") 87 | dst_image_path = os.path.join(dst_image_dir, name + ".jpg") 88 | 89 | shutil.copyfile(src_annotation_path, dst_annotation_path) 90 | shutil.copyfile(src_image_path, dst_image_path) 91 | 92 | print('train num: {}, test num: {}'.format(len(total_train_list), len(total_test_list))) 93 | 94 | # 保存文件名 95 | train_dir = os.path.join(data_dir, 'train', 'name.csv') 96 | np.savetxt(train_dir, total_train_list, fmt='%s', delimiter=' ') 97 | test_dir = os.path.join(data_dir, 'test', 'name.csv') 98 | np.savetxt(test_dir, total_test_list, fmt='%s', delimiter=' ') 99 | 100 | print('done') 101 | -------------------------------------------------------------------------------- /py/lib/models/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午3:38 5 | @file: __init__.py.py 6 | @author: zj 7 | @description: 8 | """ -------------------------------------------------------------------------------- /py/lib/models/mobilenet/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/5 上午6:18 5 | @file: __init__.py.py 6 | @author: zj 7 | @description: 8 | """ -------------------------------------------------------------------------------- /py/lib/models/mobilenet/conv_bn_relu.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/7 上午9:07 5 | @file: conv_bn_relu.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch.nn as nn 11 | 12 | 13 | class ConvBNReLU(nn.Sequential): 14 | 15 | def __init__(self, in_planes, out_planes, kernel_size=3, stride=1, padding=0, groups=1): 16 | super(ConvBNReLU, self).__init__( 17 | nn.Conv2d(in_planes, out_planes, kernel_size, stride=stride, padding=padding, groups=groups, bias=False), 18 | nn.BatchNorm2d(out_planes), 19 | nn.ReLU6(inplace=True) 20 | ) 21 | -------------------------------------------------------------------------------- /py/lib/models/mobilenet/depthwise_separable_conv.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/6 下午2:49 5 | @file: depthwise_separable_conv.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | import torch.nn as nn 12 | 13 | from .conv_bn_relu import ConvBNReLU 14 | 15 | 16 | class DepthwiseSeparableConv(nn.Sequential): 17 | 18 | def __init__(self, inp, oup, stride): 19 | super(DepthwiseSeparableConv, self).__init__() 20 | self.stride = stride 21 | assert stride in [1, 2] 22 | 23 | padding = 1 if stride == 2 else 0 24 | 25 | layers = [] 26 | layers.extend([ 27 | # depthwise 28 | ConvBNReLU(inp, oup, kernel_size=3, stride=stride, padding=padding, groups=inp), 29 | # pointwise 30 | ConvBNReLU(oup, oup, kernel_size=1, stride=1) 31 | ]) 32 | self.conv = nn.Sequential(*layers) 33 | 34 | def forward(self, x): 35 | return self.conv(x) 36 | -------------------------------------------------------------------------------- /py/lib/models/mobilenet/mobilenet.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/7 上午9:15 5 | @file: mobilenet.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch.nn as nn 11 | 12 | from .conv_bn_relu import ConvBNReLU 13 | from .depthwise_separable_conv import DepthwiseSeparableConv 14 | 15 | 16 | class MobileNet(nn.Module): 17 | 18 | def __init__(self, num_classes=1000): 19 | super(MobileNet, self).__init__() 20 | depth_sep_conv_setting = [ 21 | # inp, oup, stride 22 | [32, 64, 1], 23 | [64, 128, 2], 24 | [128, 128, 1], 25 | [128, 256, 2], 26 | [256, 256, 1], 27 | [256, 512, 2], 28 | 29 | # repeat 5 times 30 | [512, 512, 1], 31 | [512, 512, 1], 32 | [512, 512, 1], 33 | [512, 512, 1], 34 | [512, 512, 1], 35 | 36 | [512, 1024, 2], 37 | [1024, 1024, 2] 38 | ] 39 | 40 | features = [ConvBNReLU(3, 32, kernel_size=3, stride=2)] 41 | for inp, oup, stride in depth_sep_conv_setting: 42 | features.append(DepthwiseSeparableConv(inp, oup, stride)) 43 | self.features = nn.Sequential(*features) 44 | 45 | # 分类器 46 | self.classifier = nn.Sequential( 47 | nn.Dropout(0.2), 48 | nn.Linear(1024, num_classes) 49 | ) 50 | 51 | self.init_param() 52 | 53 | def init_param(self): 54 | # weight initialization 55 | for m in self.modules(): 56 | if isinstance(m, nn.Conv2d): 57 | nn.init.kaiming_normal_(m.weight, mode='fan_out') 58 | if m.bias is not None: 59 | nn.init.zeros_(m.bias) 60 | elif isinstance(m, nn.BatchNorm2d): 61 | nn.init.ones_(m.weight) 62 | nn.init.zeros_(m.bias) 63 | elif isinstance(m, nn.Linear): 64 | nn.init.normal_(m.weight, 0, 0.01) 65 | nn.init.zeros_(m.bias) 66 | 67 | def _forward_impl(self, x): 68 | # This exists since TorchScript doesn't support inheritance, so the superclass method 69 | # (this one) needs to have a name other than `forward` that can be accessed in a subclass 70 | x = self.features(x) 71 | # Cannot use "squeeze" as batch-size can be 1 => must use reshape with x.shape[0] 72 | x = nn.functional.adaptive_avg_pool2d(x, 1).reshape(x.shape[0], -1) 73 | x = self.classifier(x) 74 | return x 75 | 76 | def forward(self, x): 77 | return self._forward_impl(x) 78 | 79 | 80 | if __name__ == '__main__': 81 | import torch 82 | 83 | data = torch.randn(1, 3, 224, 224) 84 | model = MobileNet() 85 | outputs = model(data) 86 | 87 | print(outputs.shape) 88 | -------------------------------------------------------------------------------- /py/lib/models/mobilenet_v2/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/8 上午9:36 5 | @file: __init__.py.py 6 | @author: zj 7 | @description: 8 | """ -------------------------------------------------------------------------------- /py/lib/models/mobilenet_v2/conv_bn_relu.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/8 下午4:17 5 | @file: conv_bn_relu.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch.nn as nn 11 | 12 | 13 | class ConvBNReLU(nn.Sequential): 14 | 15 | def __init__(self, in_planes, out_planes, kernel_size=3, stride=1, groups=1): 16 | padding = (kernel_size - 1) // 2 17 | super(ConvBNReLU, self).__init__( 18 | nn.Conv2d(in_planes, out_planes, kernel_size, stride, padding, groups=groups, bias=False), 19 | nn.BatchNorm2d(out_planes), 20 | nn.ReLU6(inplace=True) 21 | ) 22 | -------------------------------------------------------------------------------- /py/lib/models/mobilenet_v2/inverted_residual.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/8 下午4:18 5 | @file: inverted_residual.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch.nn as nn 11 | 12 | from .conv_bn_relu import ConvBNReLU 13 | 14 | 15 | class InvertedResidual(nn.Module): 16 | def __init__(self, inp, oup, stride, expand_ratio): 17 | super(InvertedResidual, self).__init__() 18 | self.stride = stride 19 | assert stride in [1, 2] 20 | 21 | hidden_dim = int(round(inp * expand_ratio)) 22 | self.use_res_connect = self.stride == 1 and inp == oup 23 | 24 | layers = [] 25 | if expand_ratio != 1: 26 | # pw 27 | layers.append(ConvBNReLU(inp, hidden_dim, kernel_size=1)) 28 | layers.extend([ 29 | # dw 30 | ConvBNReLU(hidden_dim, hidden_dim, stride=stride, groups=hidden_dim), 31 | # pw-linear 32 | nn.Conv2d(hidden_dim, oup, 1, 1, 0, bias=False), 33 | nn.BatchNorm2d(oup), 34 | ]) 35 | self.conv = nn.Sequential(*layers) 36 | 37 | def forward(self, x): 38 | if self.use_res_connect: 39 | return x + self.conv(x) 40 | else: 41 | return self.conv(x) 42 | -------------------------------------------------------------------------------- /py/lib/models/mobilenet_v2/mobilenet_v2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/8 上午9:36 5 | @file: mobilenet_v2.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch.nn as nn 11 | 12 | from .conv_bn_relu import ConvBNReLU 13 | from .inverted_residual import InvertedResidual 14 | 15 | 16 | def _make_divisible(v, divisor, min_value=None): 17 | """ 18 | This function is taken from the original tf repo. 19 | It ensures that all layers have a channel number that is divisible by 8 20 | It can be seen here: 21 | https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py 22 | :param v: 23 | :param divisor: 24 | :param min_value: 25 | :return: 26 | """ 27 | if min_value is None: 28 | min_value = divisor 29 | new_v = max(min_value, int(v + divisor / 2) // divisor * divisor) 30 | # Make sure that round down does not go down by more than 10%. 31 | if new_v < 0.9 * v: 32 | new_v += divisor 33 | return new_v 34 | 35 | 36 | class MobileNetV2(nn.Module): 37 | def __init__(self, 38 | num_classes=1000, 39 | width_mult=1.0, 40 | inverted_residual_setting=None, 41 | round_nearest=8, 42 | block=None): 43 | """ 44 | MobileNet V2 main class 45 | 46 | Args: 47 | num_classes (int): Number of classes 48 | width_mult (float): Width multiplier - adjusts number of channels in each layer by this amount 49 | inverted_residual_setting: Network structure 50 | round_nearest (int): Round the number of channels in each layer to be a multiple of this number 51 | Set to 1 to turn off rounding 52 | block: Module specifying inverted residual building block for mobilenet 53 | 54 | """ 55 | super(MobileNetV2, self).__init__() 56 | 57 | if block is None: 58 | block = InvertedResidual 59 | input_channel = 32 60 | last_channel = 1280 61 | 62 | if inverted_residual_setting is None: 63 | inverted_residual_setting = [ 64 | # t, c, n, s 65 | [1, 16, 1, 1], 66 | [6, 24, 2, 2], 67 | [6, 32, 3, 2], 68 | [6, 64, 4, 2], 69 | [6, 96, 3, 1], 70 | [6, 160, 3, 2], 71 | [6, 320, 1, 1], 72 | ] 73 | 74 | # only check the first element, assuming user knows t,c,n,s are required 75 | if len(inverted_residual_setting) == 0 or len(inverted_residual_setting[0]) != 4: 76 | raise ValueError("inverted_residual_setting should be non-empty " 77 | "or a 4-element list, got {}".format(inverted_residual_setting)) 78 | 79 | # building first layer 80 | input_channel = _make_divisible(input_channel * width_mult, round_nearest) 81 | self.last_channel = _make_divisible(last_channel * max(1.0, width_mult), round_nearest) 82 | features = [ConvBNReLU(3, input_channel, stride=2)] 83 | # building inverted residual blocks 84 | for t, c, n, s in inverted_residual_setting: 85 | output_channel = _make_divisible(c * width_mult, round_nearest) 86 | for i in range(n): 87 | stride = s if i == 0 else 1 88 | features.append(block(input_channel, output_channel, stride, expand_ratio=t)) 89 | input_channel = output_channel 90 | # building last several layers 91 | features.append(ConvBNReLU(input_channel, self.last_channel, kernel_size=1)) 92 | # make it nn.Sequential 93 | self.features = nn.Sequential(*features) 94 | 95 | # building classifier 96 | self.classifier = nn.Sequential( 97 | nn.Dropout(0.2), 98 | nn.Linear(self.last_channel, num_classes), 99 | ) 100 | 101 | # weight initialization 102 | for m in self.modules(): 103 | if isinstance(m, nn.Conv2d): 104 | nn.init.kaiming_normal_(m.weight, mode='fan_out') 105 | if m.bias is not None: 106 | nn.init.zeros_(m.bias) 107 | elif isinstance(m, nn.BatchNorm2d): 108 | nn.init.ones_(m.weight) 109 | nn.init.zeros_(m.bias) 110 | elif isinstance(m, nn.Linear): 111 | nn.init.normal_(m.weight, 0, 0.01) 112 | nn.init.zeros_(m.bias) 113 | 114 | def _forward_impl(self, x): 115 | # This exists since TorchScript doesn't support inheritance, so the superclass method 116 | # (this one) needs to have a name other than `forward` that can be accessed in a subclass 117 | x = self.features(x) 118 | # Cannot use "squeeze" as batch-size can be 1 => must use reshape with x.shape[0] 119 | x = nn.functional.adaptive_avg_pool2d(x, 1).reshape(x.shape[0], -1) 120 | x = self.classifier(x) 121 | return x 122 | 123 | def forward(self, x): 124 | return self._forward_impl(x) 125 | -------------------------------------------------------------------------------- /py/lib/models/shufflenet/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/7 上午9:42 5 | @file: __init__.py.py 6 | @author: zj 7 | @description: 8 | """ -------------------------------------------------------------------------------- /py/lib/models/shufflenet/channel_shuffle.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/7 下午2:21 5 | @file: channel_shuffle.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | import torch.nn as nn 12 | 13 | 14 | class ChannelShuffle(nn.Module): 15 | 16 | def __init__(self, groups): 17 | super(ChannelShuffle, self).__init__() 18 | 19 | self.groups = groups 20 | 21 | def forward(self, x): 22 | batchsize, num_channels, height, width = x.data.size() 23 | channels_per_group = num_channels // self.groups 24 | 25 | # reshape 26 | x = x.view(batchsize, self.groups, channels_per_group, height, width) 27 | 28 | x = torch.transpose(x, 1, 2).contiguous() 29 | 30 | # flatten 31 | x = x.view(batchsize, -1, height, width) 32 | 33 | return x 34 | -------------------------------------------------------------------------------- /py/lib/models/shufflenet/shufflenet.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/7 上午9:54 5 | @file: shufflenet.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch.nn as nn 11 | from torchvision.models import shufflenetv2 12 | from .shufflenet_unit import ShuffleNetUnit 13 | 14 | 15 | class ShuffleNet(nn.Module): 16 | 17 | def __init__(self, stages_repeats, stages_out_channels, groups=1, num_classes=1000): 18 | super(ShuffleNet, self).__init__() 19 | 20 | if len(stages_repeats) != 3: 21 | raise ValueError('expected stages_repeats as list of 3 positive ints') 22 | if len(stages_out_channels) != 4: 23 | raise ValueError('expected stages_out_channels as list of 4 positive ints') 24 | self._stage_out_channels = stages_out_channels 25 | 26 | input_channels = 3 27 | output_channels = self._stage_out_channels[0] 28 | self.conv1 = nn.Sequential( 29 | nn.Conv2d(input_channels, output_channels, 3, 2, 1, bias=False), 30 | nn.BatchNorm2d(output_channels), 31 | nn.ReLU(inplace=True), 32 | ) 33 | input_channels = output_channels 34 | 35 | self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) 36 | 37 | stage_names = ['stage{}'.format(i) for i in [2, 3, 4]] 38 | for name, repeats, output_channels in zip(stage_names, stages_repeats, self._stage_out_channels[1:]): 39 | seq = [ShuffleNetUnit(input_channels, output_channels, 2, groups=groups)] 40 | for i in range(repeats - 1): 41 | seq.append(ShuffleNetUnit(output_channels, output_channels, 1, groups=groups)) 42 | setattr(self, name, nn.Sequential(*seq)) 43 | input_channels = output_channels 44 | 45 | output_channels = self._stage_out_channels[-1] 46 | self.fc = nn.Linear(output_channels, num_classes) 47 | 48 | def _forward_impl(self, x): 49 | # See note [TorchScript super()] 50 | x = self.conv1(x) 51 | x = self.maxpool(x) 52 | x = self.stage2(x) 53 | x = self.stage3(x) 54 | x = self.stage4(x) 55 | x = x.mean([2, 3]) # globalpool 56 | x = self.fc(x) 57 | return x 58 | 59 | def forward(self, x): 60 | return self._forward_impl(x) 61 | 62 | 63 | def shufflenet_g_1(num_classes=1000): 64 | return ShuffleNet([4, 8, 4], [24, 144, 288, 576], num_classes=num_classes) 65 | 66 | 67 | def shufflenet_g_2(num_classes=1000): 68 | return ShuffleNet([4, 8, 4], [24, 200, 400, 800], num_classes=num_classes) 69 | 70 | 71 | def shufflenet_g_3(num_classes=1000): 72 | return ShuffleNet([4, 8, 4], [24, 240, 480, 960], num_classes=num_classes) 73 | 74 | 75 | def shufflenet_g_4(num_classes=1000): 76 | return ShuffleNet([4, 8, 4], [24, 272, 544, 1088], num_classes=num_classes) 77 | 78 | 79 | def shufflenet_g_8(num_classes=1000): 80 | return ShuffleNet([4, 8, 4], [24, 384, 768, 1536], num_classes=num_classes) 81 | -------------------------------------------------------------------------------- /py/lib/models/shufflenet/shufflenet_unit.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/7 下午2:06 5 | @file: shufflenet_unit.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | import torch.nn as nn 12 | import torch.nn.functional as F 13 | 14 | from .channel_shuffle import ChannelShuffle 15 | 16 | 17 | class ShuffleNetUnit(nn.Module): 18 | 19 | def __init__(self, inp, oup, stride, groups=1): 20 | super(ShuffleNetUnit, self).__init__() 21 | assert stride in [1, 2] 22 | 23 | self.stride = stride 24 | 25 | if self.stride == 2: 26 | self.branch1 = nn.Sequential( 27 | nn.AvgPool2d(kernel_size=3, stride=2, padding=1) 28 | ) 29 | dw_out_channels = inp * (oup // inp) 30 | gconv_oup = oup - inp 31 | else: 32 | self.branch1 = nn.Sequential() 33 | dw_out_channels = oup 34 | gconv_oup = oup 35 | 36 | self.branch2 = nn.Sequential( 37 | # 分组卷积 38 | nn.Conv2d(inp, inp, kernel_size=1, stride=1, padding=0, bias=False, groups=groups), 39 | nn.BatchNorm2d(inp), 40 | nn.ReLU(inplace=True), 41 | ChannelShuffle(groups), 42 | # 深度卷积 43 | nn.Conv2d(inp, dw_out_channels, kernel_size=3, stride=self.stride, padding=1, bias=False, groups=inp), 44 | nn.BatchNorm2d(dw_out_channels), 45 | # 分组卷积 46 | nn.Conv2d(dw_out_channels, gconv_oup, kernel_size=1, stride=1, padding=0, bias=False, groups=groups), 47 | nn.BatchNorm2d(gconv_oup), 48 | nn.ReLU(inplace=True), 49 | ) 50 | 51 | def _forward_impl(self, x): 52 | if self.stride == 1: 53 | out = x + self.branch2(x) 54 | else: 55 | out = torch.cat((self.branch1(x), self.branch2(x)), dim=1) 56 | 57 | out = F.relu(out) 58 | 59 | return out 60 | 61 | def forward(self, x): 62 | return self._forward_impl(x) 63 | -------------------------------------------------------------------------------- /py/lib/models/shufflenet_v2/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/8 下午4:21 5 | @file: __init__.py.py 6 | @author: zj 7 | @description: 8 | """ -------------------------------------------------------------------------------- /py/lib/models/shufflenet_v2/inverted_residual.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/8 下午4:22 5 | @file: inverted_residual.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | import torch.nn as nn 12 | 13 | 14 | def channel_shuffle(x, groups): 15 | # type: (torch.Tensor, int) -> torch.Tensor 16 | batchsize, num_channels, height, width = x.data.size() 17 | channels_per_group = num_channels // groups 18 | 19 | # reshape 20 | x = x.view(batchsize, groups, channels_per_group, height, width) 21 | 22 | x = torch.transpose(x, 1, 2).contiguous() 23 | 24 | # flatten 25 | x = x.view(batchsize, -1, height, width) 26 | 27 | return x 28 | 29 | 30 | class InvertedResidual(nn.Module): 31 | def __init__(self, inp, oup, stride): 32 | super(InvertedResidual, self).__init__() 33 | 34 | if not (1 <= stride <= 3): 35 | raise ValueError('illegal stride value') 36 | self.stride = stride 37 | 38 | branch_features = oup // 2 39 | assert (self.stride != 1) or (inp == branch_features << 1) 40 | 41 | if self.stride > 1: 42 | self.branch1 = nn.Sequential( 43 | self.depthwise_conv(inp, inp, kernel_size=3, stride=self.stride, padding=1), 44 | nn.BatchNorm2d(inp), 45 | nn.Conv2d(inp, branch_features, kernel_size=1, stride=1, padding=0, bias=False), 46 | nn.BatchNorm2d(branch_features), 47 | nn.ReLU(inplace=True), 48 | ) 49 | else: 50 | self.branch1 = nn.Sequential() 51 | 52 | self.branch2 = nn.Sequential( 53 | nn.Conv2d(inp if (self.stride > 1) else branch_features, 54 | branch_features, kernel_size=1, stride=1, padding=0, bias=False), 55 | nn.BatchNorm2d(branch_features), 56 | nn.ReLU(inplace=True), 57 | self.depthwise_conv(branch_features, branch_features, kernel_size=3, stride=self.stride, padding=1), 58 | nn.BatchNorm2d(branch_features), 59 | nn.Conv2d(branch_features, branch_features, kernel_size=1, stride=1, padding=0, bias=False), 60 | nn.BatchNorm2d(branch_features), 61 | nn.ReLU(inplace=True), 62 | ) 63 | 64 | @staticmethod 65 | def depthwise_conv(i, o, kernel_size, stride=1, padding=0, bias=False): 66 | return nn.Conv2d(i, o, kernel_size, stride, padding, bias=bias, groups=i) 67 | 68 | def forward(self, x): 69 | if self.stride == 1: 70 | x1, x2 = x.chunk(2, dim=1) 71 | out = torch.cat((x1, self.branch2(x2)), dim=1) 72 | else: 73 | out = torch.cat((self.branch1(x), self.branch2(x)), dim=1) 74 | 75 | out = channel_shuffle(out, 2) 76 | 77 | return out 78 | -------------------------------------------------------------------------------- /py/lib/models/shufflenet_v2/shufflenet_v2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/8 下午4:21 5 | @file: shufflenet_v2.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch.nn as nn 11 | 12 | from .inverted_residual import InvertedResidual 13 | 14 | 15 | class ShuffleNetV2(nn.Module): 16 | def __init__(self, stages_repeats, stages_out_channels, num_classes=1000, inverted_residual=InvertedResidual): 17 | super(ShuffleNetV2, self).__init__() 18 | 19 | if len(stages_repeats) != 3: 20 | raise ValueError('expected stages_repeats as list of 3 positive ints') 21 | if len(stages_out_channels) != 5: 22 | raise ValueError('expected stages_out_channels as list of 5 positive ints') 23 | self._stage_out_channels = stages_out_channels 24 | 25 | input_channels = 3 26 | output_channels = self._stage_out_channels[0] 27 | self.conv1 = nn.Sequential( 28 | nn.Conv2d(input_channels, output_channels, 3, 2, 1, bias=False), 29 | nn.BatchNorm2d(output_channels), 30 | nn.ReLU(inplace=True), 31 | ) 32 | input_channels = output_channels 33 | 34 | self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) 35 | 36 | stage_names = ['stage{}'.format(i) for i in [2, 3, 4]] 37 | for name, repeats, output_channels in zip( 38 | stage_names, stages_repeats, self._stage_out_channels[1:]): 39 | seq = [inverted_residual(input_channels, output_channels, 2)] 40 | for i in range(repeats - 1): 41 | seq.append(inverted_residual(output_channels, output_channels, 1)) 42 | setattr(self, name, nn.Sequential(*seq)) 43 | input_channels = output_channels 44 | 45 | output_channels = self._stage_out_channels[-1] 46 | self.conv5 = nn.Sequential( 47 | nn.Conv2d(input_channels, output_channels, 1, 1, 0, bias=False), 48 | nn.BatchNorm2d(output_channels), 49 | nn.ReLU(inplace=True), 50 | ) 51 | 52 | self.fc = nn.Linear(output_channels, num_classes) 53 | 54 | def _forward_impl(self, x): 55 | # See note [TorchScript super()] 56 | x = self.conv1(x) 57 | x = self.maxpool(x) 58 | x = self.stage2(x) 59 | x = self.stage3(x) 60 | x = self.stage4(x) 61 | x = self.conv5(x) 62 | x = x.mean([2, 3]) # globalpool 63 | x = self.fc(x) 64 | return x 65 | 66 | def forward(self, x): 67 | return self._forward_impl(x) 68 | 69 | 70 | def shufflenet_v2_x0_5(num_classes=1000): 71 | return ShuffleNetV2([4, 8, 4], [24, 48, 96, 192, 1024], num_classes=num_classes) 72 | 73 | 74 | def shufflenet_v2_x1_0(num_classes=1000): 75 | return ShuffleNetV2([4, 8, 4], [24, 116, 232, 464, 1024], num_classes=num_classes) 76 | 77 | 78 | def shufflenet_v2_x1_5(num_classes=1000): 79 | return ShuffleNetV2([4, 8, 4], [24, 176, 352, 704, 1024], num_classes=num_classes) 80 | 81 | 82 | def shufflenet_v2_x2_0(num_classes=1000): 83 | return ShuffleNetV2([4, 8, 4], [24, 244, 488, 976, 2048], num_classes=num_classes) 84 | -------------------------------------------------------------------------------- /py/lib/models/squeezenet/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/5 上午6:18 5 | @file: __init__.py.py 6 | @author: zj 7 | @description: 8 | """ -------------------------------------------------------------------------------- /py/lib/models/squeezenet/basic_conv2d.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/16 下午1:10 5 | @file: basic_conv2d.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch.nn as nn 11 | 12 | 13 | class BasicConv2d(nn.Module): 14 | """ 15 | 结合BN的卷积操作 16 | """ 17 | 18 | def __init__(self, in_channels, out_channels, kernel_size=1, stride=1, padding=0, 19 | norm_layer=None, relu_layer=None): 20 | super(BasicConv2d, self).__init__() 21 | if norm_layer is None: 22 | norm_layer = nn.BatchNorm2d 23 | if relu_layer is None: 24 | relu_layer = nn.RReLU 25 | 26 | self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, stride=stride, padding=padding) 27 | self.bn = norm_layer(out_channels, eps=0.001) 28 | self.relu = relu_layer(lower=0.1, upper=0.1, inplace=True) 29 | 30 | def forward(self, x): 31 | assert len(x.shape) == 4 32 | x = self.conv(x) 33 | x = self.bn(x) 34 | return self.relu(x) 35 | -------------------------------------------------------------------------------- /py/lib/models/squeezenet/fire.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午3:39 5 | @file: fire.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | import torch.nn as nn 12 | 13 | from models.squeezenet.basic_conv2d import BasicConv2d 14 | 15 | 16 | class Fire(nn.Module): 17 | 18 | def __init__(self, inplanes, squeeze_planes, expand1x1_planes, expand3x3_planes): 19 | super(Fire, self).__init__() 20 | conv_block = BasicConv2d 21 | 22 | self.inplanes = inplanes 23 | self.squeeze = conv_block(inplanes, squeeze_planes, kernel_size=1) 24 | self.expand1x1 = conv_block(squeeze_planes, expand1x1_planes, kernel_size=1) 25 | self.expand3x3 = conv_block(squeeze_planes, expand3x3_planes, kernel_size=3, padding=1) 26 | 27 | def forward(self, x): 28 | assert len(x.shape) == 4 29 | x = self.squeeze(x) 30 | return torch.cat([ 31 | self.expand1x1(x), 32 | self.expand3x3(x) 33 | ], 1) 34 | -------------------------------------------------------------------------------- /py/lib/models/squeezenet/fire_bypass.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午4:40 5 | @file: fire_bypass.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | import torch.nn as nn 12 | from models.squeezenet.basic_conv2d import BasicConv2d 13 | 14 | 15 | class FireBypass(nn.Module): 16 | """ 17 | 两层网络,卷积核大小固定为3x3,每一层的滤波器个数相同 18 | """ 19 | 20 | def __init__(self, inplanes, squeeze_planes, expand1x1_planes, expand3x3_planes, norm_layer=None): 21 | super(FireBypass, self).__init__() 22 | conv_block = BasicConv2d 23 | if norm_layer is None: 24 | norm_layer = nn.BatchNorm2d 25 | 26 | self.inplanes = inplanes 27 | self.squeeze = conv_block(inplanes, squeeze_planes) 28 | self.expand1x1 = self.conv1x1(squeeze_planes, expand1x1_planes) 29 | self.bn1 = norm_layer(expand1x1_planes) 30 | self.expand3x3 = self.conv3x3(squeeze_planes, expand3x3_planes) 31 | self.bn2 = norm_layer(expand3x3_planes) 32 | 33 | self.relu = nn.ReLU(inplace=True) 34 | 35 | def forward(self, x): 36 | identity = x 37 | 38 | out = self.squeeze(x) 39 | out_1 = self.expand1x1(out) 40 | out_1 = self.bn1(out_1) 41 | out_2 = self.expand3x3(out) 42 | out_2 = self.bn2(out_2) 43 | out = torch.cat([out_1, out_2], 1) 44 | 45 | out += identity 46 | out = self.relu(out) 47 | 48 | return out 49 | 50 | def conv3x3(self, in_planes, out_planes, stride=1): 51 | """3x3 convolution with padding""" 52 | return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1) 53 | 54 | def conv1x1(self, in_planes, out_planes, stride=1): 55 | """1x1 convolution""" 56 | return nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride) 57 | -------------------------------------------------------------------------------- /py/lib/models/squeezenet/squeeze_net.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午3:38 5 | @file: squeeze_net.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch.nn as nn 11 | 12 | from models.squeezenet.basic_conv2d import BasicConv2d 13 | from models.squeezenet.fire import Fire 14 | 15 | 16 | class SqueezeNet(nn.Module): 17 | 18 | def __init__(self, num_classes=1000): 19 | super(SqueezeNet, self).__init__() 20 | conv_block = BasicConv2d 21 | fire_block = Fire 22 | 23 | self.conv1 = conv_block(3, 96, kernel_size=7, stride=2, padding=2) 24 | self.max_pool = nn.MaxPool2d(3, stride=2) 25 | 26 | self.fire2 = fire_block(96, 16, 64, 64) 27 | self.fire3 = fire_block(128, 16, 64, 64) 28 | self.fire4 = fire_block(128, 32, 128, 128) 29 | self.fire5 = fire_block(256, 32, 128, 128) 30 | self.fire6 = fire_block(256, 48, 192, 192) 31 | self.fire7 = fire_block(384, 48, 192, 192) 32 | self.fire8 = fire_block(384, 64, 256, 256) 33 | self.fire9 = fire_block(512, 64, 256, 256) 34 | self.conv10 = conv_block(512, num_classes, kernel_size=1) 35 | 36 | self.avg_pool = nn.AvgPool2d(13, stride=1) 37 | 38 | def forward(self, x): 39 | assert len(x.shape) == 4 40 | # N x 3 x 224 x 224 41 | x = self.conv1(x) 42 | # N x 96 x 111 x 111 43 | x = self.max_pool(x) 44 | # N x 96 x 55 x 55 45 | x = self.fire2(x) 46 | # N x 128 x 55 x 55 47 | x = self.fire3(x) 48 | # N x 128 x 55 x 55 49 | x = self.fire4(x) 50 | # N x 256 x 55 x 55 51 | x = self.max_pool(x) 52 | # N x 256 x 27 x 27 53 | x = self.fire5(x) 54 | # N x 256 x 27 x 27 55 | x = self.fire6(x) 56 | # N x 384 x 27 x 27 57 | x = self.fire7(x) 58 | # N x 384 x 27 x 27 59 | x = self.fire8(x) 60 | # N x 512 x 27 x 27 61 | x = self.max_pool(x) 62 | # N x 512 x 13 x 13 63 | x = self.fire9(x) 64 | # N x 512 x 13 x 13 65 | x = self.conv10(x) 66 | # N x C x 13 x 13 67 | x = self.avg_pool(x) 68 | # N x C x 1 x 1 69 | return x.squeeze() -------------------------------------------------------------------------------- /py/lib/models/squeezenet/squeeze_net_bypass.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午4:55 5 | @file: squeeze_net_bypass.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch.nn as nn 11 | 12 | from models.squeezenet.basic_conv2d import BasicConv2d 13 | from models.squeezenet.fire import Fire 14 | from models.squeezenet.fire_bypass import FireBypass 15 | 16 | 17 | class SqueezeNetBypass(nn.Module): 18 | 19 | def __init__(self, num_classes=1000): 20 | super(SqueezeNetBypass, self).__init__() 21 | conv_block = BasicConv2d 22 | fire_block = Fire 23 | fire_bypass_block = FireBypass 24 | 25 | self.conv1 = conv_block(3, 96, kernel_size=7, stride=2, padding=2) 26 | self.max_pool = nn.MaxPool2d(3, stride=2) 27 | 28 | self.fire2 = fire_block(96, 16, 64, 64) 29 | self.fire_bypass3 = fire_bypass_block(128, 16, 64, 64) 30 | self.fire4 = fire_block(128, 32, 128, 128) 31 | self.fire_bypass5 = fire_bypass_block(256, 32, 128, 128) 32 | self.fire6 = fire_block(256, 48, 192, 192) 33 | self.fire_bypass7 = fire_bypass_block(384, 48, 192, 192) 34 | self.fire8 = fire_block(384, 64, 256, 256) 35 | self.fire_bypass9 = fire_bypass_block(512, 64, 256, 256) 36 | self.conv10 = conv_block(512, num_classes, kernel_size=1) 37 | 38 | self.avg_pool = nn.AvgPool2d(13, stride=1) 39 | 40 | def forward(self, x): 41 | assert len(x.shape) == 4 42 | # N x 3 x 224 x 224 43 | x = self.conv1(x) 44 | # N x 96 x 111 x 111 45 | x = self.max_pool(x) 46 | # N x 96 x 55 x 55 47 | x = self.fire2(x) 48 | # N x 128 x 55 x 55 49 | x = self.fire_bypass3(x) 50 | # N x 128 x 55 x 55 51 | x = self.fire4(x) 52 | # N x 256 x 55 x 55 53 | x = self.max_pool(x) 54 | # N x 256 x 27 x 27 55 | x = self.fire_bypass5(x) 56 | # N x 256 x 27 x 27 57 | x = self.fire6(x) 58 | # N x 384 x 27 x 27 59 | x = self.fire_bypass7(x) 60 | # N x 384 x 27 x 27 61 | x = self.fire8(x) 62 | # N x 512 x 27 x 27 63 | x = self.max_pool(x) 64 | # N x 512 x 13 x 13 65 | x = self.fire_bypass9(x) 66 | # N x 512 x 13 x 13 67 | x = self.conv10(x) 68 | # N x C x 13 x 13 69 | x = self.avg_pool(x) 70 | # N x C x 1 x 1 71 | return x.squeeze() -------------------------------------------------------------------------------- /py/lib/test/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午3:43 5 | @file: __init__.py.py 6 | @author: zj 7 | @description: 8 | """ -------------------------------------------------------------------------------- /py/lib/test/test_basic_conv2d.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午3:43 5 | @file: test_basic_conv2d.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | from models.squeezenet.basic_conv2d import BasicConv2d 12 | 13 | 14 | def test(): 15 | x = torch.randn((1, 3, 28, 28)) 16 | model = BasicConv2d(3, 10, kernel_size=3, padding=1) 17 | outputs = model(x) 18 | assert len(outputs.shape) == 4 19 | -------------------------------------------------------------------------------- /py/lib/test/test_fire.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午3:49 5 | @file: test_fire.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | from models.squeezenet.fire import Fire 12 | 13 | 14 | def test(): 15 | x = torch.randn((1, 3, 28, 28)) 16 | model = Fire(3, 10, 5, 5) 17 | outputs = model(x) 18 | assert len(outputs.shape) == 4 19 | -------------------------------------------------------------------------------- /py/lib/test/test_mobilenet.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/7 上午9:32 5 | @file: test_mobilenet.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | from models.mobilenet.mobilenet import MobileNet 12 | 13 | 14 | def test(): 15 | N = 8 16 | num_classes = 20 17 | 18 | x = torch.randn((N, 3, 224, 224)) 19 | model = MobileNet(num_classes=num_classes) 20 | outputs = model(x) 21 | assert outputs.shape == (N, num_classes) 22 | -------------------------------------------------------------------------------- /py/lib/test/test_mobilenet_v2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/8 下午4:19 5 | @file: test_mobilenet_v2.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | from models.mobilenet_v2.mobilenet_v2 import MobileNetV2 12 | 13 | 14 | def test(): 15 | N = 8 16 | num_classes = 20 17 | 18 | x = torch.randn((N, 3, 224, 224)) 19 | model = MobileNetV2(num_classes=num_classes) 20 | outputs = model(x) 21 | assert outputs.shape == (N, num_classes) 22 | -------------------------------------------------------------------------------- /py/lib/test/test_shufflenet.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/7 下午2:37 5 | @file: test_shufflenet.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | from models.shufflenet.shufflenet import shufflenet_g_1 12 | from models.shufflenet.shufflenet import shufflenet_g_2 13 | from models.shufflenet.shufflenet import shufflenet_g_3 14 | from models.shufflenet.shufflenet import shufflenet_g_4 15 | from models.shufflenet.shufflenet import shufflenet_g_8 16 | 17 | 18 | def test_g_1(): 19 | N = 8 20 | num_classes = 20 21 | 22 | x = torch.randn((N, 3, 224, 224)) 23 | model = shufflenet_g_1(num_classes=num_classes) 24 | outputs = model(x) 25 | assert outputs.shape == (N, num_classes) 26 | 27 | 28 | def test_g_2(): 29 | N = 8 30 | num_classes = 20 31 | 32 | x = torch.randn((N, 3, 224, 224)) 33 | model = shufflenet_g_2(num_classes=num_classes) 34 | outputs = model(x) 35 | assert outputs.shape == (N, num_classes) 36 | 37 | 38 | def test_g_3(): 39 | N = 8 40 | num_classes = 20 41 | 42 | x = torch.randn((N, 3, 224, 224)) 43 | model = shufflenet_g_3(num_classes=num_classes) 44 | outputs = model(x) 45 | assert outputs.shape == (N, num_classes) 46 | 47 | 48 | def test_g_4(): 49 | N = 8 50 | num_classes = 20 51 | 52 | x = torch.randn((N, 3, 224, 224)) 53 | model = shufflenet_g_4(num_classes=num_classes) 54 | outputs = model(x) 55 | assert outputs.shape == (N, num_classes) 56 | 57 | 58 | def test_g_8(): 59 | N = 8 60 | num_classes = 20 61 | 62 | x = torch.randn((N, 3, 224, 224)) 63 | model = shufflenet_g_8(num_classes=num_classes) 64 | outputs = model(x) 65 | assert outputs.shape == (N, num_classes) 66 | -------------------------------------------------------------------------------- /py/lib/test/test_shufflenet_v2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/6/8 下午4:25 5 | @file: test_shufflenet_v2.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | from models.shufflenet_v2.shufflenet_v2 import shufflenet_v2_x0_5 12 | from models.shufflenet_v2.shufflenet_v2 import shufflenet_v2_x1_0 13 | from models.shufflenet_v2.shufflenet_v2 import shufflenet_v2_x1_5 14 | from models.shufflenet_v2.shufflenet_v2 import shufflenet_v2_x2_0 15 | 16 | 17 | class TestShuffleNetV2(object): 18 | 19 | def test_shufflenet_v2_x0_5(self): 20 | N = 8 21 | num_classes = 20 22 | 23 | x = torch.randn((N, 3, 224, 224)) 24 | model = shufflenet_v2_x0_5(num_classes=num_classes) 25 | outputs = model(x) 26 | assert outputs.shape == (N, num_classes) 27 | 28 | def test_shufflenet_v2_x1_0(self): 29 | N = 8 30 | num_classes = 20 31 | 32 | x = torch.randn((N, 3, 224, 224)) 33 | model = shufflenet_v2_x1_0(num_classes=num_classes) 34 | outputs = model(x) 35 | assert outputs.shape == (N, num_classes) 36 | 37 | def test_shufflenet_v2_x1_5(self): 38 | N = 8 39 | num_classes = 20 40 | 41 | x = torch.randn((N, 3, 224, 224)) 42 | model = shufflenet_v2_x1_5(num_classes=num_classes) 43 | outputs = model(x) 44 | assert outputs.shape == (N, num_classes) 45 | 46 | def test_shufflenet_v2_x2_0(self): 47 | N = 8 48 | num_classes = 20 49 | 50 | x = torch.randn((N, 3, 224, 224)) 51 | model = shufflenet_v2_x2_0(num_classes=num_classes) 52 | outputs = model(x) 53 | assert outputs.shape == (N, num_classes) 54 | -------------------------------------------------------------------------------- /py/lib/test/test_squeeze_net.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午4:07 5 | @file: test_squeeze_net.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | from models.squeezenet.squeeze_net import SqueezeNet 12 | 13 | 14 | def test(): 15 | N = 8 16 | num_classes = 20 17 | 18 | x = torch.randn((N, 3, 224, 224)) 19 | model = SqueezeNet(num_classes=num_classes) 20 | outputs = model(x) 21 | assert outputs.shape == (N, num_classes) 22 | 23 | -------------------------------------------------------------------------------- /py/lib/test/test_squeezenet_bypass.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午7:53 5 | @file: test_squeezenet_bypass.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | from models.squeezenet.squeeze_net_bypass import SqueezeNetBypass 12 | 13 | 14 | def test(): 15 | N = 8 16 | num_classes = 20 17 | 18 | x = torch.randn((N, 3, 224, 224)) 19 | model = SqueezeNetBypass(num_classes=num_classes) 20 | outputs = model(x) 21 | 22 | assert outputs.shape == (N, num_classes) 23 | -------------------------------------------------------------------------------- /py/lib/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午3:35 5 | @file: __init__.py.py 6 | @author: zj 7 | @description: 8 | """ -------------------------------------------------------------------------------- /py/lib/utils/metrics.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/27 下午8:25 5 | @file: metrics.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | from thop import profile 12 | 13 | from torchvision.models import AlexNet 14 | from models.squeeze_net import SqueezeNet 15 | from models.squeeze_net_bypass import SqueezeNetBypass 16 | 17 | 18 | def compute_num_flops(model): 19 | input = torch.randn(1, 3, 224, 224) 20 | macs, params = profile(model, inputs=(input,), verbose=False) 21 | # print(macs, params) 22 | 23 | GFlops = macs * 2.0 / pow(10, 9) 24 | params_size = params * 4.0 / 1024 / 1024 25 | return GFlops, params_size 26 | 27 | 28 | def topk_accuracy(output, target, topk=(1,)): 29 | """ 30 | 计算前K个。N表示样本数,C表示类别数 31 | :param output: 大小为[N, C],每行表示该样本计算得到的C个类别概率 32 | :param target: 大小为[N],每行表示指定类别 33 | :param topk: tuple,计算前top-k的accuracy 34 | :return: list 35 | """ 36 | assert len(output.shape) == 2 and output.shape[0] == target.shape[0] 37 | maxk = max(topk) 38 | batch_size = target.size(0) 39 | 40 | _, pred = output.topk(maxk, 1, largest=True, sorted=True) 41 | pred = pred.t() 42 | correct = pred.eq(target.view(1, -1).expand_as(pred)) 43 | 44 | res = [] 45 | for k in topk: 46 | correct_k = correct[:k].view(-1).float().sum(0) 47 | res.append(correct_k.mul_(100.0 / batch_size)) 48 | return res 49 | 50 | 51 | if __name__ == '__main__': 52 | for name in ['alexnet', 'squeezenet', 'squeezenet-bypass']: 53 | if name == 'alexnet': 54 | model = AlexNet() 55 | elif name == 'squeezenet': 56 | model = SqueezeNet() 57 | else: 58 | model = SqueezeNetBypass() 59 | gflops, params_size = compute_num_flops(model) 60 | print('{}: {:.3f} GFlops - {:.3f} MB'.format(name, gflops, params_size)) 61 | -------------------------------------------------------------------------------- /py/lib/utils/util.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午3:35 5 | @file: util.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import torch 11 | import os 12 | import matplotlib.pyplot as plt 13 | 14 | 15 | def get_device(): 16 | return torch.device('cuda:0' if torch.cuda.is_available() else 'cpu') 17 | 18 | 19 | def check_dir(data_dir): 20 | if not os.path.exists(data_dir): 21 | os.mkdir(data_dir) 22 | 23 | 24 | def save_model(model, model_save_path): 25 | # 保存最好的模型参数 26 | check_dir('./models') 27 | torch.save(model.state_dict(), model_save_path) 28 | 29 | 30 | def save_png(title, res_dict): 31 | # x_major_locator = MultipleLocator(1) 32 | # ax = plt.gca() 33 | # ax.xaxis.set_major_locator(x_major_locator) 34 | fig = plt.figure() 35 | 36 | plt.title(title) 37 | for name, res in res_dict.items(): 38 | for k, v in res.items(): 39 | x = list(range(len(v))) 40 | plt.plot(v, label='%s-%s' % (name, k)) 41 | 42 | plt.legend() 43 | plt.savefig('%s.png' % title) 44 | -------------------------------------------------------------------------------- /py/squeezenet/train.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | @date: 2020/4/26 下午7:58 5 | @file: train.py 6 | @author: zj 7 | @description: 8 | """ 9 | 10 | import time 11 | import copy 12 | import os 13 | import torch 14 | import torch.nn as nn 15 | import torch.optim as optim 16 | from torchvision.models import alexnet 17 | from torch.utils.data import DataLoader 18 | import torchvision.transforms as transforms 19 | from torchvision.datasets import ImageFolder 20 | 21 | from utils import util 22 | from utils import metrics 23 | from models.squeeze_net import SqueezeNet 24 | from models.squeeze_net_bypass import SqueezeNetBypass 25 | 26 | 27 | def load_data(data_root_dir): 28 | transform = transforms.Compose([ 29 | # transforms.ToPILImage(), 30 | transforms.Resize(256), 31 | transforms.RandomCrop((224, 224)), 32 | transforms.RandomHorizontalFlip(), 33 | transforms.ToTensor(), 34 | transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) 35 | ]) 36 | 37 | data_loaders = {} 38 | data_sizes = {} 39 | for name in ['train', 'test']: 40 | data_dir = os.path.join(data_root_dir, name + '_imgs') 41 | # print(data_dir) 42 | 43 | data_set = ImageFolder(data_dir, transform=transform) 44 | data_loader = DataLoader(data_set, batch_size=128, shuffle=True, num_workers=8) 45 | data_loaders[name] = data_loader 46 | data_sizes[name] = len(data_set) 47 | return data_loaders, data_sizes 48 | 49 | 50 | def train_model(data_loaders, data_sizes, model_name, model, criterion, optimizer, lr_scheduler, 51 | num_epochs=25, device=None): 52 | since = time.time() 53 | 54 | best_model_weights = copy.deepcopy(model.state_dict()) 55 | best_top1_acc = 0.0 56 | best_top5_acc = 0.0 57 | 58 | loss_dict = {'train': [], 'test': []} 59 | top1_acc_dict = {'train': [], 'test': []} 60 | top5_acc_dict = {'train': [], 'test': []} 61 | for epoch in range(num_epochs): 62 | 63 | print('{} - Epoch {}/{}'.format(model_name, epoch, num_epochs - 1)) 64 | print('-' * 10) 65 | 66 | # Each epoch has a training and test phase 67 | for phase in ['train', 'test']: 68 | if phase == 'train': 69 | model.train() # Set model to training mode 70 | else: 71 | model.eval() # Set model to evaluate mode 72 | 73 | running_loss = 0.0 74 | # running_corrects = 0 75 | running_top1_acc = 0.0 76 | running_top5_acc = 0.0 77 | 78 | # Iterate over data. 79 | for inputs, labels in data_loaders[phase]: 80 | inputs = inputs.to(device) 81 | labels = labels.to(device) 82 | 83 | # zero the parameter gradients 84 | optimizer.zero_grad() 85 | 86 | # forward 87 | # track history if only in train 88 | with torch.set_grad_enabled(phase == 'train'): 89 | outputs = model(inputs) 90 | # print(outputs.shape) 91 | # _, preds = torch.max(outputs, 1) 92 | loss = criterion(outputs, labels) 93 | 94 | # compute top-k accuray 95 | topk_list = metrics.topk_accuracy(outputs, labels, topk=(1, 5)) 96 | running_top1_acc += topk_list[0] 97 | running_top5_acc += topk_list[1] 98 | 99 | # backward + optimize only if in training phase 100 | if phase == 'train': 101 | loss.backward() 102 | optimizer.step() 103 | 104 | # statistics 105 | running_loss += loss.item() * inputs.size(0) 106 | # running_corrects += torch.sum(preds == labels.data) 107 | if phase == 'train': 108 | lr_scheduler.step() 109 | 110 | epoch_loss = running_loss / data_sizes[phase] 111 | epoch_top1_acc = running_top1_acc / len(data_loaders[phase]) 112 | epoch_top5_acc = running_top5_acc / len(data_loaders[phase]) 113 | 114 | loss_dict[phase].append(epoch_loss) 115 | top1_acc_dict[phase].append(epoch_top1_acc) 116 | top5_acc_dict[phase].append(epoch_top5_acc) 117 | 118 | print('{} Loss: {:.4f} Top-1 Acc: {:.4f} Top-5 Acc: {:.4f}'.format( 119 | phase, epoch_loss, epoch_top1_acc, epoch_top5_acc)) 120 | 121 | # deep copy the model 122 | if phase == 'test' and epoch_top1_acc > best_top1_acc: 123 | best_top1_acc = epoch_top1_acc 124 | best_model_weights = copy.deepcopy(model.state_dict()) 125 | if phase == 'test' and epoch_top5_acc > best_top5_acc: 126 | best_top5_acc = epoch_top5_acc 127 | 128 | # 每训练一轮就保存 129 | # util.save_model(model.cpu(), '../data/models/%s_%d.pth' % (model_name, epoch)) 130 | # model = model.to(device) 131 | 132 | time_elapsed = time.time() - since 133 | print('Training {} complete in {:.0f}m {:.0f}s'.format(model_name, time_elapsed // 60, time_elapsed % 60)) 134 | print('Best test Top-1 Acc: {:4f}'.format(best_top1_acc)) 135 | print('Best test Top-5 Acc: {:4f}'.format(best_top5_acc)) 136 | 137 | # load best model weights 138 | model.load_state_dict(best_model_weights) 139 | return model, loss_dict, top1_acc_dict, top5_acc_dict 140 | 141 | 142 | if __name__ == '__main__': 143 | device = util.get_device() 144 | # device = 'cpu' 145 | 146 | data_loaders, data_sizes = load_data('../data/pascal-voc') 147 | print(data_loaders) 148 | print(data_sizes) 149 | 150 | res_loss = dict() 151 | res_top1_acc = dict() 152 | res_top5_acc = dict() 153 | num_classes = 20 154 | for name in ['SqueezeNetBypass', 'SqueezeNet', 'AlexNet']: 155 | if name == 'SqueezeNet': 156 | model = SqueezeNet(num_classes=num_classes) 157 | elif name == 'SqueezeNetBypass': 158 | model = SqueezeNetBypass(num_classes=num_classes) 159 | else: 160 | model = alexnet(num_classes=num_classes) 161 | model.eval() 162 | # print(model) 163 | model = model.to(device) 164 | 165 | criterion = nn.CrossEntropyLoss() 166 | optimizer = optim.Adam(model.parameters(), lr=1e-3, weight_decay=1e-4) 167 | lr_schduler = optim.lr_scheduler.StepLR(optimizer, step_size=7, gamma=0.96) 168 | 169 | util.check_dir('../data/models/') 170 | best_model, loss_dict, top1_acc_dict, top5_acc_dict = train_model( 171 | data_loaders, data_sizes, name, model, criterion, optimizer, lr_schduler, num_epochs=50, device=device) 172 | # 保存最好的模型参数 173 | # util.save_model(best_model.cpu(), '../data/models/best_%s.pth' % name) 174 | 175 | res_loss[name] = loss_dict 176 | res_top1_acc[name] = top1_acc_dict 177 | res_top5_acc[name] = top5_acc_dict 178 | 179 | print('train %s done' % name) 180 | print() 181 | 182 | util.save_png('loss', res_loss) 183 | util.save_png('top-1 acc', res_top1_acc) 184 | util.save_png('top-5 acc', res_top5_acc) 185 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | mkdocs==1.0.4 2 | mkdocs-material==4.6.0 3 | mkdocs-minify-plugin==0.2.1 4 | Markdown==3.1.1 5 | markdown-katex==201912.11b0 --------------------------------------------------------------------------------