Skip to content

Commit

Permalink
fix: rename tensorflow to keras
Browse files Browse the repository at this point in the history
  • Loading branch information
dstalzjohn authored and aiakide committed Dec 18, 2023
1 parent c6f9fd3 commit f38536f
Show file tree
Hide file tree
Showing 55 changed files with 157 additions and 143 deletions.
4 changes: 2 additions & 2 deletions configs/ops/prediction/op_prediction_base.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
model_loader:
_target_: niceml.dlframeworks.tensorflow.kerasmodelloader.KerasModelLoader
_target_: niceml.dlframeworks.keras.kerasmodelloader.KerasModelLoader
prediction_steps: ${niceml.to_int:${oc.env:PREDICTION_STEPS,null}}
prediction_function:
_target_: niceml.dlframeworks.tensorflow.predictionfunctions.keraspredictionfunction.KerasPredictionFunction
_target_: niceml.dlframeworks.keras.predictionfunctions.keraspredictionfunction.KerasPredictionFunction
8 changes: 4 additions & 4 deletions configs/ops/train/callbacks/callbacks_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

_target_: niceml.mlcomponents.callbacks.callbackinitializer.CallbackInitializer
callback_list:
- _target_: niceml.dlframeworks.tensorflow.callbacks.callback_factories.InitCallbackFactory
- _target_: niceml.dlframeworks.keras.callbacks.callback_factories.InitCallbackFactory
callback:
_target_: niceml.dlframeworks.tensorflow.callbacks.nancheckcallback.LossNanCheckCallback
- _target_: niceml.dlframeworks.tensorflow.callbacks.callback_factories.LoggingOutputCallbackFactory
_target_: niceml.dlframeworks.keras.callbacks.nancheckcallback.LossNanCheckCallback
- _target_: niceml.dlframeworks.keras.callbacks.callback_factories.LoggingOutputCallbackFactory
callback_dict:
save_model:
# Stores the model after each epoch
_target_: niceml.dlframeworks.tensorflow.callbacks.callback_factories.ModelCallbackFactory
_target_: niceml.dlframeworks.keras.callbacks.callback_factories.ModelCallbackFactory
model_subfolder: models/model-id_{short_id}-ep{epoch:03d}.hdf5
6 changes: 3 additions & 3 deletions configs/ops/train/op_train_cls_binary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ data_validation:
sub_dir: validation
set_name: validation
model:
_target_: niceml.dlframeworks.tensorflow.models.mobilenet.OwnMobileNetModel
_target_: niceml.dlframeworks.keras.models.mobilenet.OwnMobileNetModel
final_activation: sigmoid
learner:
_target_: niceml.dlframeworks.tensorflow.learners.defaultlearner.DefaultLearner
_target_: niceml.dlframeworks.keras.learners.keraslearner.KerasLearner
model_compiler:
_target_: niceml.dlframeworks.tensorflow.modelcompiler.defaultmodelcompiler.DefaultModelCompiler
_target_: niceml.dlframeworks.keras.modelcompiler.defaultmodelcompiler.DefaultModelCompiler
loss: binary_crossentropy
# Optimizer used in the experiment
optimizer:
Expand Down
24 changes: 12 additions & 12 deletions configs/ops/train/op_train_objdet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ data_description:
height: 1024

model:
_target_: niceml.dlframeworks.tensorflow.models.retinanet.RetinaNetFactory
_target_: niceml.dlframeworks.keras.models.retinanet.RetinaNetFactory

