Skip to content

Commit

Permalink
fixes #469
Browse files Browse the repository at this point in the history
  • Loading branch information
amaiya committed Dec 11, 2022
1 parent 39c0c22 commit 1ab2025
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ Most recent releases are shown at the top. Each release shows:
- **Changed**: Additional parameters, changes to inputs or outputs, etc
- **Fixed**: Bug fixes that don't change documented behaviour

## 0.32.1 (2022-12-11)

### new:
- N/A

### changed
- N/A

### fixed:
- In TensorFlow 2.11, the `tf.optimizers.Optimizer` base class points the new keras optimizer that seems to have problems. Users should use legacy optimizers in `tf.keras.optimizers.legacy` with **ktrain** (which evidently will never be deleted). This means that, in TF 2.11, supplying a string representation of an optimizer like `"adam"` to `model.compile` uses the new optimizer instead of the legacy optimizers. In these cases, **ktrain** will issue a warning and automatically recompile the model with the default `tf.keras.optimizers.legacy.Adam` optimizer.


## 0.32.0 (2022-12-08)

### new:
Expand Down
15 changes: 14 additions & 1 deletion ktrain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def get_learner(
learner = BERTTextClassLearner
else: # vanilla text classifiers use standard ArrayLearners
learner = ArrayLearner
return learner(
l = learner(
model,
train_data=train_data,
val_data=val_data,
Expand All @@ -127,6 +127,19 @@ def get_learner(
workers=workers,
use_multiprocessing=use_multiprocessing,
)
import tensorflow as tf
from tensorflow.keras.optimizers import Optimizer
import warnings
from packaging import version

if (version.parse(tf.__version__) >= version.parse("2.11")) and (
isinstance(l.model.optimizer, Optimizer)
):
warnings.warn(
"ktrain currently only supports legacy optimizers in tensorflow>=2.11 - recompiling your model to use legacy Adam"
)
l._recompile(wd=0)
return l


# keys
Expand Down
2 changes: 1 addition & 1 deletion ktrain/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__all__ = ["__version__"]
__version__ = "0.32.0"
__version__ = "0.32.1"
4 changes: 2 additions & 2 deletions ktrain/vision/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def image_classifier(
If None, then all layers except new Dense layers
will be frozen/untrainable.
metrics (list): metrics to use
optimizer_name(str): name of Keras optimizer (e.g., 'adam', 'sgd')
optimizer_name(str|obj): name of Keras optimizer (e.g., 'adam', 'sgd') or instance of keras Optimizer
multilabel(bool): If True, model will be build to support
multilabel classificaiton (labels are not mutually exclusive).
If False, binary/multiclassification model will be returned.
Expand Down Expand Up @@ -259,7 +259,7 @@ def image_model(
If None, then all layers except new Dense layers
will be frozen/untrainable.
metrics (list): metrics to use
optimizer_name(str): name of Keras optimizer (e.g., 'adam', 'sgd')
optimizer_name(str|obj): name of Keras optimizer (e.g., 'adam', 'sgd') or instance of Keras optimizer
multilabel(bool): If True, model will be build to support
multilabel classificaiton (labels are not mutually exclusive).
If False, binary/multiclassification model will be returned.
Expand Down

0 comments on commit 1ab2025

Please sign in to comment.