-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
32 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
from tensorflow import keras | ||
import keras as k | ||
|
||
OPT_SHORTCUTS = ["sgd", "rmsprop", "adam"] | ||
TF_OPTIMIZERS = [ | ||
keras.optimizers.SGD(), | ||
keras.optimizers.RMSprop(), | ||
keras.optimizers.Adam(), | ||
k.optimizers.SGD(), | ||
k.optimizers.RMSprop(), | ||
k.optimizers.Adam(), | ||
] | ||
|
||
|
||
def checkOptimizer(optimizer) -> keras.optimizers.Optimizer: | ||
def checkOptimizer(optimizer) -> k.optimizers.Optimizer: | ||
if isinstance(optimizer, str): | ||
if optimizer in OPT_SHORTCUTS: | ||
for opt, tf_opt in zip(OPT_SHORTCUTS, TF_OPTIMIZERS): | ||
if optimizer == opt: | ||
return tf_opt | ||
else: | ||
raise ValueError( | ||
f"`optimizer` should be selected in {OPT_SHORTCUTS}, " | ||
f'"optimizer" should be selected in {OPT_SHORTCUTS}, ' | ||
f"instead '{optimizer}' passed" | ||
) | ||
elif isinstance(optimizer, keras.optimizers.Optimizer): | ||
elif isinstance(optimizer, k.optimizers.Optimizer): | ||
return optimizer | ||
else: | ||
raise TypeError( | ||
f"`optimizer` should be a TensorFlow `Optimizer`, " | ||
f'"optimizer" should be a Keras Optimizer, ' | ||
f"instead {type(optimizer)} passed" | ||
) |
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