From ee0cdb0ead0e4bfdff7a3bf7a5dc26e715089b6a Mon Sep 17 00:00:00 2001 From: Falco Weichselbaum <f.weichselbaum@fz-juelich.de> Date: Mon, 25 Oct 2021 12:18:21 +0200 Subject: [PATCH] uncommented imports that were commented for testing in model_class.py and fixed InputSpec import in advanced_paddings.py --- mlair/model_modules/advanced_paddings.py | 44 ++++++++++++++++++++++++ mlair/model_modules/model_class.py | 4 +-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/mlair/model_modules/advanced_paddings.py b/mlair/model_modules/advanced_paddings.py index b0f6c9c2..7a16c2b6 100644 --- a/mlair/model_modules/advanced_paddings.py +++ b/mlair/model_modules/advanced_paddings.py @@ -8,6 +8,7 @@ from typing import Union, Tuple import numpy as np import tensorflow as tf +from tensorflow.keras import backend as K # from tensorflow.keras.backend.common import normalize_data_format from tensorflow.keras.layers import ZeroPadding2D # from tensorflow.keras.layers.convolutional import _ZeroPadding @@ -194,6 +195,49 @@ class PadUtils: return normalized_padding +class InputSpec(object): + """Specifies the ndim, dtype and shape of every input to a layer. + Every layer should expose (if appropriate) an `input_spec` attribute: + a list of instances of InputSpec (one per input tensor). + A None entry in a shape is compatible with any dimension, + a None shape is compatible with any shape. + # Arguments + dtype: Expected datatype of the input. + shape: Shape tuple, expected shape of the input + (may include None for unchecked axes). + ndim: Integer, expected rank of the input. + max_ndim: Integer, maximum rank of the input. + min_ndim: Integer, minimum rank of the input. + axes: Dictionary mapping integer axes to + a specific dimension value. + """ + + def __init__(self, dtype=None, + shape=None, + ndim=None, + max_ndim=None, + min_ndim=None, + axes=None): + self.dtype = dtype + self.shape = shape + if shape is not None: + self.ndim = len(shape) + else: + self.ndim = ndim + self.max_ndim = max_ndim + self.min_ndim = min_ndim + self.axes = axes or {} + + def __repr__(self): + spec = [('dtype=' + str(self.dtype)) if self.dtype else '', + ('shape=' + str(self.shape)) if self.shape else '', + ('ndim=' + str(self.ndim)) if self.ndim else '', + ('max_ndim=' + str(self.max_ndim)) if self.max_ndim else '', + ('min_ndim=' + str(self.min_ndim)) if self.min_ndim else '', + ('axes=' + str(self.axes)) if self.axes else ''] + return 'InputSpec(%s)' % ', '.join(x for x in spec if x) + + class _ZeroPadding(Layer): """Abstract nD ZeroPadding layer (private, used as implementation base). # Arguments diff --git a/mlair/model_modules/model_class.py b/mlair/model_modules/model_class.py index be4f4b22..1165999e 100644 --- a/mlair/model_modules/model_class.py +++ b/mlair/model_modules/model_class.py @@ -123,9 +123,9 @@ __date__ = '2020-05-12' import tensorflow.keras as keras from mlair.model_modules import AbstractModelClass -#from mlair.model_modules.inception_model import InceptionModelBase +from mlair.model_modules.inception_model import InceptionModelBase from mlair.model_modules.flatten import flatten_tail -#from mlair.model_modules.advanced_paddings import PadUtils, Padding2D, SymmetricPadding2D +from mlair.model_modules.advanced_paddings import PadUtils, Padding2D, SymmetricPadding2D from mlair.model_modules.loss import l_p_loss -- GitLab