%% Load Pretrained YAMNet
% Load a pretrained YAMNet convolutional neural network and examine the layers and classes.
% Use yamnet to load the pretrained YAMNet network. The output net is a SeriesNetwork object.

net = yamnet

%
% View the network architecture using the Layers property. The network has 86 layers. There are 28 layers with learnable weights: 27 convolutional layers, and 1 fully connected layer.

net.Layers

%
% To view the names of the classes learned by the network, you can view the Classes property of the classification output layer (the final layer). View the first 10 classes by specifying the first 10 elements.

net.Layers(end).Classes(1:10)

%
% Use analyzeNetwork to visually explore the network.

analyzeNetwork(net)

%
%
% YAMNet was released with a corresponding sound class ontology, which you can explore using the yamnetGraph object.

ygraph = yamnetGraph;
p = plot(ygraph);
layout(p,'layered')

%
% The ontology graph plots all 521 possible sound classes. Plot a subgraph of the sounds related to respiratory sounds.

allRespiratorySounds = dfsearch(ygraph,"Respiratory sounds");
ygraphSpeech = subgraph(ygraph,allRespiratorySounds);
plot(ygraphSpeech)

%
% Copyright 2020 The MathWorks, Inc.