python variables_Python variables.PartitionedVariable方法代码示例
本文整理汇总了Python中tensorflow.python.ops.variables.PartitionedVariable方法的典型用法代码示例。如果您正苦于以下问题:Python variables.PartitionedVariable方法的具体用法?Python variables.PartitionedVariable怎么用?Python variables.PartitionedVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块tensorflow.python.ops.variables的用法示例。
在下文中一共展示了variables.PartitionedVariable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testPartitionedVariable
点赞 6
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def testPartitionedVariable(self):
with tf.Graph().as_default():
v0 = tf.Variable([0])
v1 = tf.Variable([1])
v0._set_save_slice_info(variables.Variable.SaveSliceInfo(
v0.name, [2], [0], [1]))
v1._set_save_slice_info(variables.Variable.SaveSliceInfo(
v0.name, [2], [1], [1]))
partitions = [2]
# Pass variable_list as [v1, v0] to ensure they are properly
# re-sorted to [v0, v1] based on their slice info offsets.
partitioned_variable = variables.PartitionedVariable(
name="two_vars",
shape=[2],
dtype=v0.dtype,
variable_list=[v1, v0],
partitions=partitions)
concatenated = tf.convert_to_tensor(partitioned_variable)
num_partitions = len(partitioned_variable)
iterated_partitions = list(partitioned_variable)
self.assertEqual(2, num_partitions)
self.assertEqual([v0, v1], iterated_partitions)
self.assertEqual([2], concatenated.get_shape())
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,
示例2: _add_variable_to_collections
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def _add_variable_to_collections(variable, collections_set, collections_name):
"""Adds variable (or all its parts) to all collections with that name."""
collections = utils.get_variable_collections(collections_set,
collections_name) or []
variables_list = [variable]
if isinstance(variable, tf_variables.PartitionedVariable):
variables_list = [v for v in variable]
for collection in collections:
for var in variables_list:
if var not in ops.get_collection(collection):
ops.add_to_collection(collection, var)
开发者ID:taehoonlee,项目名称:tensornets,代码行数:13,
示例3: _rnn_get_variable
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def _rnn_get_variable(self, getter, *args, **kwargs):
variable = getter(*args, **kwargs)
trainable = (variable in tf_variables.trainable_variables() or
(isinstance(variable, tf_variables.PartitionedVariable) and
list(variable)[0] in tf_variables.trainable_variables()))
if trainable and variable not in self._trainable_weights:
self._trainable_weights.append(variable)
elif not trainable and variable not in self._non_trainable_weights:
self._non_trainable_weights.append(variable)
return variable
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:12,
示例4: _get_dense_tensor
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def _get_dense_tensor(self, inputs, weight_collections=None, trainable=None):
# Get sparse IDs and weights.
sparse_tensors = self.categorical_column._get_sparse_tensors( # pylint: disable=protected-access
inputs, weight_collections=weight_collections, trainable=trainable)
sparse_ids = sparse_tensors.id_tensor
sparse_weights = sparse_tensors.weight_tensor
# Create embedding weight, and restore from checkpoint if necessary.
embedding_weights = variable_scope.get_variable(
name='embedding_weights',
shape=(self.categorical_column._num_buckets, self.dimension), # pylint: disable=protected-access
dtype=dtypes.float32,
initializer=self.initializer,
trainable=self.trainable and trainable,
collections=weight_collections)
if self.ckpt_to_load_from is not None:
to_restore = embedding_weights
if isinstance(to_restore, variables.PartitionedVariable):
to_restore = to_restore._get_variable_list() # pylint: disable=protected-access
checkpoint_utils.init_from_checkpoint(self.ckpt_to_load_from, {
self.tensor_name_in_ckpt: to_restore
})
# Return embedding lookup result.
return _safe_embedding_lookup_sparse(
embedding_weights=embedding_weights,
sparse_ids=sparse_ids,
sparse_weights=sparse_weights,
combiner=self.combiner,
name='%s_weights' % self.name,
max_norm=self.max_norm)
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:33,
示例5: _add_variable_to_collections
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def _add_variable_to_collections(variable, collections_set, collections_name):
"""Adds variable (or all its parts) to all collections with that name."""
collections = utils.get_variable_collections(
collections_set, collections_name) or []
variables_list = [variable]
if isinstance(variable, tf_variables.PartitionedVariable):
variables_list = [v for v in variable]
for collection in collections:
for var in variables_list:
if var not in ops.get_collection(collection):
ops.add_to_collection(collection, var)
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:13,
示例6: embedding_lookup_unique
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def embedding_lookup_unique(params, ids, name=None):
"""Version of embedding_lookup that avoids duplicate lookups.
This can save communication in the case of repeated ids.
Same interface as embedding_lookup. Except it supports multi-dimensional `ids`
which allows to not reshape input/output to fit gather.
Args:
params: A list of tensors with the same shape and type, or a
`PartitionedVariable`. Shape `[index, d1, d2, ...]`.
ids: A one-dimensional `Tensor` with type `int32` or `int64` containing
the ids to be looked up in `params`. Shape `[ids1, ids2, ...]`.
name: A name for this operation (optional).
Returns:
A `Tensor` with the same type as the tensors in `params` and dimension of
`[ids1, ids2, d1, d2, ...]`.
Raises:
ValueError: If `params` is empty.
"""
with ops.name_scope(name, "EmbeddingLookupUnique", [params, ids]):
ids = ops.convert_to_tensor(ids)
shape = array_ops.shape(ids)
ids_flat = array_ops.reshape(
ids, math_ops.reduce_prod(shape, keep_dims=True))
unique_ids, idx = array_ops.unique(ids_flat)
unique_embeddings = embedding_ops.embedding_lookup(params, unique_ids)
embeds_flat = array_ops.gather(unique_embeddings, idx)
embed_shape = array_ops.concat(
[shape, array_ops.shape(unique_embeddings)[1:]], 0)
embeds = array_ops.reshape(embeds_flat, embed_shape)
embeds.set_shape(ids.get_shape().concatenate(
unique_embeddings.get_shape()[1:]))
return embeds
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:37,
示例7: embedding_lookup_unique
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def embedding_lookup_unique(params, ids, name=None):
"""Version of embedding_lookup that avoids duplicate lookups.
This can save communication in the case of repeated ids.
Same interface as embedding_lookup. Except it supports multi-dimensional `ids`
which allows to not reshape input/output to fit gather.
Args:
params: A list of tensors with the same shape and type, or a
`PartitionedVariable`. Shape `[index, d1, d2, ...]`.
ids: A one-dimensional `Tensor` with type `int32` or `int64` containing
the ids to be looked up in `params`. Shape `[ids1, ids2, ...]`.
name: A name for this operation (optional).
Returns:
A `Tensor` with the same type as the tensors in `params` and dimension of
`[ids1, ids2, d1, d2, ...]`.
Raises:
ValueError: If `params` is empty.
"""
with ops.name_scope(name, "EmbeddingLookupUnique", [params, ids]):
ids = ops.convert_to_tensor(ids)
shape = array_ops.shape(ids)
ids_flat = array_ops.reshape(
ids, math_ops.reduce_prod(shape, keep_dims=True))
unique_ids, idx = array_ops.unique(ids_flat)
unique_embeddings = embedding_ops.embedding_lookup(params, unique_ids)
embeds_flat = array_ops.gather(unique_embeddings, idx)
embed_shape = array_ops.concat(
0, [shape, array_ops.shape(unique_embeddings)[1:]])
embeds = array_ops.reshape(embeds_flat, embed_shape)
embeds.set_shape(ids.get_shape().concatenate(
unique_embeddings.get_shape()[1:]))
return embeds
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:37,
示例8: _add_variable_to_collections
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def _add_variable_to_collections(variable, collections_set, collections_name):
"""Adds variable (or all its parts) to all collections with that name."""
collections = utils.get_variable_collections(
collections_set, collections_name) or []
variables_list = [variable]
if isinstance(variable, tf_variables.PartitionedVariable):
variables_list = [v for v in variable]
for collection in collections:
for var in variables_list:
if var not in ops.get_collection(collection):
ops.add_to_collection(collection, var)
开发者ID:balancap,项目名称:tf-imagenet,代码行数:13,
示例9: _add_variable_to_collections
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def _add_variable_to_collections(variable, collections_set, collections_name):
"""Adds variable (or all its parts) to all collections with that name."""
collections = utils.get_variable_collections(collections_set,
collections_name) or []
variables_list = [variable]
if isinstance(variable, tf_variables.PartitionedVariable):
variables_list = [v for v in variable]
for collection in collections:
for var in variables_list:
if var not in ops.get_collection(collection):
ops.add_to_collection(collection, var)
开发者ID:hyperconnect,项目名称:MMNet,代码行数:13,
示例10: _rnn_get_variable
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def _rnn_get_variable(self, getter, *args, **kwargs):
variable = getter(*args, **kwargs)
trainable = (variable in tf_variables.trainable_variables() or
(isinstance(variable, tf_variables.PartitionedVariable) and
list(variable)[0] in tf_variables.trainable_variables()))
if trainable and variable not in self._trainable_weights:
self._trainable_weights.append(variable)
elif not trainable and variable not in self._non_trainable_weights:
self._non_trainable_weights.append(variable)
return variable
开发者ID:Trinkle23897,项目名称:Artificial-Neural-Network-THU-2018,代码行数:12,
示例11: begin
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def begin(self):
with tf.compat.v1.variable_scope(
tf.compat.v1.get_variable_scope()) as scope:
scope.reuse_variables()
partitioned_weight = tf.compat.v1.get_variable(
self._var_name, shape=(self._var_dim, 1))
self._test_case.assertTrue(
isinstance(partitioned_weight, variables_lib.PartitionedVariable))
for part in partitioned_weight:
self._test_case.assertEqual(self._var_dim // self._partitions,
part.get_shape()[0])
开发者ID:tensorflow,项目名称:estimator,代码行数:13,
示例12: _create_slots
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def _create_slots(self):
"""Make unshrunk internal variables (slots)."""
# Unshrunk variables have the updates before applying L1 regularization.
# Each unshrunk slot variable is either a `Variable` or list of
# `Variable`, depending on the value of its corresponding primary variable.
# We avoid using `PartitionedVariable` for the unshrunk slots since we do
# not need any of the extra information.
self._slots = collections.defaultdict(list)
for name in ['sparse_features_weights', 'dense_features_weights']:
for var in self._variables[name]:
# Our primary variable may be either a PartitionedVariable, or a list
# of Variables (each representing a partition).
if (isinstance(var, var_ops.PartitionedVariable) or
isinstance(var, list)):
var_list = []
for v in var:
with ops.colocate_with(v):
slot_var = tf.Variable(
initial_value=tf.compat.v1.zeros_like(v.initialized_value(),
tf.dtypes.float32),
name=v.op.name + '_unshrunk')
var_list.append(slot_var)
self._slots['unshrunk_' + name].append(var_list)
else:
with tf.compat.v1.device(var.device):
self._slots['unshrunk_' + name].append(
tf.Variable(
tf.compat.v1.zeros_like(var.initialized_value(),
tf.dtypes.float32),
name=var.op.name + '_unshrunk'))
开发者ID:tensorflow,项目名称:estimator,代码行数:32,
示例13: _var_to_list
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def _var_to_list(self, var):
"""Wraps var in a list if it is not a list or PartitionedVariable."""
if not isinstance(var, (list, var_ops.PartitionedVariable)):
var = [var]
return var
开发者ID:tensorflow,项目名称:estimator,代码行数:7,
示例14: _convert_n_to_tensor
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def _convert_n_to_tensor(self, input_list, as_ref=False):
"""Converts input list to a set of tensors."""
# input_list can be a list of Variables (that are implicitly partitioned),
# in which case the underlying logic in internal_convert_to_tensor will not
# concatenate the partitions together. This method takes care of the
# concatenating (we only allow partitioning on the first axis).
output_list = []
for x in input_list:
tensor_to_convert = x
if isinstance(x, list) or isinstance(x, var_ops.PartitionedVariable):
# We only allow for partitioning on the first axis.
tensor_to_convert = tf.concat(x, axis=0)
output_list.append(
internal_convert_to_tensor(tensor_to_convert, as_ref=as_ref))
return output_list
开发者ID:tensorflow,项目名称:estimator,代码行数:17,
示例15: _rnn_get_variable
点赞 5
# 需要导入模块: from tensorflow.python.ops import variables [as 别名]
# 或者: from tensorflow.python.ops.variables import PartitionedVariable [as 别名]
def _rnn_get_variable(self, getter, *args, **kwargs):
variable = getter(*args, **kwargs)
if context.in_graph_mode():
trainable = (variable in tf_variables.trainable_variables() or
(isinstance(variable, tf_variables.PartitionedVariable) and
list(variable)[0] in tf_variables.trainable_variables()))
else:
trainable = variable._trainable # pylint: disable=protected-access
if trainable and variable not in self._trainable_weights:
self._trainable_weights.append(variable)
elif not trainable and variable not in self._non_trainable_weights:
self._non_trainable_weights.append(variable)
return variable
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:15,
注:本文中的tensorflow.python.ops.variables.PartitionedVariable方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。
python variables_Python variables.PartitionedVariable方法代码示例相关推荐
- python fonttool_Python wx.Font方法代码示例
本文整理汇总了Python中wx.Font方法的典型用法代码示例.如果您正苦于以下问题:Python wx.Font方法的具体用法?Python wx.Font怎么用?Python wx.Font使用 ...
- python dropout_Python slim.dropout方法代码示例
本文整理汇总了Python中tensorflow.contrib.slim.dropout方法的典型用法代码示例.如果您正苦于以下问题:Python slim.dropout方法的具体用法?Pytho ...
- python transformat_Python transforms.Bbox方法代码示例
本文整理汇总了Python中matplotlib.transforms.Bbox方法的典型用法代码示例.如果您正苦于以下问题:Python transforms.Bbox方法的具体用法?Python ...
- python dateformatter_Python dates.DateFormatter方法代码示例
本文整理汇总了Python中matplotlib.dates.DateFormatter方法的典型用法代码示例.如果您正苦于以下问题:Python dates.DateFormatter方法的具体用法 ...
- python paperclip_Python pyplot.sca方法代码示例
本文整理汇总了Python中matplotlib.pyplot.sca方法的典型用法代码示例.如果您正苦于以下问题:Python pyplot.sca方法的具体用法?Python pyplot.sca ...
- python res_Python models.resnet152方法代码示例
本文整理汇总了Python中torchvision.models.resnet152方法的典型用法代码示例.如果您正苦于以下问题:Python models.resnet152方法的具体用法?Pyth ...
- python batch_size_Python config.batch_size方法代码示例
本文整理汇总了Python中config.batch_size方法的典型用法代码示例.如果您正苦于以下问题:Python config.batch_size方法的具体用法?Python config. ...
- python pool_Python pool.Pool方法代码示例
本文整理汇总了Python中multiprocessing.pool.Pool方法的典型用法代码示例.如果您正苦于以下问题:Python pool.Pool方法的具体用法?Python pool.Po ...
- python nextpow2_Python signal.hann方法代码示例
本文整理汇总了Python中scipy.signal.hann方法的典型用法代码示例.如果您正苦于以下问题:Python signal.hann方法的具体用法?Python signal.hann怎么 ...
最新文章
- 3 calender python_python3笔记二十一:时间操作datetime和calendar
- 【不采用】人工智能如何帮助银行反欺诈
- 手撕 CNN 经典网络之 VGGNet(理论篇)
- boost::mp11::mp_eval_if_q相关用法的测试程序
- Netflix:如何通过机器学习提高流媒体质量?
- mysql基础知识点
- html怎么设置数据条的颜色,jQuery EasyUI 数据网格 – 条件设置行背景颜色 | 菜鸟教程...
- Golang slice高级应用
- spark入门及环境搭建
- java day16 【异常、线程】
- zoj2676 Network Wars 0-1分数规划
- F5 LTM ping 数据包丢包解决过程
- 剑指Offer——京东实习笔试题汇总
- WPS删除粘贴后的[]中括号痕迹
- 【转】WebMagic-总体流程源码分析
- 计算机桌面怎么全屏显示,台式电脑桌面两边黑框怎么调全屏 定位到缩放栏目...
- 力扣1046-最后一块石头的重量(原汁原味利用排序,自己写的100% Java题解)
- 临滴LKD2586编译缺少库
- 旁站及C段收集与利用方式
- (图像处理之滤波)OpenCV实现频率域的低通高斯滤波(C++)
热门文章
- 浅谈kruskal重构树
- c++:有武器的角色类
- 我的世界服务器改无限耐久的插件,迷你世界怎么把武器改成无限耐久 | 手游网游页游攻略大全...
- 盈利背后,美团渴望第二曲线
- 金山办公的WPS AI将引入大模型能力(LLM)到表格、文字、演示和PDF四大组件
- 【js】三种获取时间戳的方法
- 发票 发票 Necurs僵尸网络也开假发票 实则传播Locky勒索软件
- 解决 Visual Studio 卸载不完全的问题
- [转帖]一直想整理下游戏中FOV的设置,结果发现网上已经有人整理过了转过来大家看~ 《FPS游戏的摄像机视场(FOV)为何选择65度75度90度?》...
- 用三分钟理解c语言sizeof