Skip to content

Commit ff16f7b

Browse files
committed
Fix minor code warnings
1 parent e8111f5 commit ff16f7b

File tree

10 files changed

+23
-31
lines changed

10 files changed

+23
-31
lines changed

api/src/main/kotlin/org/jetbrains/kotlinx/dl/api/core/GraphTrainableModel.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public abstract class GraphTrainableModel(vararg layers: Layer) : TrainableModel
412412
// TODO: probably I should it by name, not by type
413413
val validationLossValue = evaluationResult.lossValue
414414
epochTrainingEvent.valLossValue = validationLossValue
415-
epochTrainingEvent.valMetricValues = validationMetricValues!!
415+
epochTrainingEvent.valMetricValues = validationMetricValues
416416
logger.info { "epochs: $i loss: $avgLossValue metric: ${avgTrainingMetricValue.contentToString()} val loss: $validationLossValue val metrics: $validationMetricValues" } // TODO: check printing for validation
417417
} else {
418418
logger.info { "epochs: $i loss: $avgLossValue metric: ${avgTrainingMetricValue.contentToString()}" }

api/src/main/kotlin/org/jetbrains/kotlinx/dl/api/core/Sequential.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ public class Sequential(vararg layers: Layer) : GraphTrainableModel(*layers) {
112112
"It is generated during Sequential model saving with SavingFormat.JSON_CONFIG_CUSTOM_VARIABLES."
113113
)
114114

115-
return org.jetbrains.kotlinx.dl.api.inference.keras.loadSequentialModelConfiguration(
116-
configuration, inputShape
117-
)
115+
return loadSequentialModelConfiguration(configuration, inputShape)
118116
}
119117

120118
/**

api/src/main/kotlin/org/jetbrains/kotlinx/dl/api/core/TrainableModel.kt

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 JetBrains s.r.o. and Kotlin Deep Learning project contributors. All Rights Reserved.
2+
* Copyright 2020-2022 JetBrains s.r.o. and Kotlin Deep Learning project contributors. All Rights Reserved.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
44
*/
55

@@ -476,10 +476,6 @@ public abstract class TrainableModel : TensorFlowInferenceModel() {
476476
)
477477
}
478478

479-
public override fun close() {
480-
super.close()
481-
}
482-
483479
/**
484480
* Returns model summary.
485481
*

api/src/main/kotlin/org/jetbrains/kotlinx/dl/api/core/callback/EarlyStopping.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 JetBrains s.r.o. and Kotlin Deep Learning project contributors. All Rights Reserved.
2+
* Copyright 2020-2022 JetBrains s.r.o. and Kotlin Deep Learning project contributors. All Rights Reserved.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
44
*/
55

