def save_tf_keras_optimizer(optimizer, h5py_file):
    if isinstance(optimizer, optimizers.TFOptimizer):
        logging.warning('TensorFlow optimizers do not make it possible to access optimizer attributes or optimizer state after instantiation. As a result, we cannot save the optimizer as part of the model save file.You will have to compile your model again after loading it. Prefer using a Keras optimizer instead (see keras.io/optimizers).')
    else:
        h5py_file.attrs['training_config'] = json.dumps({'optimizer_config': {'class_name': optimizer.__class__.__name__, 'config': optimizer.get_config()}}, default=serialization.get_json_type).encode('utf8')
        symbolic_weights = getattr(optimizer, 'weights')
        if symbolic_weights:
            optimizer_weights_group = h5py_file.create_group('optimizer_weights')
            weight_values = K.batch_get_value(symbolic_weights)
            weight_names = []
            for (w, val) in zip(symbolic_weights, weight_values):
                name = str(w.name)
                weight_names.append(name.encode('utf8'))
            optimizer_weights_group.attrs['weight_names'] = weight_names
            for (name, val) in zip(weight_names, weight_values):
                param_dset = optimizer_weights_group.create_dataset(name, val.shape, dtype=val.dtype)
                if (not val.shape):
                    param_dset[()] = val
                else:
                    param_dset[:] = val
    h5py_file.flush()
def save_tf_keras_optimizer(optimizer, h5py_file):
    if isinstance(optimizer, optimizers.TFOptimizer):
        logging.warning('TensorFlow optimizers do not make it possible to access optimizer attributes or optimizer state after instantiation. As a result, we cannot save the optimizer as part of the model save file.You will have to compile your model again after loading it. Prefer using a Keras optimizer instead (see keras.io/optimizers).')
    else:
        h5py_file.attrs['training_config'] = json.dumps({'optimizer_config': {'class_name': optimizer.__class__.__name__, 'config': optimizer.get_config()}}, default=serialization.get_json_type).encode('utf8')
        symbolic_weights = getattr(optimizer, 'weights')
        if symbolic_weights:
            optimizer_weights_group = h5py_file.create_group('optimizer_weights')
            weight_values = K.batch_get_value(symbolic_weights)
            weight_names = []
            for (w, val) in zip(symbolic_weights, weight_values):
                name = str(w.name)
                weight_names.append(name.encode('utf8'))
            optimizer_weights_group.attrs['weight_names'] = weight_names
            for (name, val) in zip(weight_names, weight_values):
                param_dset = optimizer_weights_group.create_dataset(name, val.shape, dtype=val.dtype)
                if (not val.shape):
                    param_dset[()] = val
                else:
                    param_dset[:] = val
    h5py_file.flush()