进入Demo所在目录

  1. cd /E/MAX78000/MAXSDK/Examples/MAX78000/CNN/kws20_demo

执行编译

  1. make

image.png
如果之前已经被编译过了,可以先清除,再make

  1. make distclean

选择板型

根据自己用的开发板不一样,注释掉BOARD=EvKit_V1
To compile code for MAX78000 EVKIT enable BOARD=EvKit_V1 in project.mk:

  1. # Specify the board used
  2. ifeq "$(BOARD)" ""
  3. BOARD=EvKit_V1
  4. #BOARD=FTHR_RevA
  5. endif

To compile code for MAX78000 Feather board enable BOARD=FTHR_RevA in project.mk:

  1. # Specify the board used
  2. ifeq "$(BOARD)" ""
  3. #BOARD=EvKit_V1
  4. BOARD=FTHR_RevA
  5. endif

如果你用的IDE来开发的,可以这里设置。
image.png
之后可以打开这个文件,来看一下
image.png

开始烧录

如果你是Window上整的

  1. openocd -s $MAXIM_PATH/Tools/OpenOCD/scripts -f interface/cmsis-dap.cfg -f target/max78000.cfg -c "program build/MAX78000.elf reset exit"

image.png
然后就烧录进去了,没了,里面本来的那个Demo没了,变成这玩意了
image.png
如果你在Linux上

  1. ./openocd -f tcl/interface/cmsis-dap.cfg -f tcl/target/max78000.cfg -c "program build/MAX78000.elf verify reset exit"

我看代码其实不应该是这样的,但暂时没找出来问题出在了哪里。
image.png

原理部分

这个Demo的软件框图如下
image.png

CNN Model 卷积神经网络模型

The KWS20 v.3 Convolutional Neural Network (CNN) model consists of 1D CNN with 8 layers and one fully connected layer to recognize keyword from 20 words dictionary used for training.

  1. class AI85KWS20Netv3(nn.Module):
  2. """
  3. Compound KWS20 v3 Audio net, all with Conv1Ds
  4. """
  5. # num_classes = n keywords + 1 unknown
  6. def __init__(
  7. self,
  8. num_classes=21,
  9. num_channels=128,
  10. dimensions=(128, 1), # pylint: disable=unused-argument
  11. bias=False,
  12. **kwargs
  13. ):
  14. super().__init__()
  15. self.drop = nn.Dropout(p=0.2)
  16. # Time: 128 Feature :128
  17. self.voice_conv1 = ai8x.FusedConv1dReLU(num_channels, 100, 1,
  18. stride=1, padding=0,
  19. bias=bias, **kwargs)
  20. # T: 128 F: 100
  21. self.voice_conv2 = ai8x.FusedConv1dReLU(100, 96, 3,
  22. stride=1, padding=0,
  23. bias=bias, **kwargs)
  24. # T: 126 F : 96
  25. self.voice_conv3 = ai8x.FusedMaxPoolConv1dReLU(96, 64, 3,
  26. stride=1, padding=1,
  27. bias=bias, **kwargs)
  28. # T: 62 F : 64
  29. self.voice_conv4 = ai8x.FusedConv1dReLU(64, 48, 3,
  30. stride=1, padding=0,
  31. bias=bias, **kwargs)
  32. # T : 60 F : 48
  33. self.kws_conv1 = ai8x.FusedMaxPoolConv1dReLU(48, 64, 3,
  34. stride=1, padding=1,
  35. bias=bias, **kwargs)
  36. # T: 30 F : 64
  37. self.kws_conv2 = ai8x.FusedConv1dReLU(64, 96, 3,
  38. stride=1, padding=0,
  39. bias=bias, **kwargs)
  40. # T: 28 F : 96
  41. self.kws_conv3 = ai8x.FusedAvgPoolConv1dReLU(96, 100, 3,
  42. stride=1, padding=1,
  43. bias=bias, **kwargs)
  44. # T : 14 F: 100
  45. self.kws_conv4 = ai8x.FusedMaxPoolConv1dReLU(100, 64, 6,
  46. stride=1, padding=1,
  47. bias=bias, **kwargs)
  48. # T : 2 F: 128
  49. self.fc = ai8x.Linear(256, num_classes, bias=bias, wide=True, **kwargs)
  50. def forward(self, x): # pylint: disable=arguments-differ
  51. """Forward prop"""
  52. # Run CNN
  53. x = self.voice_conv1(x)
  54. x = self.voice_conv2(x)
  55. x = self.drop(x)
  56. x = self.voice_conv3(x)
  57. x = self.voice_conv4(x)
  58. x = self.drop(x)
  59. x = self.kws_conv1(x)
  60. x = self.kws_conv2(x)
  61. x = self.drop(x)
  62. x = self.kws_conv3(x)
  63. x = self.kws_conv4(x)
  64. x = x.view(x.size(0), -1)
  65. x = self.fc(x)
  66. return x

The CNN input is 128x128=16384 8-bit signed speech samples.

试试烧录试kws20_v3

image.png
成功。image.png
在编译烧录之前一定注意,要先make distclean 一下,不然会出问题的

尝试烧录 work15

  1. cd /E/MAX78000/voice_light/work15/work15/kws20_demo/

image.png
报错喽

尝试烧录kws20_demo-riscv

  1. $ cd /E/MAX78000/MAXSDK/Examples/MAX78000/CNN/kws20_demo-riscv/

image.png