learner:
_target_: niceml.dlframeworks.tensorflow.learners.defaultlearner.DefaultLearner
_target_: niceml.dlframeworks.keras.learners.keraslearner.KerasLearner
model_compiler:
_target_: niceml.dlframeworks.tensorflow.modelcompiler.defaultmodelcompiler.DefaultModelCompiler
_target_: niceml.dlframeworks.keras.modelcompiler.defaultmodelcompiler.DefaultModelCompiler
run_eagerly: ${niceml.to_bool:${oc.env:RUN_EAGERLY,false}}
loss:
_target_: niceml.dlframeworks.tensorflow.losses.objdetlosses.CombinationLoss
_target_: niceml.dlframeworks.keras.losses.objdetlosses.CombinationLoss
weights: [5000.0,0.1]
losses:
- _target_: niceml.dlframeworks.tensorflow.losses.objdetlosses.RetinaNetClsLoss
- _target_: niceml.dlframeworks.tensorflow.losses.objdetlosses.RetinaNetBoxLoss
- _target_: niceml.dlframeworks.keras.losses.objdetlosses.RetinaNetClsLoss
- _target_: niceml.dlframeworks.keras.losses.objdetlosses.RetinaNetBoxLoss
# Optimizer is used in the experiment
optimizer:
_target_: tensorflow.keras.optimizers.RMSprop
learning_rate: 0.0001
metrics:
- _target_: niceml.dlframeworks.tensorflow.losses.objdetlosses.RetinaNetClsLoss
- _target_: niceml.dlframeworks.tensorflow.losses.objdetlosses.RetinaNetBoxLoss
- _target_: niceml.dlframeworks.tensorflow.metrics.objdetmetrics.AvgPosPredObjDet
- _target_: niceml.dlframeworks.tensorflow.metrics.objdetmetrics.AvgPosTargetCountObjDet
- _target_: niceml.dlframeworks.tensorflow.metrics.objdetmetrics.AvgNegTargetCountObjDet
- _target_: niceml.dlframeworks.tensorflow.metrics.objdetmetrics.AvgNegPredObjDet
- _target_: niceml.dlframeworks.keras.losses.objdetlosses.RetinaNetClsLoss
- _target_: niceml.dlframeworks.keras.losses.objdetlosses.RetinaNetBoxLoss
- _target_: niceml.dlframeworks.keras.metrics.objdetmetrics.AvgPosPredObjDet
- _target_: niceml.dlframeworks.keras.metrics.objdetmetrics.AvgPosTargetCountObjDet
- _target_: niceml.dlframeworks.keras.metrics.objdetmetrics.AvgNegTargetCountObjDet
- _target_: niceml.dlframeworks.keras.metrics.objdetmetrics.AvgNegPredObjDet


data_train:
Expand Down
6 changes: 3 additions & 3 deletions configs/ops/train/op_train_reg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ data_validation:
subset_name: validation
df_filename: numbers_tabular_data_validation.parq
model:
_target_: niceml.dlframeworks.tensorflow.models.mlp.OwnMLP
_target_: niceml.dlframeworks.keras.models.mlp.OwnMLP
activation: tanh
final_activation: tanh
hidden_layers:
- 25
- 35
- 12
learner:
_target_: niceml.dlframeworks.tensorflow.learners.defaultlearner.DefaultLearner
_target_: niceml.dlframeworks.keras.learners.keraslearner.KerasLearner
model_compiler:
_target_: niceml.dlframeworks.tensorflow.modelcompiler.defaultmodelcompiler.DefaultModelCompiler
_target_: niceml.dlframeworks.keras.modelcompiler.defaultmodelcompiler.DefaultModelCompiler
loss: mse
# Optimizer used in the experiment
optimizer:
Expand Down
22 changes: 11 additions & 11 deletions configs/ops/train/op_train_semseg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,39 @@ data_description:
max_number: 3

model:
_target_: niceml.dlframeworks.tensorflow.models.unets.mobilenetv2_unet
_target_: niceml.dlframeworks.keras.models.unets.mobilenetv2_unet
use_input_scale: true
allow_preconvolution: true
activation: sigmoid
alpha: 1.0
downscale_layer_factory:
_target_: niceml.dlframeworks.tensorflow.models.layerfactory.DownscaleConvBlockFactory
_target_: niceml.dlframeworks.keras.models.layerfactory.DownscaleConvBlockFactory
channel_list: [128, 128, 128]
post_layer_factory:
_target_: niceml.dlframeworks.tensorflow.models.layerfactory.Conv2DBlockFactory
_target_: niceml.dlframeworks.keras.models.layerfactory.Conv2DBlockFactory
channel_list: [1024, 1024]
kernel_size: 1
dropout_values: [0.25, 0.25]

