Skip to content

Commit

Permalink
Serialize custom layer and test with mlflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dnerini committed Nov 27, 2023
1 parent 9decd1d commit e066839
Show file tree
Hide file tree
Showing 4 changed files with 1,186 additions and 490 deletions.
14 changes: 10 additions & 4 deletions mlpp_lib/models.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import tensorflow as tf
import logging
from typing import Optional, Union, Any

import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import (
Add,
Dense,
Dropout,
BatchNormalization,
Activation,
)

from tensorflow.keras import Model, initializers

from mlpp_lib.physical_layers import *
from mlpp_lib.probabilistic_layers import *

import numpy as np

try:
import tcn # type: ignore
except ImportError:
Expand All @@ -24,6 +23,10 @@
TCN_IMPORTED = True


_LOGGER = logging.getLogger(__name__)


@tf.keras.utils.register_keras_serializable()
class MonteCarloDropout(Dropout):
def call(self, inputs):
return super().call(inputs, training=True)
Expand All @@ -39,6 +42,9 @@ def _build_fcn_block(
skip_connection,
idx=0,
):
if mc_dropout and dropout is None:
_LOGGER.warning("dropout=None, hence I will ignore mc_dropout=True")

x = inputs
for i, units in enumerate(hidden_layers):
x = Dense(units, name=f"dense_{idx}_{i}")(x)
Expand Down
Loading

0 comments on commit e066839

Please sign in to comment.