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.

3_CNN_VGG16.py 1.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import sys
  2. sys.path.append('..')
  3. import numpy as np
  4. import torch
  5. from torch import nn
  6. from torch.autograd import Variable
  7. from torchvision.datasets import CIFAR10
  8. def vgg_block(num_convs, in_channels, out_channels):
  9. net = [nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1), \
  10. nn.ReLU(True)] # 定义第一层
  11. for i in range(num_convs-1): # 定义后面的很多层
  12. net.append(nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1))
  13. net.append(nn.ReLU(True))
  14. net.append(nn.MaxPool2d(2, 2)) # 定义池化层
  15. return nn.Sequential(*net)
  16. def vgg_stack(num_convs, channels):
  17. net = []
  18. for n, c in zip(num_convs, channels):
  19. in_c = c[0]
  20. out_c = c[1]
  21. net.append(vgg_block(n, in_c, out_c))
  22. return nn.Sequential(*net)
  23. vgg_net = vgg_stack((2, 2, 3, 3, 3), \
  24. ((3, 64), (64, 128), (128, 256), (256, 512), (512, 512)))
  25. class vgg(nn.Module):
  26. def __init__(self):
  27. super(vgg, self).__init__()
  28. self.feature = vgg_net
  29. self.fc = nn.Sequential(
  30. nn.Linear(512, 100),
  31. nn.ReLU(True),
  32. nn.Linear(100, 10)
  33. )
  34. def forward(self, x):
  35. x = self.feature(x)
  36. x = x.view(x.shape[0], -1)
  37. x = self.fc(x)
  38. return x

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