learner:
_target_: niceml.dlframeworks.tensorflow.learners.defaultlearner.DefaultLearner
_target_: niceml.dlframeworks.keras.learners.keraslearner.KerasLearner
model_compiler:
_target_: niceml.dlframeworks.tensorflow.modelcompiler.defaultmodelcompiler.DefaultModelCompiler
_target_: niceml.dlframeworks.keras.modelcompiler.defaultmodelcompiler.DefaultModelCompiler
run_eagerly: ${niceml.to_bool:${oc.env:RUN_EAGERLY,false}}
loss:
_target_: niceml.dlframeworks.tensorflow.losses.semseglosses.SemSegFocalLoss
_target_: niceml.dlframeworks.keras.losses.semseglosses.SemSegFocalLoss
alpha: 0.25
gamma: 2.0
# Optimizer is used in the experiment
optimizer:
_target_: tensorflow.keras.optimizers.RMSprop
learning_rate: 0.0001
metrics:
- _target_: niceml.dlframeworks.tensorflow.kerasmetrics.MeanIoU
- _target_: niceml.dlframeworks.tensorflow.metrics.semsegmetrics.AvgPosPredSemSeg
- _target_: niceml.dlframeworks.tensorflow.metrics.semsegmetrics.AvgNegPredSemSeg
- _target_: niceml.dlframeworks.tensorflow.metrics.semsegmetrics.AvgPosTargetCountSemSeg
- _target_: niceml.dlframeworks.tensorflow.metrics.semsegmetrics.AvgNegTargetCountSemSeg
- _target_: niceml.dlframeworks.keras.kerasmetrics.MeanIoU
- _target_: niceml.dlframeworks.keras.metrics.semsegmetrics.AvgPosPredSemSeg
- _target_: niceml.dlframeworks.keras.metrics.semsegmetrics.AvgNegPredSemSeg
- _target_: niceml.dlframeworks.keras.metrics.semsegmetrics.AvgPosTargetCountSemSeg
- _target_: niceml.dlframeworks.keras.metrics.semsegmetrics.AvgNegTargetCountSemSeg

data_train:
datainfo_listing:
Expand Down
6 changes: 3 additions & 3 deletions docs/write-custom-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ data_validation:
sub_dir: validation
set_name: validation
model:
_target_: niceml.dlframeworks.tensorflow.models.mobilenet.OwnMobileNetModel
_target_: niceml.dlframeworks.keras.models.mobilenet.OwnMobileNetModel
final_activation: sigmoid
model_load_custom_objects:
_target_: niceml.mlcomponents.modelcompiler.modelcustomloadobjects.ModelCustomLoadObjects
learner:
_target_: niceml.dlframeworks.tensorflow.learners.defaultlearner.DefaultLearner
_target_: niceml.dlframeworks.keras.learners.defaultlearner.DefaultLearner
model_compiler:
_target_: niceml.dlframeworks.tensorflow.modelcompiler.defaultmodelcompiler.DefaultModelCompiler
_target_: niceml.dlframeworks.keras.modelcompiler.defaultmodelcompiler.DefaultModelCompiler
loss: binary_crossentropy
# Optimizer used in the experiment
optimizer:
Expand Down
4 changes: 2 additions & 2 deletions niceml/dashboard/cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _load_model(exp: ExperimentData):
exp: experiment (ExperimentData)
Returns:
tensorflow model
keras model
"""

model = load_model(exp.get_model_path())
Expand Down Expand Up @@ -92,7 +92,7 @@ def create_heatmap(
generates heatmap using last conv layer "conv" specified in create_model section
Args:
model: tensorflow Model
model: keras Model
img: image as numpy array
class_idx: class index of output tensor
layer_name: last conv layer name - DEFAULT: "conv"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from pathlib import Path
from typing import Any, List

from niceml.dlframeworks.tensorflow.callbacks.csvlogger import CSVLogger
from niceml.dlframeworks.tensorflow.callbacks.modelcheckpoint import ModelCheckpoint
from niceml.dlframeworks.keras.callbacks.csvlogger import CSVLogger
from niceml.dlframeworks.keras.callbacks.modelcheckpoint import ModelCheckpoint
from niceml.experiments.experimentcontext import ExperimentContext
from niceml.utilities.factoryutils import subs_path_and_create_folder
from niceml.utilities.fsspec.locationutils import join_location_w_path
Expand Down Expand Up @@ -96,6 +96,6 @@ def create_callback(self, exp_context: ExperimentContext):
Path(filepath).mkdir(exist_ok=True, parents=False)

# pylint: disable=import-outside-toplevel
from niceml.dlframeworks.tensorflow.callbacks.cam_callback import CamCallback
from niceml.dlframeworks.keras.callbacks.cam_callback import CamCallback

return CamCallback(output_dir=filepath, images=self.images)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@


# pylint: disable=too-few-public-methods
class DefaultLearner(Learner):
"""default learner for keras/tensorflow models"""
class KerasLearner(Learner):
"""default learner for keras/keras models"""

def __init__(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, alpha: Union[float, List[float]], gamma: float = 2.0, **kwarg
gamma: float
gamma value of the paper
kwargs:
all parameters are applied to tensorflow loss
all parameters are applied to keras loss
"""
super().__init__(**kwargs)
self.alpha = np.array(alpha, dtype=np.float32)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Module for model compilers in tensorflow"""
"""Module for model compilers in keras"""
from typing import Any, List, Union

from niceml.data.datadescriptions.datadescription import DataDescription
Expand All @@ -8,7 +8,7 @@


class DefaultModelCompiler(ModelCompiler): # pylint: disable=too-few-public-methods
"""Simplest model compiler for tensorflow"""
"""Simplest model compiler for keras"""

def __init__(
self, loss: Union[str, dict], metrics: List, optimizer: dict, **kwargs
Expand All @@ -32,7 +32,7 @@ def compile(


class ComplexModelCompiler(ModelCompiler): # pylint: disable=too-few-public-methods
"""Complex model compiler for tensorflow"""
"""Complex model compiler for keras"""

def __init__(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from niceml.data.datadescriptions.outputdatadescriptions import (
OutputVectorDataDescription,
)
from niceml.dlframeworks.tensorflow.models.premodellayers import add_premodel_layers
from niceml.dlframeworks.keras.models.premodellayers import add_premodel_layers
from niceml.mlcomponents.models.modelfactory import ModelFactory
from niceml.utilities.commonutils import check_instance
from niceml.utilities.imagesize import ImageSize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Module for ownmlp for tensorflow model"""
"""Module for ownmlp for keras model"""
from typing import Any, List

