本文整理汇总了Python中keras.__version__方法的典型用法代码示例。如果您正苦于以下问题:Python keras.__version__方法的具体用法?Python keras.__version__怎么用?Python keras.__version__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras
的用法示例。
在下文中一共展示了keras.__version__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: collect_environment
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def collect_environment(self, overwrite_variables=None):
import socket
import os
import pip
import platform
env = {}
if not overwrite_variables:
overwrite_variables = {}
import aetros
env['aetros_version'] = aetros.__version__
env['python_version'] = platform.python_version()
env['python_executable'] = sys.executable
env['hostname'] = socket.gethostname()
env['variables'] = dict(os.environ)
env['variables'].update(overwrite_variables)
if 'AETROS_SSH_KEY' in env['variables']: del env['variables']['AETROS_SSH_KEY']
if 'AETROS_SSH_KEY_BASE64' in env['variables']: del env['variables']['AETROS_SSH_KEY_BASE64']
env['pip_packages'] = sorted([[i.key, i.version] for i in pip.get_installed_distributions()])
self.set_system_info('environment', env)
示例2: _get_decoder_initial_states
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def _get_decoder_initial_states(self):
"""
Return decoder states as Input layers
"""
decoder_states_inputs = []
for units in self.encoder_layers:
decoder_state_input_h = Input(shape=(units,))
input_states = [decoder_state_input_h]
if self.cell == LSTMCell:
decoder_state_input_c = Input(shape=(units,))
input_states = [decoder_state_input_h, decoder_state_input_c]
decoder_states_inputs.extend(input_states)
if keras.__version__ < '2.2':
return list(reversed(decoder_states_inputs))
else:
return decoder_states_inputs
示例3: __init__
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def __init__(self, params):
super(NeuralNetworkAlgorithm, self).__init__(params)
self.library_version = keras.__version__
self.rounds = additional.get("one_step", 1)
self.max_iters = additional.get("max_steps", 1)
self.learner_params = {
"dense_layers": params.get("dense_layers"),
"dense_1_size": params.get("dense_1_size"),
"dense_2_size": params.get("dense_2_size"),
"dropout": params.get("dropout"),
"learning_rate": params.get("learning_rate"),
"momentum": params.get("momentum"),
"decay": params.get("decay"),
}
self.model = None # we need input data shape to construct model
if "model_architecture_json" in params:
self.model = model_from_json(
json.loads(params.get("model_architecture_json"))
)
self.compile_model()
logger.debug("NeuralNetworkAlgorithm __init__")
示例4: _load_model
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def _load_model(model_path, keras_module, **kwargs):
keras_models = importlib.import_module(keras_module.__name__ + ".models")
custom_objects = kwargs.pop("custom_objects", {})
custom_objects_path = None
if os.path.isdir(model_path):
if os.path.isfile(os.path.join(model_path, _CUSTOM_OBJECTS_SAVE_PATH)):
custom_objects_path = os.path.join(model_path, _CUSTOM_OBJECTS_SAVE_PATH)
model_path = os.path.join(model_path, _MODEL_SAVE_PATH)
if custom_objects_path is not None:
import cloudpickle
with open(custom_objects_path, "rb") as in_f:
pickled_custom_objects = cloudpickle.load(in_f)
pickled_custom_objects.update(custom_objects)
custom_objects = pickled_custom_objects
from distutils.version import StrictVersion
if StrictVersion(keras_module.__version__.split('-')[0]) >= StrictVersion("2.2.3"):
# NOTE: Keras 2.2.3 does not work with unicode paths in python2. Pass in h5py.File instead
# of string to avoid issues.
import h5py
with h5py.File(os.path.abspath(model_path), "r") as model_path:
return keras_models.load_model(model_path, custom_objects=custom_objects, **kwargs)
else:
# NOTE: Older versions of Keras only handle filepath.
return keras_models.load_model(model_path, custom_objects=custom_objects, **kwargs)
示例5: log_model
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def log_model(keras_model, artifact_path, image_dims, domain):
"""
Log a KerasImageClassifierPyfunc model as an MLflow artifact for the current run.
:param keras_model: Keras model to be saved.
:param artifact_path: Run-relative artifact path this model is to be saved to.
:param image_dims: Image dimensions the Keras model expects.
:param domain: Labels for the classes this model can predict.
"""
with TempDir() as tmp:
data_path = tmp.path("image_model")
os.mkdir(data_path)
conf = {
"image_dims": "/".join(map(str, image_dims)),
"domain": "/".join(map(str, domain))
}
with open(os.path.join(data_path, "conf.yaml"), "w") as f:
yaml.safe_dump(conf, stream=f)
keras_path = os.path.join(data_path, "keras_model")
mlflow.keras.save_model(keras_model, path=keras_path)
conda_env = tmp.path("conda_env.yaml")
with open(conda_env, "w") as f:
f.write(conda_env_template.format(python_version=PYTHON_VERSION,
keras_version=keras.__version__,
tf_name=tf.__name__, # can have optional -gpu suffix
tf_version=tf.__version__,
pillow_version=PIL.__version__))
mlflow.pyfunc.log_model(artifact_path=artifact_path,
loader_module=__name__,
code_path=[__file__],
data_path=data_path,
conda_env=conda_env)
示例6: version
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def version():
import tensorflow # pylint: disable=E0401
tensorflow.logging.set_verbosity(tensorflow.logging.ERROR)
return tensorflow.__version__ #pylint: disable=E1101
示例7: conv_2d
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def conv_2d(filters, kernel_shape, strides, padding, input_shape=None):
"""
Defines the right convolutional layer according to the
version of Keras that is installed.
:param filters: (required integer) the dimensionality of the output
space (i.e. the number output of filters in the
convolution)
:param kernel_shape: (required tuple or list of 2 integers) specifies
the strides of the convolution along the width and
height.
:param padding: (required string) can be either 'valid' (no padding around
input or feature map) or 'same' (pad to ensure that the
output feature map size is identical to the layer input)
:param input_shape: (optional) give input shape if this is the first
layer of the model
:return: the Keras layer
"""
if LooseVersion(keras.__version__) >= LooseVersion('2.0.0'):
if input_shape is not None:
return Conv2D(filters=filters, kernel_size=kernel_shape,
strides=strides, padding=padding,
input_shape=input_shape)
else:
return Conv2D(filters=filters, kernel_size=kernel_shape,
strides=strides, padding=padding)
else:
if input_shape is not None:
return Convolution2D(filters, kernel_shape[0], kernel_shape[1],
subsample=strides, border_mode=padding,
input_shape=input_shape)
else:
return Convolution2D(filters, kernel_shape[0], kernel_shape[1],
subsample=strides, border_mode=padding)
示例8: save_model
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def save_model(model, filepath, overwrite=True):
def get_json_type(obj):
if hasattr(obj, 'get_config'):
return {'class_name': obj.__class__.__name__,
'config': obj.get_config()}
if type(obj).__module__ == np.__name__:
return obj.item()
if callable(obj) or type(obj).__name__ == type.__name__:
return obj.__name__
raise TypeError('Not JSON Serializable:', obj)
import h5py
from keras import __version__ as keras_version
if not overwrite and os.path.isfile(filepath):
proceed = keras.models.ask_to_proceed_with_overwrite(filepath)
if not proceed:
return
f = h5py.File(filepath, 'w')
f.attrs['keras_version'] = str(keras_version).encode('utf8')
f.attrs['generator_config'] = json.dumps({
'class_name': model.discriminator.__class__.__name__,
'config': model.generator.get_config(),
}, default=get_json_type).encode('utf8')
f.attrs['discriminator_config'] = json.dumps({
'class_name': model.discriminator.__class__.__name__,
'config': model.discriminator.get_config(),
}, default=get_json_type).encode('utf8')
generator_weights_group = f.create_group('generator_weights')
discriminator_weights_group = f.create_group('discriminator_weights')
model.generator.save_weights_to_hdf5_group(generator_weights_group)
model.discriminator.save_weights_to_hdf5_group(discriminator_weights_group)
f.flush()
f.close()
示例9: upload_keras_graph
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def upload_keras_graph(self, model):
from aetros.keras import model_to_graph
import keras
if keras.__version__[0] == '2':
graph = model_to_graph(model)
self.set_graph(graph)
示例10: set_generator_validation_nb
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def set_generator_validation_nb(self, number):
"""
sets self.nb_val_samples which is used in model.fit if input is a generator
:param number:
:return:
"""
self.nb_val_samples = number
diff_to_batch = number % self.get_batch_size()
if diff_to_batch > 0:
self.nb_val_samples += self.get_batch_size() - diff_to_batch
import keras
if '1' != keras.__version__[0]:
self.nb_val_samples = self.nb_val_samples // self.get_batch_size()
示例11: conv_2d
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def conv_2d(filters, kernel_shape, strides, padding, input_shape=None):
"""
Defines the right convolutional layer according to the
version of Keras that is installed.
:param filters: (required integer) the dimensionality of the output
space (i.e. the number output of filters in the
convolution)
:param kernel_shape: (required tuple or list of 2 integers) specifies
the strides of the convolution along the width and
height.
:param padding: (required string) can be either 'valid' (no padding around
input or feature map) or 'same' (pad to ensure that the
output feature map size is identical to the layer input)
:param input_shape: (optional) give input shape if this is the first
layer of the model
:return: the Keras layer
"""
if LooseVersion(keras.__version__) >= LooseVersion('2.0.0'):
print "Using Keras version", keras.__version__
if input_shape is not None:
return Conv2D(filters=filters, kernel_size=kernel_shape,
strides=strides, padding=padding,
input_shape=input_shape)
else:
return Conv2D(filters=filters, kernel_size=kernel_shape,
strides=strides, padding=padding)
else:
print "Using *old* keras version", keras.__version__
if input_shape is not None:
return Convolution2D(filters, kernel_shape[0], kernel_shape[1],
subsample=strides, border_mode=padding,
input_shape=input_shape)
else:
return Convolution2D(filters, kernel_shape[0], kernel_shape[1],
subsample=strides, border_mode=padding)
示例12: keras_version
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def keras_version():
return tuple(map(int, keras.__version__.split('.')))
示例13: assert_keras_version
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def assert_keras_version():
detected = keras.__version__
required = '.'.join(map(str, minimum_keras_version))
assert(keras_version() >= minimum_keras_version), 'You are using keras version {}. The minimum required version is {}.'.format(detected, required)
示例14: keras_version
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def keras_version():
""" Get the Keras version.
Returns
tuple of (major, minor, patch).
"""
return tuple(map(int, keras.__version__.split('.')))
示例15: assert_keras_version
# 需要导入模块: import keras [as 别名]
# 或者: from keras import __version__ [as 别名]
def assert_keras_version():
""" Assert that the Keras version is up to date.
"""
detected = keras.__version__
required = '.'.join(map(str, minimum_keras_version))
assert(keras_version() >= minimum_keras_version), 'You are using keras version {}. The minimum required version is {}.'.format(detected, required)