You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

03-AlexNet.ipynb 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "# AlexNet\n",
  8. "\n",
  9. "\n",
  10. "第一个典型的卷积神经网络是 LeNet5 ,但是第一个开启深度学习的网络却是 AlexNet,这个网络在2012年的ImageNet竞赛中取得冠军。这网络提出了深度学习常用的技术:ReLU和Dropout。AlexNet网络结构在整体上类似于LeNet,都是先卷积然后在全连接,但在细节上有很大不同,AlexNet更为复杂,Alexnet模型由5个卷积层和3个池化Pooling层,其中还有3个全连接层构成,共有$6 \\times 10^7$个参数和65000个神经元,最终的输出层是1000通道的Softmax。AlexNet 跟 LeNet 结构类似,但使⽤了更多的卷积层和更⼤的参数空间来拟合⼤规模数据集 ImageNet,它是浅层神经⽹络和深度神经⽹络的分界线。\n"
  11. ]
  12. },
  13. {
  14. "cell_type": "code",
  15. "execution_count": null,
  16. "metadata": {
  17. "collapsed": true
  18. },
  19. "outputs": [],
  20. "source": [
  21. "import torch.nn as nn\n",
  22. "import torch\n",
  23. "\n",
  24. "class AlexNet(nn.Module):\n",
  25. " def __init__(self, num_classes=1000, init_weights=False): \n",
  26. " super(AlexNet, self).__init__()\n",
  27. " self.features = nn.Sequential( \n",
  28. " nn.Conv2d(3, 96, kernel_size=11, stride=4, padding=2), \n",
  29. " nn.ReLU(inplace=True), #inplace 可以载入更大模型\n",
  30. " nn.MaxPool2d(kernel_size=3, stride=2), \n",
  31. "\n",
  32. " nn.Conv2d(96, 256, kernel_size=5, padding=2),\n",
  33. " nn.ReLU(inplace=True),\n",
  34. " nn.MaxPool2d(kernel_size=3, stride=2),\n",
  35. "\n",
  36. " nn.Conv2d(256, 384, kernel_size=3, padding=1),\n",
  37. " nn.ReLU(inplace=True),\n",
  38. "\n",
  39. " nn.Conv2d(384, 384, kernel_size=3, padding=1),\n",
  40. " nn.ReLU(inplace=True),\n",
  41. "\n",
  42. " nn.Conv2d(384, 256, kernel_size=3, padding=1),\n",
  43. " nn.ReLU(inplace=True),\n",
  44. " nn.MaxPool2d(kernel_size=3, stride=2),\n",
  45. " )\n",
  46. " self.classifier = nn.Sequential(\n",
  47. " nn.Dropout(p=0.5),\n",
  48. " nn.Linear(256*6*6, 4096), #全链接\n",
  49. " nn.ReLU(inplace=True),\n",
  50. " nn.Dropout(p=0.5),\n",
  51. " nn.Linear(4096, 4096),\n",
  52. " nn.ReLU(inplace=True),\n",
  53. " nn.Linear(4096, num_classes),\n",
  54. " )\n",
  55. " if init_weights:\n",
  56. " self._initialize_weights()\n",
  57. "\n",
  58. " def forward(self, x):\n",
  59. " x = self.features(x)\n",
  60. " x = torch.flatten(x, start_dim=1) #展平或者view()\n",
  61. " x = self.classifier(x)\n",
  62. " return x\n",
  63. "\n",
  64. " def _initialize_weights(self):\n",
  65. " for m in self.modules():\n",
  66. " if isinstance(m, nn.Conv2d):\n",
  67. " #何教授方法\n",
  68. " nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu') \n",
  69. " if m.bias is not None:\n",
  70. " nn.init.constant_(m.bias, 0)\n",
  71. " elif isinstance(m, nn.Linear):\n",
  72. " #正态分布赋值\n",
  73. " nn.init.normal_(m.weight, 0, 0.01) \n",
  74. " nn.init.constant_(m.bias, 0)"
  75. ]
  76. }
  77. ],
  78. "metadata": {
  79. "kernelspec": {
  80. "display_name": "Python 3",
  81. "language": "python",
  82. "name": "python3"
  83. },
  84. "language_info": {
  85. "codemirror_mode": {
  86. "name": "ipython",
  87. "version": 3
  88. },
  89. "file_extension": ".py",
  90. "mimetype": "text/x-python",
  91. "name": "python",
  92. "nbconvert_exporter": "python",
  93. "pygments_lexer": "ipython3",
  94. "version": "3.5.4"
  95. }
  96. },
  97. "nbformat": 4,
  98. "nbformat_minor": 2
  99. }

机器学习越来越多应用到飞行器、机器人等领域,其目的是利用计算机实现类似人类的智能,从而实现装备的智能化与无人化。本课程旨在引导学生掌握机器学习的基本知识、典型方法与技术,通过具体的应用案例激发学生对该学科的兴趣,鼓励学生能够从人工智能的角度来分析、解决飞行器、机器人所面临的问题和挑战。本课程主要内容包括Python编程基础,机器学习模型,无监督学习、监督学习、深度学习基础知识与实现,并学习如何利用机器学习解决实际问题,从而全面提升自我的《综合能力》。