本文整理匯總了Python中dragnn.python.component.MasterState方法的典型用法代碼示例。如果您正苦於以下問題:Python component.MasterState方法的具體用法?Python component.MasterState怎麽用?Python component.MasterState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dragnn.python.component
的用法示例。
在下文中一共展示了component.MasterState方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: build_inference
# 需要導入模塊: from dragnn.python import component [as 別名]
# 或者: from dragnn.python.component import MasterState [as 別名]
def build_inference(self, handle, use_moving_average=False):
"""Builds an inference pipeline.
This always uses the whole pipeline.
Args:
handle: Handle tensor for the ComputeSession.
use_moving_average: Whether or not to read from the moving
average variables instead of the true parameters. Note: it is not
possible to make gradient updates when this is True.
Returns:
handle: Handle after annotation.
"""
self.read_from_avg = use_moving_average
network_states = {}
for comp in self.components:
network_states[comp.name] = component.NetworkState()
handle = dragnn_ops.init_component_data(
handle, beam_size=comp.inference_beam_size, component=comp.name)
master_state = component.MasterState(handle,
dragnn_ops.batch_size(
handle, component=comp.name))
with tf.control_dependencies([handle]):
handle = comp.build_greedy_inference(master_state, network_states)
handle = dragnn_ops.write_annotations(handle, component=comp.name)
self.read_from_avg = False
return handle
示例2: setUp
# 需要導入模塊: from dragnn.python import component [as 別名]
# 或者: from dragnn.python.component import MasterState [as 別名]
def setUp(self):
self.master = MockMaster()
self.master_state = component.MasterState(
handle='handle', current_batch_size=2)
self.network_states = {
'mock': component.NetworkState(),
'test': component.NetworkState(),
}
示例3: build_inference
# 需要導入模塊: from dragnn.python import component [as 別名]
# 或者: from dragnn.python.component import MasterState [as 別名]
def build_inference(self,
handle,
use_moving_average=False,
build_runtime_graph=False):
"""Builds an inference pipeline.
This always uses the whole pipeline.
Args:
handle: Handle tensor for the ComputeSession.
use_moving_average: Whether or not to read from the moving
average variables instead of the true parameters. Note: it is not
possible to make gradient updates when this is True.
build_runtime_graph: Whether to build a graph for use by the runtime.
Returns:
handle: Handle after annotation.
"""
self.read_from_avg = use_moving_average
self.build_runtime_graph = build_runtime_graph
network_states = {}
for comp in self.components:
network_states[comp.name] = component.NetworkState()
handle = dragnn_ops.init_component_data(
handle, beam_size=comp.inference_beam_size, component=comp.name)
if build_runtime_graph:
batch_size = 1 # runtime uses singleton batches
else:
batch_size = dragnn_ops.batch_size(handle, component=comp.name)
master_state = component.MasterState(handle, batch_size)
with tf.control_dependencies([handle]):
handle = comp.build_greedy_inference(master_state, network_states)
handle = dragnn_ops.write_annotations(handle, component=comp.name)
self.read_from_avg = False
self.build_runtime_graph = False
return handle
示例4: setUp
# 需要導入模塊: from dragnn.python import component [as 別名]
# 或者: from dragnn.python.component import MasterState [as 別名]
def setUp(self):
# Clear the graph and all existing variables. Otherwise, variables created
# in different tests may collide with each other.
tf.reset_default_graph()
self.master = MockMaster()
self.master_state = component.MasterState(
handle=tf.constant(['foo', 'bar']), current_batch_size=2)
self.network_states = {
'mock': component.NetworkState(),
'test': component.NetworkState(),
}