@@ -125,9 +125,7 @@ public class EarlyStopping(
125125
if ((monitorOp ?: return).apply(current.toDouble() - minDelta, best)) {
126126
best = current.toDouble()
127127
wait = 0
128-
if (restoreBestWeights) {
129-
// TODO this.bestWeights = this.model.getWeights();
130-
}
128+
// TODO if (restoreBestWeights) this.bestWeights = this.model.getWeights();
131129
} else {
132130
wait++
133131
if (wait > patience) {

api/src/main/kotlin/org/jetbrains/kotlinx/dl/api/core/layer/merge/Dot.kt

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class Dot(
3333
require(input.size == 2) { "A `Dot` layer should be called on exactly 2 input. 'Received: input=${input}" }
3434
var x1 = input[0]
3535
var x2 = input[1]
36-
val axes: IntArray = IntArray(2)
37-
val scope: Scope = tf.scope()
36+
val axes = IntArray(2)
37+
val scope = tf.scope()
3838
for (i in 0 until 2) {
3939
if (axis[i] < 0) {
4040
axes[i] = axis[i] % input[i].asOutput().shape().numDimensions()
@@ -89,7 +89,7 @@ public fun batchDot(scope: Scope?, x: Operand<Float>, y: Operand<Float>, axis: I
8989
val xDim = x.asOutput().shape().numDimensions()
9090
val yDim = y.asOutput().shape().numDimensions()
9191
val diff: Int
92-
var x2: Operand<Float> = x;
92+
var x2: Operand<Float> = x
9393
var y2: Operand<Float> = y
9494
if (xDim > yDim) {
9595
diff = xDim - yDim
@@ -120,10 +120,10 @@ public fun batchDot(scope: Scope?, x: Operand<Float>, y: Operand<Float>, axis: I
120120
val x2Dim = x2.asOutput().shape().numDimensions()
121121
val y2Dim = y2.asOutput().shape().numDimensions()
122122
if (x2Dim == 2 && y2Dim == 2) {
123-
if (axis[0] == axis[1]) {
124-
out = ReduceSum.create(scope, Mul.create(scope, x2, y2), Constant.create(scope, axis[0]))
123+
out = if (axis[0] == axis[1]) {
124+
ReduceSum.create(scope, Mul.create(scope, x2, y2), Constant.create(scope, axis[0]))
125125
} else {
126-
out = ReduceSum.create(
126+
ReduceSum.create(
127127
scope,
128128
Mul.create(scope, Transpose.create(scope, x2, Constant.create(scope, intArrayOf(1, 0))), y2),
129129
Constant.create(scope, axis[1])
@@ -142,10 +142,10 @@ public fun batchDot(scope: Scope?, x: Operand<Float>, y: Operand<Float>, axis: I
142142
}
143143
val idx: Float
144144
if (diff != 0) {
145-
if (xDim > yDim) {
146-
idx = (xDim + yDim - 3).toFloat()
145+
idx = if (xDim > yDim) {
146+
(xDim + yDim - 3).toFloat()
147147
} else {
148-
idx = (xDim - 1).toFloat()
148+
(xDim - 1).toFloat()
149149
}
150150
out = Squeeze.create(scope, Constant.create(scope, FloatArray(diff) { it + idx }))
151151
}

api/src/main/kotlin/org/jetbrains/kotlinx/dl/dataset/embeddedDatasets.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public fun freeSpokenDigits(
189189
val dataset = File(path)
190190
.listFiles()?.flatMap(::extractWavFileSamples)
191191
?: throw IllegalStateException("Cannot find Free Spoken Digits Dataset files in $path")
192-
val maxDataSize = dataset.map { it.first.size }.maxOrNull()
192+
val maxDataSize = dataset.maxOfOrNull { it.first.size }
193193
?: throw IllegalStateException("Empty Free Spoken Digits Dataset")
194194
check(maxDataSize <= FSDD_SOUND_DATA_SIZE) {
195195
"Sound data should be limited to $FSDD_SOUND_DATA_SIZE values but has $maxDataSize"

dataset/src/main/kotlin/org/jetbrains/kotlinx/dl/dataset/OnHeapDataset.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public class OnHeapDataset internal constructor(public val x: Array<FloatArray>,
242242
return FloatArray(xFiles.size) { Float.NaN }
243243
}
244244
else -> {
245-
throw UnsupportedOperationException("Unknown label generator: ${labelGenerator.toString()}") // TODO: labelGenerator.apply(...) will be better solution here.
245+
throw UnsupportedOperationException("Unknown label generator: ${labelGenerator}") // TODO: labelGenerator.apply(...) will be better solution here.
246246
}
247247
}
248248
}

docs/quick_start_guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ first you'll need to set up the appropriate dependencies.
77
1. Open a Kotlin project where you want to use Kotlin DL, or create a new Kotlin project in IntelliJ IDEA as described in the [Kotlin documentation](https://kotlinlang.org/docs/tutorials/jvm-get-started.html).
88
2. Add the Kotlin DL dependency to your project's build file.
99
* If you're using Gradle as the build system, add the following to the `build.gradle` file:
10-
```kotlin
10+
```groovy
1111
repositories {
1212
mavenCentral()
1313
}

examples/src/main/kotlin/examples/cnn/mnist/advanced/LeNetWithAlternativeLossFunction.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,24 @@ fun lenetWithAlternativeLossFunction() {
4848

4949
val (newTrain, validation) = train.split(0.95)
5050

51-
lenet5Classic.use {
52-
it.compile(
51+
lenet5Classic.use { model ->
52+
model.compile(
5353
optimizer = Adam(),
5454
loss = Losses.HUBER,
5555
metric = Metrics.ACCURACY
5656
)
5757

58-
it.logSummary()
58+
model.logSummary()
5959

60-
val history = it.fit(
60+
val history = model.fit(
6161
trainingDataset = newTrain,
6262
validationDataset = validation,
6363
epochs = EPOCHS,
6464
trainBatchSize = TRAINING_BATCH_SIZE,
6565
validationBatchSize = TEST_BATCH_SIZE
6666
)
6767

68-
val accuracy = it.evaluate(dataset = test, batchSize = TEST_BATCH_SIZE).metrics[Metrics.ACCURACY]
68+
val accuracy = model.evaluate(dataset = test, batchSize = TEST_BATCH_SIZE).metrics[Metrics.ACCURACY]
6969

7070
println("Accuracy: $accuracy")
7171

examples/src/main/kotlin/examples/transferlearning/modelhub/mobilenet/additionalTrainingForMobileNet.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private const val TRAIN_TEST_SPLIT_RATIO = 0.7
4949
*/
5050
fun mobilenetWithAdditionalTraining() {
5151
val modelHub = TFModelHub(cacheDirectory = File("cache/pretrainedModels"))
52-
var modelType = TFModels.CV.MobileNet()
52+
val modelType = TFModels.CV.MobileNet()
5353
val model = modelHub.loadModel(modelType)
5454

5555
val preprocessing: Preprocessing = preprocess {

0 commit comments

Comments
 (0)