Python tensorflow.python.ops.init_ops.truncated_normal_initializer() Examples
The following are 30
code examples of tensorflow.python.ops.init_ops.truncated_normal_initializer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.python.ops.init_ops
, or try the search function
.
Example #1
Source File: feature_column.py From keras-lambda with MIT License | 6 votes |
def __new__(cls, column_name, size, dimension, hash_key, combiner="sqrtn", initializer=None): if initializer is not None and not callable(initializer): raise ValueError("initializer must be callable if specified. " "column_name: {}".format(column_name)) if initializer is None: stddev = 0.1 # TODO(b/25671353): Better initial value? initializer = init_ops.truncated_normal_initializer( mean=0.0, stddev=stddev) return super(_ScatteredEmbeddingColumn, cls).__new__(cls, column_name, size, dimension, hash_key, combiner, initializer)
Example #2
Source File: loss_ops_test.py From tf-slim with Apache License 2.0 | 6 votes |
def testGradientWithZeroWeight(self): with ops.Graph().as_default(): random_seed.set_random_seed(0) inputs = array_ops.ones((2, 3)) weights = variable_scope.get_variable( 'weights', shape=[3, 4], initializer=init_ops.truncated_normal_initializer()) predictions = math_ops.matmul(inputs, weights) optimizer = momentum_lib.MomentumOptimizer( learning_rate=0.001, momentum=0.9) loss = loss_ops.mean_pairwise_squared_error(predictions, predictions, 0) gradients_to_variables = optimizer.compute_gradients(loss) init_op = variables.global_variables_initializer() with self.cached_session() as sess: sess.run(init_op) for grad, _ in gradients_to_variables: np_grad = sess.run(grad) self.assertFalse(np.isnan(np_grad).any())
Example #3
Source File: variables_test.py From tf-slim with Apache License 2.0 | 6 votes |
def testNoScopes(self): init_value0 = np.asarray([1.0, 3.0, 9.0]).reshape((1, 3, 1)) init_value1 = np.asarray([2.0, 4.0, 6.0, 8.0]).reshape((2, 1, 2)) with self.cached_session() as sess: initializer = init_ops.truncated_normal_initializer(stddev=.1) var0 = variables_lib2.variable( 'my_var0', shape=[1, 3, 1], initializer=initializer) var1 = variables_lib2.variable( 'my_var1', shape=[2, 1, 2], initializer=initializer) var_names_to_values = {'my_var0': init_value0, 'my_var1': init_value1} init_fn = variables_lib2.assign_from_values_fn(var_names_to_values) # Initialize the variables. sess.run(variables_lib.global_variables_initializer()) # Perform the assignment. init_fn(sess) # Request and test the variable values: var0, var1 = sess.run([var0, var1]) self.assertAllEqual(init_value0, var0) self.assertAllEqual(init_value1, var1)
Example #4
Source File: feature_column.py From lambda-packs with MIT License | 6 votes |
def __new__(cls, column_name, size, dimension, hash_key, combiner="sqrtn", initializer=None): if initializer is not None and not callable(initializer): raise ValueError("initializer must be callable if specified. " "column_name: {}".format(column_name)) if initializer is None: logging.warn("The default stddev value of initializer will change from " "\"0.1\" to \"1/sqrt(dimension)\" after 2017/02/25.") stddev = 0.1 initializer = init_ops.truncated_normal_initializer( mean=0.0, stddev=stddev) return super(_ScatteredEmbeddingColumn, cls).__new__(cls, column_name, size, dimension, hash_key, combiner, initializer)
Example #5
Source File: variables_test.py From tf-slim with Apache License 2.0 | 6 votes |
def testNoScopes(self): init_value0 = np.asarray([1.0, 3.0, 9.0]).reshape((1, 3, 1)) init_value1 = np.asarray([2.0, 4.0, 6.0, 8.0]).reshape((2, 1, 2)) with self.cached_session() as sess: initializer = init_ops.truncated_normal_initializer(stddev=.1) var0 = variables_lib2.variable( 'my_var0', shape=[1, 3, 1], initializer=initializer) var1 = variables_lib2.variable( 'my_var1', shape=[2, 1, 2], initializer=initializer) var_names_to_values = {'my_var0': init_value0, 'my_var1': init_value1} assign_op, feed_dict = variables_lib2.assign_from_values( var_names_to_values) # Initialize the variables. sess.run(variables_lib.global_variables_initializer()) # Perform the assignment. sess.run(assign_op, feed_dict) # Request and test the variable values: var0, var1 = sess.run([var0, var1]) self.assertAllEqual(init_value0, var0) self.assertAllEqual(init_value1, var1)
Example #6
Source File: feature_column.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def __new__(cls, column_name, size, dimension, hash_key, combiner="sqrtn", initializer=None): if initializer is not None and not callable(initializer): raise ValueError("initializer must be callable if specified. " "column_name: {}".format(column_name)) if initializer is None: stddev = 0.1 # TODO(b/25671353): Better initial value? initializer = init_ops.truncated_normal_initializer( mean=0.0, stddev=stddev) return super(_ScatteredEmbeddingColumn, cls).__new__(cls, column_name, size, dimension, hash_key, combiner, initializer)
Example #7
Source File: feature_column.py From deep_image_model with Apache License 2.0 | 6 votes |
def __new__(cls, column_name, size, dimension, combiner="sqrtn", initializer=None): if initializer is not None and not callable(initializer): raise ValueError("initializer must be callable if specified. " "column_name: {}".format(column_name)) if initializer is None: stddev = 0.1 # TODO(b/25671353): Better initial value? initializer = init_ops.truncated_normal_initializer( mean=0.0, stddev=stddev) return super(_HashedEmbeddingColumn, cls).__new__(cls, column_name, size, dimension, combiner, initializer)
Example #8
Source File: decisions_to_data.py From deep_image_model with Apache License 2.0 | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner.get_device(self.layer_num)): self.tree_parameters = variable_scope.get_variable( name='tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features_per_node], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #9
Source File: decisions_to_data.py From deep_image_model with Apache License 2.0 | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner.get_device(self.layer_num)): self.tree_parameters = variable_scope.get_variable( name='hard_tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features], initializer=variable_scope.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='hard_tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=variable_scope.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #10
Source File: decisions_to_data.py From deep_image_model with Apache License 2.0 | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner.get_device(self.layer_num)): self.tree_parameters = variable_scope.get_variable( name='stochastic_hard_tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='stochastic_hard_tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #11
Source File: decisions_to_data.py From deep_image_model with Apache License 2.0 | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner.get_device(self.layer_num)): self.tree_parameters = variable_scope.get_variable( name='stochastic_soft_tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='stochastic_soft_tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #12
Source File: feature_column.py From deep_image_model with Apache License 2.0 | 5 votes |
def embedding_column(sparse_id_column, dimension, combiner=None, initializer=None, ckpt_to_load_from=None, tensor_name_in_ckpt=None): """Creates an `_EmbeddingColumn`. Args: sparse_id_column: A `_SparseColumn` which is created by for example `sparse_column_with_*` or crossed_column functions. Note that `combiner` defined in `sparse_id_column` is ignored. dimension: An integer specifying dimension of the embedding. combiner: A string specifying how to reduce if there are multiple entries in a single row. Currently "mean", "sqrtn" and "sum" are supported. Each of this can be considered an example level normalization on the column: * "sum": do not normalize * "mean": do l1 normalization * "sqrtn": do l2 normalization For more information: `tf.embedding_lookup_sparse`. initializer: A variable initializer function to be used in embedding variable initialization. If not specified, defaults to `tf.truncated_normal_initializer` with mean 0.0 and standard deviation 1/sqrt(sparse_id_column.length). ckpt_to_load_from: (Optional). String representing checkpoint name/pattern to restore the column weights. Required if `tensor_name_in_ckpt` is not None. tensor_name_in_ckpt: (Optional). Name of the `Tensor` in the provided checkpoint from which to restore the column weights. Required if `ckpt_to_load_from` is not None. Returns: An `_EmbeddingColumn`. """ if combiner is None: logging.warn("The default value of combiner will change from \"mean\" " "to \"sqrtn\" after 2016/11/01.") combiner = "mean" return _EmbeddingColumn(sparse_id_column, dimension, combiner, initializer, ckpt_to_load_from, tensor_name_in_ckpt)
Example #13
Source File: rnn_ops.py From video_prediction with MIT License | 5 votes |
def _conv2d(self, inputs): output_filters = 4 * self._filters input_shape = inputs.get_shape().as_list() kernel_shape = list(self._kernel_size) + [input_shape[-1], output_filters] kernel = vs.get_variable("kernel", kernel_shape, dtype=dtypes.float32, initializer=init_ops.truncated_normal_initializer(stddev=0.02)) outputs = nn_ops.conv2d(inputs, kernel, [1] * 4, padding='SAME') if not self._normalizer_fn: bias = vs.get_variable('bias', [output_filters], dtype=dtypes.float32, initializer=init_ops.zeros_initializer()) outputs = nn_ops.bias_add(outputs, bias) return outputs
Example #14
Source File: rnn_ops.py From video_prediction with MIT License | 5 votes |
def _dense(self, inputs): num_units = 4 * self._filters input_shape = inputs.shape.as_list() kernel_shape = [input_shape[-1], num_units] kernel = vs.get_variable("weights", kernel_shape, dtype=dtypes.float32, initializer=init_ops.truncated_normal_initializer(stddev=0.02)) outputs = tf.matmul(inputs, kernel) return outputs
Example #15
Source File: rnn_ops.py From video_prediction with MIT License | 5 votes |
def _conv2d(self, inputs, output_filters, bias_initializer): input_shape = inputs.get_shape().as_list() kernel_shape = list(self._kernel_size) + [input_shape[-1], output_filters] kernel = vs.get_variable("kernel", kernel_shape, dtype=dtypes.float32, initializer=init_ops.truncated_normal_initializer(stddev=0.02)) outputs = nn_ops.conv2d(inputs, kernel, [1] * 4, padding='SAME') if not self._normalizer_fn: bias = vs.get_variable('bias', [output_filters], dtype=dtypes.float32, initializer=bias_initializer) outputs = nn_ops.bias_add(outputs, bias) return outputs
Example #16
Source File: rnn_ops.py From video_prediction with MIT License | 5 votes |
def _dense(self, inputs, num_units): input_shape = inputs.shape.as_list() kernel_shape = [input_shape[-1], num_units] kernel = vs.get_variable("weights", kernel_shape, dtype=dtypes.float32, initializer=init_ops.truncated_normal_initializer(stddev=0.02)) outputs = tf.matmul(inputs, kernel) return outputs
Example #17
Source File: ConvLSTMCell.py From ConvLSTMCell-tensorflow with MIT License | 5 votes |
def _conv(args, output_size, filter_size, stddev=0.001, bias=True, bias_start=0.0, scope=None): if args is None or (nest.is_sequence(args) and not args): raise ValueError("`args` must be specified") if not nest.is_sequence(args): args = [args] # Calculate the total size of arguments on dimension 3. # (batch_size x height x width x arg_size) total_arg_size = 0 shapes = [a.get_shape().as_list() for a in args] height = shapes[0][1] width = shapes[0][2] for shape in shapes: if len(shape) != 4: raise ValueError("Conv is expecting 3D arguments: %s" % str(shapes)) if not shape[3]: raise ValueError("Conv expects shape[3] of arguments: %s" % str(shapes)) if shape[1] == height and shape[2] == width: total_arg_size += shape[3] else : raise ValueError("Inconsistent height and width size in arguments: %s" % str(shapes)) with vs.variable_scope(scope or "Conv"): kernel = vs.get_variable("Kernel", [filter_size[0], filter_size[1], total_arg_size, output_size], initializer=init_ops.truncated_normal_initializer(stddev=stddev)) if len(args) == 1: res = tf.nn.conv2d(args[0], kernel, [1, 1, 1, 1], padding='SAME') else: res = tf.nn.conv2d(array_ops.concat(3, args), kernel, [1, 1, 1, 1], padding='SAME') if not bias: return res bias_term = vs.get_variable( "Bias", [output_size], initializer=init_ops.constant_initializer(bias_start)) return res + bias_term
Example #18
Source File: decisions_to_data.py From keras-lambda with MIT License | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner.get_device(self.layer_num)): self.tree_parameters = variable_scope.get_variable( name='tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #19
Source File: decisions_to_data.py From keras-lambda with MIT License | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner.get_device(self.layer_num)): self.tree_parameters = variable_scope.get_variable( name='tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features_per_node], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #20
Source File: decisions_to_data.py From keras-lambda with MIT License | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner.get_device(self.layer_num)): self.tree_parameters = variable_scope.get_variable( name='hard_tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features], initializer=variable_scope.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='hard_tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=variable_scope.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #21
Source File: decisions_to_data.py From keras-lambda with MIT License | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner.get_device(self.layer_num)): self.tree_parameters = variable_scope.get_variable( name='stochastic_hard_tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='stochastic_hard_tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #22
Source File: feature_column.py From keras-lambda with MIT License | 5 votes |
def __new__(cls, sparse_id_column, dimension, combiner="sqrtn", initializer=None, ckpt_to_load_from=None, tensor_name_in_ckpt=None, shared_embedding_name=None, shared_vocab_size=None, max_norm=None): if initializer is not None and not callable(initializer): raise ValueError("initializer must be callable if specified. " "Embedding of column_name: {}".format( sparse_id_column.name)) if (ckpt_to_load_from is None) != (tensor_name_in_ckpt is None): raise ValueError("Must specify both `ckpt_to_load_from` and " "`tensor_name_in_ckpt` or none of them.") if initializer is None: stddev = 1 / math.sqrt(sparse_id_column.length) # TODO(b/25671353): Better initial value? initializer = init_ops.truncated_normal_initializer( mean=0.0, stddev=stddev) return super(_EmbeddingColumn, cls).__new__(cls, sparse_id_column, dimension, combiner, initializer, ckpt_to_load_from, tensor_name_in_ckpt, shared_embedding_name, shared_vocab_size, max_norm)
Example #23
Source File: decisions_to_data.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner.get_device(self.layer_num)): self.tree_parameters = variable_scope.get_variable( name='hard_tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features], initializer=variable_scope.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='hard_tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=variable_scope.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #24
Source File: decisions_to_data.py From lambda-packs with MIT License | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner): self.tree_parameters = variable_scope.get_variable( name='tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #25
Source File: decisions_to_data.py From lambda-packs with MIT License | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner): self.tree_parameters = variable_scope.get_variable( name='tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features_per_node], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #26
Source File: decisions_to_data.py From lambda-packs with MIT License | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner): self.tree_parameters = variable_scope.get_variable( name='hard_tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features], initializer=variable_scope.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='hard_tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=variable_scope.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #27
Source File: decisions_to_data.py From lambda-packs with MIT License | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner): self.tree_parameters = variable_scope.get_variable( name='stochastic_hard_tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='stochastic_hard_tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #28
Source File: feature_column.py From lambda-packs with MIT License | 5 votes |
def __new__(cls, sparse_id_column, dimension, combiner="mean", initializer=None, ckpt_to_load_from=None, tensor_name_in_ckpt=None, shared_embedding_name=None, shared_vocab_size=None, max_norm=None, trainable=True): if initializer is not None and not callable(initializer): raise ValueError("initializer must be callable if specified. " "Embedding of column_name: {}".format( sparse_id_column.name)) if (ckpt_to_load_from is None) != (tensor_name_in_ckpt is None): raise ValueError("Must specify both `ckpt_to_load_from` and " "`tensor_name_in_ckpt` or none of them.") if initializer is None: logging.warn("The default stddev value of initializer will change from " "\"1/sqrt(vocab_size)\" to \"1/sqrt(dimension)\" after " "2017/02/25.") stddev = 1 / math.sqrt(sparse_id_column.length) initializer = init_ops.truncated_normal_initializer( mean=0.0, stddev=stddev) return super(_EmbeddingColumn, cls).__new__(cls, sparse_id_column, dimension, combiner, initializer, ckpt_to_load_from, tensor_name_in_ckpt, shared_embedding_name, shared_vocab_size, max_norm, trainable)
Example #29
Source File: decisions_to_data.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner.get_device(self.layer_num)): self.tree_parameters = variable_scope.get_variable( name='tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))
Example #30
Source File: decisions_to_data.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _define_vars(self, params, **kwargs): with ops.device(self.device_assigner.get_device(self.layer_num)): self.tree_parameters = variable_scope.get_variable( name='tree_parameters_%d' % self.layer_num, shape=[params.num_nodes, params.num_features_per_node], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std)) self.tree_thresholds = variable_scope.get_variable( name='tree_thresholds_%d' % self.layer_num, shape=[params.num_nodes], initializer=init_ops.truncated_normal_initializer( mean=params.weight_init_mean, stddev=params.weight_init_std))