-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist Constant, Ones, Zeros, Orthogonal and TruncatedNormal initial…
…izers
- Loading branch information
1 parent
2cbd2ee
commit 6d5155f
Showing
7 changed files
with
182 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
...rc/test/kotlin/org/jetbrains/kotlinx/dl/api/inference/keras/InitializerPersistenceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* Copyright 2022 JetBrains s.r.o. and Kotlin Deep Learning project contributors. All Rights Reserved. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlinx.dl.api.inference.keras | ||
|
||
import org.jetbrains.kotlinx.dl.api.core.Sequential | ||
import org.jetbrains.kotlinx.dl.api.core.initializer.* | ||
import org.jetbrains.kotlinx.dl.api.core.layer.core.Dense | ||
import org.jetbrains.kotlinx.dl.api.core.layer.core.Input | ||
import org.junit.jupiter.api.Test | ||
|
||
class InitializerPersistenceTest { | ||
@Test | ||
fun ones() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = Ones()) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun zeros() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = Zeros()) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `random normal`() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = RandomNormal(mean = 10f, stdev = 0.1f, seed = 10)) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `random uniform`() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = RandomUniform(maxVal = 10f, minVal = -10f, seed = 10)) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `truncated normal`() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = TruncatedNormal(seed = 10)) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `glorot normal`() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = GlorotNormal(seed = 10)) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `glorot uniform`() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = GlorotUniform(seed = 10)) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `he normal`() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = HeNormal(seed = 10)) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `he uniform`() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = HeUniform(seed = 10)) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `lecun normal`() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = LeCunNormal(seed = 10)) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `lecun uniform`() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = LeCunUniform(seed = 10)) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun identity() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = Identity(gain = 2.0f)) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun constant() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(10), | ||
Dense(10, kernelInitializer = Constant(constantValue = 2.0f)) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun orthogonal() { | ||
LayerPersistenceTest.run( | ||
Sequential.of( | ||
Input(2), | ||
Dense(2, kernelInitializer = Orthogonal(gain = 0.5f, seed = 10)) | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters