Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit b0cc1c4

Browse files
authored
Removing softmax as terminal activation within remaining image classification models. (#491)
1 parent 08692fb commit b0cc1c4

File tree

5 files changed

+7
-8
lines changed

5 files changed

+7
-8
lines changed

Models/ImageClassification/EfficientNet.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public struct EfficientNet: Layer {
271271
dropoutProb = Dropout<Float>(probability: dropout)
272272
outputClassifier = Dense(
273273
inputSize: makeDivisible(filter: 1280, width: width),
274-
outputSize: classCount, activation: softmax)
274+
outputSize: classCount)
275275
}
276276

277277
@differentiable

Models/ImageClassification/MobileNetV2.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ public struct MobileNetV2: Layer {
219219
outputConvBatchNorm = BatchNorm(featureCount: lastBlockFilterCount)
220220

221221
outputClassifier = Dense(
222-
inputSize: lastBlockFilterCount, outputSize: classCount,
223-
activation: softmax)
222+
inputSize: lastBlockFilterCount, outputSize: classCount)
224223
}
225224

226225
@differentiable

Models/ImageClassification/MobileNetV3.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public struct MobileNetV3Large: Layer {
357357
input.shape[0], 1, 1, self.lastConvChannel,
358358
])
359359
let finalConvResult = dropoutLayer(hardSwish(finalConv(averagePool)))
360-
return softmax(flatten(classiferConv(finalConvResult)))
360+
return flatten(classiferConv(finalConvResult))
361361
}
362362
}
363363

@@ -473,6 +473,6 @@ public struct MobileNetV3Small: Layer {
473473
input.shape[0], 1, 1, lastConvChannel,
474474
])
475475
let finalConvResult = dropoutLayer(hardSwish(finalConv(averagePool)))
476-
return softmax(flatten(classiferConv(finalConvResult)))
476+
return flatten(classiferConv(finalConvResult))
477477
}
478478
}

Models/ImageClassification/VGG.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public struct VGG16: Layer {
5858
layer3 = VGGBlock(featureCounts: (128, 256, 256, 256), blockCount: 3)
5959
layer4 = VGGBlock(featureCounts: (256, 512, 512, 512), blockCount: 3)
6060
layer5 = VGGBlock(featureCounts: (512, 512, 512, 512), blockCount: 3)
61-
output = Dense(inputSize: 4096, outputSize: classCount, activation: softmax)
61+
output = Dense(inputSize: 4096, outputSize: classCount)
6262
}
6363

6464
@differentiable
@@ -86,7 +86,7 @@ public struct VGG19: Layer {
8686
layer3 = VGGBlock(featureCounts: (128, 256, 256, 256), blockCount: 4)
8787
layer4 = VGGBlock(featureCounts: (256, 512, 512, 512), blockCount: 4)
8888
layer5 = VGGBlock(featureCounts: (512, 512, 512, 512), blockCount: 4)
89-
output = Dense(inputSize: 4096, outputSize: classCount, activation: softmax)
89+
output = Dense(inputSize: 4096, outputSize: classCount)
9090
}
9191

9292
@differentiable

Models/Spatiotemporal/C3D.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public struct C3D: Layer {
3939
var output: Dense<Float>
4040

4141
public init(classCount: Int) {
42-
self.output = Dense<Float>(inputSize: 1024, outputSize: classCount, activation: softmax)
42+
self.output = Dense<Float>(inputSize: 1024, outputSize: classCount)
4343
}
4444

4545
@differentiable

0 commit comments

Comments
 (0)