Remove tf.keras.utils.convert_all_kernels_in_model
as its deprecation date is overdue.
PiperOrigin-RevId: 331570917 Change-Id: I60183861ac4e04acad041c631c541189a6f9bfe8
This commit is contained in:
parent
499d35942a
commit
627520ec70
@ -30,7 +30,6 @@ from tensorflow.python.keras import optimizers
|
||||
from tensorflow.python.keras.saving import model_config as model_config_lib
|
||||
from tensorflow.python.keras.saving import saving_utils
|
||||
from tensorflow.python.keras.saving.saved_model import json_utils
|
||||
from tensorflow.python.keras.utils import conv_utils
|
||||
from tensorflow.python.keras.utils.generic_utils import LazyLoader
|
||||
from tensorflow.python.keras.utils.io_utils import ask_to_proceed_with_overwrite
|
||||
from tensorflow.python.ops import variables as variables_module
|
||||
@ -402,10 +401,6 @@ def preprocess_weights_for_loading(layer,
|
||||
|
||||
conv_layers = ['Conv1D', 'Conv2D', 'Conv3D', 'Conv2DTranspose', 'ConvLSTM2D']
|
||||
if layer.__class__.__name__ in conv_layers:
|
||||
if original_backend == 'theano':
|
||||
weights[0] = conv_utils.convert_kernel(weights[0])
|
||||
if layer.__class__.__name__ == 'ConvLSTM2D':
|
||||
weights[1] = conv_utils.convert_kernel(weights[1])
|
||||
if K.int_shape(layer.weights[0]) != weights[0].shape:
|
||||
weights[0] = np.transpose(weights[0], (3, 2, 0, 1))
|
||||
if layer.__class__.__name__ == 'ConvLSTM2D':
|
||||
|
@ -35,7 +35,6 @@ from tensorflow.python.keras.utils.generic_utils import get_custom_objects
|
||||
from tensorflow.python.keras.utils.generic_utils import Progbar
|
||||
from tensorflow.python.keras.utils.generic_utils import serialize_keras_object
|
||||
from tensorflow.python.keras.utils.io_utils import HDF5Matrix
|
||||
from tensorflow.python.keras.utils.layer_utils import convert_all_kernels_in_model
|
||||
from tensorflow.python.keras.utils.layer_utils import get_source_inputs
|
||||
from tensorflow.python.keras.utils.multi_gpu_utils import multi_gpu_model
|
||||
from tensorflow.python.keras.utils.np_utils import normalize
|
||||
|
@ -208,31 +208,6 @@ def normalize_padding(value):
|
||||
return padding
|
||||
|
||||
|
||||
def convert_kernel(kernel):
|
||||
"""Converts a Numpy kernel matrix from Theano format to TensorFlow format.
|
||||
|
||||
Also works reciprocally, since the transformation is its own inverse.
|
||||
|
||||
This is used for converting legacy Theano-saved model files.
|
||||
|
||||
Arguments:
|
||||
kernel: Numpy array (3D, 4D or 5D).
|
||||
|
||||
Returns:
|
||||
The converted kernel.
|
||||
|
||||
Raises:
|
||||
ValueError: in case of invalid kernel shape or invalid data_format.
|
||||
"""
|
||||
kernel = np.asarray(kernel)
|
||||
if not 3 <= kernel.ndim <= 5:
|
||||
raise ValueError('Invalid kernel shape:', kernel.shape)
|
||||
slices = [slice(None, None, -1) for _ in range(kernel.ndim)]
|
||||
no_flip = (slice(None, None), slice(None, None))
|
||||
slices[-2:] = no_flip
|
||||
return np.copy(kernel[slices])
|
||||
|
||||
|
||||
def conv_kernel_mask(input_shape, kernel_shape, strides, padding):
|
||||
"""Compute a mask representing the connectivity of a convolution operation.
|
||||
|
||||
|
@ -25,9 +25,6 @@ import weakref
|
||||
import numpy as np
|
||||
import six
|
||||
|
||||
from tensorflow.python.keras import backend as K
|
||||
from tensorflow.python.keras.utils.conv_utils import convert_kernel
|
||||
from tensorflow.python.util import deprecation
|
||||
from tensorflow.python.util import nest
|
||||
from tensorflow.python.util.tf_export import keras_export
|
||||
|
||||
@ -328,37 +325,6 @@ def gather_non_trainable_weights(trainable, sub_layers, extra_variables):
|
||||
return weights + non_trainable_extra_variables
|
||||
|
||||
|
||||
@deprecation.deprecated('2020-06-23',
|
||||
'The Theano kernel format is legacy; '
|
||||
'this utility will be removed.')
|
||||
@keras_export('keras.utils.convert_all_kernels_in_model')
|
||||
def convert_all_kernels_in_model(model):
|
||||
"""Converts all convolution kernels in a model from Theano to TensorFlow.
|
||||
|
||||
Also works from TensorFlow to Theano.
|
||||
|
||||
This is used for converting legacy Theano-saved model files.
|
||||
|
||||
Arguments:
|
||||
model: target model for the conversion.
|
||||
"""
|
||||
# Note: SeparableConvolution not included
|
||||
# since only supported by TF.
|
||||
conv_classes = {
|
||||
'Conv1D',
|
||||
'Conv2D',
|
||||
'Conv3D',
|
||||
'Conv2DTranspose',
|
||||
}
|
||||
to_assign = []
|
||||
for layer in model.layers:
|
||||
if layer.__class__.__name__ in conv_classes:
|
||||
original_kernel = K.get_value(layer.kernel)
|
||||
converted_kernel = convert_kernel(original_kernel)
|
||||
to_assign.append((layer.kernel, converted_kernel))
|
||||
K.batch_set_value(to_assign)
|
||||
|
||||
|
||||
def convert_dense_weights_data_format(dense,
|
||||
previous_feature_map_shape,
|
||||
target_data_format='channels_first'):
|
||||
|
@ -32,10 +32,6 @@ tf_module {
|
||||
name: "custom_object_scope"
|
||||
mtype: "<type \'type\'>"
|
||||
}
|
||||
member_method {
|
||||
name: "convert_all_kernels_in_model"
|
||||
argspec: "args=[\'model\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "deserialize_keras_object"
|
||||
argspec: "args=[\'identifier\', \'module_objects\', \'custom_objects\', \'printable_module_name\'], varargs=None, keywords=None, defaults=[\'None\', \'None\', \'object\'], "
|
||||
|
@ -32,10 +32,6 @@ tf_module {
|
||||
name: "custom_object_scope"
|
||||
mtype: "<type \'type\'>"
|
||||
}
|
||||
member_method {
|
||||
name: "convert_all_kernels_in_model"
|
||||
argspec: "args=[\'model\'], varargs=None, keywords=None, defaults=None"
|
||||
}
|
||||
member_method {
|
||||
name: "deserialize_keras_object"
|
||||
argspec: "args=[\'identifier\', \'module_objects\', \'custom_objects\', \'printable_module_name\'], varargs=None, keywords=None, defaults=[\'None\', \'None\', \'object\'], "
|
||||
|
Loading…
Reference in New Issue
Block a user