-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Compare:
convmixer-patches-are-all-you-need/convmixer/convMixerLayers.m
Lines 96 to 99 in 9770885
| lgraph = addLayers(lgraph, softmaxLayer('Name','softmax')); | |
| lgraph = addLayers(lgraph, classificationLayer('Name','classification')); | |
| lgraph = connectLayers(lgraph,'fc','softmax'); | |
| lgraph = connectLayers(lgraph,'softmax','classification'); |
with
convmixer-patches-are-all-you-need/convmixer/convMixerLayers.m
Lines 88 to 93 in 9770885
| gapFc = [ | |
| globalAveragePooling2dLayer(Name="GAP") | |
| fullyConnectedLayer(num_classes) | |
| ]; | |
| lgraph = addLayers(lgraph,gapFc); | |
| lgraph = connectLayers(lgraph,"batchnorm_"+2*depth,"GAP"); |
I think that the second is nicer as it only requires one call to addLayers and connectLayers
out = [
softmaxLayer(Name='softmax'))
classificationLayer(Name='classification'))
];
lgraph = addLayers(lgraph, out);
lgraph = connectLayers(lgraph,'fc','softmax');
And then, because of the call to connectLayers I think it is better to explicitly name the final fully connected layer rather than reply on automatic naming, i.e., L90 should be fullyConnectedLayer(num_classes,Name='fc')
Another thing to consider is to concatenate the last two layers with the previous two before the call to addLayer, i.e.,
last = [
globalAveragePooling2dLayer(Name="GAP")
fullyConnectedLayer(num_classes)
];
if connectOutputLayers
last = [
last
softmaxLayer()
classificationLayer()
];
end
lgraph = addLayers(lgraph,last);
lgraph = connectLayers(lgraph,"batchnorm_"+2*depth,"GAP");
With that version, you don't need to explicitly name most of the layers, just then ones that are referenced in the calls to connectLayers.