diff --git a/classification_models/keras.py b/classification_models/keras.py index 65bc88c..43ae583 100644 --- a/classification_models/keras.py +++ b/classification_models/keras.py @@ -1,4 +1,5 @@ -import keras +# import keras +from tensorflow import keras from .models_factory import ModelsFactory diff --git a/classification_models/models/resnet.py b/classification_models/models/resnet.py index d1f0861..9888889 100644 --- a/classification_models/models/resnet.py +++ b/classification_models/models/resnet.py @@ -5,6 +5,7 @@ from ._common_blocks import ChannelSE from .. import get_submodules_from_kwargs from ..weights import load_model_weights +from tensorflow.keras.utils import get_source_inputs backend = None layers = None @@ -209,10 +210,16 @@ def ResNet(model_params, input_shape=None, input_tensor=None, include_top=True, if input_tensor is None: img_input = layers.Input(shape=input_shape, name='data') else: - if not backend.is_keras_tensor(input_tensor): - img_input = layers.Input(tensor=input_tensor, shape=input_shape) - else: - img_input = input_tensor + """ Commented to solve following error: + ValueError: Unexpectedly found an instance of type + ``. + Expected a symbolic tensor instance. + """ + # if not backend.is_keras_tensor(input_tensor): + # img_input = layers.Input(tensor=input_tensor, shape=input_shape) + # else: + # img_input = input_tensor + img_input = input_tensor # choose residual block type ResidualBlock = model_params.residual_block @@ -266,7 +273,11 @@ def ResNet(model_params, input_shape=None, input_tensor=None, include_top=True, # Ensure that the model takes into account any potential predecessors of `input_tensor`. if input_tensor is not None: - inputs = keras_utils.get_source_inputs(input_tensor) + """ Modified to solve following error: + module 'keras.utils' has no attribute 'get_source_inputs' + """ + # inputs = keras_utils.get_source_inputs(input_tensor) + inputs = get_source_inputs(input_tensor) else: inputs = img_input diff --git a/classification_models/weights.py b/classification_models/weights.py index 7322265..d83a903 100644 --- a/classification_models/weights.py +++ b/classification_models/weights.py @@ -1,4 +1,5 @@ from . import get_submodules_from_kwargs +from tensorflow.keras.utils import get_file __all__ = ['load_model_weights'] @@ -22,7 +23,11 @@ def load_model_weights(model, model_name, dataset, classes, include_top, **kwarg raise ValueError('If using `weights` and `include_top`' ' as true, `classes` should be {}'.format(weights['classes'])) - weights_path = keras_utils.get_file( + """ Modified to solve following error: + module 'keras.utils' has no attribute 'get_file' + """ + # weights_path = keras_utils.get_file( + weights_path = get_file( weights['name'], weights['url'], cache_subdir='models',