from tensorflow.keras import Sequential, layers # pylint: disable=import-error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from niceml.data.datadescriptions.outputdatadescriptions import (
OutputObjDetDataDescription,
)
from niceml.dlframeworks.tensorflow.models.premodellayers import add_premodel_layers
from niceml.dlframeworks.keras.models.premodellayers import add_premodel_layers
from niceml.mlcomponents.models.modelfactory import ModelFactory
from niceml.utilities.commonutils import check_instance
from niceml.utilities.imagesize import ImageSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from niceml.data.datadescriptions.outputdatadescriptions import (
OutputImageDataDescription,
)
from niceml.dlframeworks.tensorflow.models.layerfactory import LayerFactory
from niceml.dlframeworks.tensorflow.models.premodellayers import add_premodel_layers
from niceml.dlframeworks.keras.models.layerfactory import LayerFactory
from niceml.dlframeworks.keras.models.premodellayers import add_premodel_layers
from niceml.mlcomponents.models.modelfactory import ModelFactory
from niceml.utilities.commonutils import check_instance

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class CyclicLRSchedule(LearningRateSchedule):
"""Cyclic learning rate schedule"""

def __init__(self, max_lr: float, cycle_size: int, min_lr: Optional[float] = None):
"""
Constructor for CyclicLRSchedule
Args:
max_lr: maximum learning rate
cycle_size: steps per cycle
min_lr: minimum learning rate (default: max_lr / 10)
"""
super().__init__()
self.max_lr = max_lr
self.cycle_size = cycle_size
Expand Down
10 changes: 8 additions & 2 deletions niceml/mlcomponents/callbacks/callbackinitializer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Module for CallbackInitializer"""
from typing import Dict, List, Optional

from niceml.dlframeworks.tensorflow.callbacks.callback_factories import CallbackFactory
from niceml.dlframeworks.keras.callbacks.callback_factories import CallbackFactory
from niceml.experiments.experimentcontext import ExperimentContext


Expand All @@ -13,11 +13,17 @@ def __init__(
callback_list: Optional[List[CallbackFactory]] = None,
callback_dict: Optional[Dict[str, CallbackFactory]] = None,
):
"""
Constructor for CallbackInitializer
Args:
callback_list: A list of callback factories
callback_dict: A dict of callback factories
"""
self.callback_list = callback_list or []
self.callback_dict = callback_dict or {}

def __call__(self, exp_context: ExperimentContext) -> List:
cur_cb: CallbackFactory
"""Initializes the callbacks"""
callback_list = self.callback_list + list(self.callback_dict.values())
cb_init_list = [cur_cb.create_callback(exp_context) for cur_cb in callback_list]
return cb_init_list
Loading

0 comments on commit f38536f

Please sign in to comment.