本文整理汇总了Python中tensorflow.python.summary.plugin_asset.get_plugin_asset函数的典型用法代码示例。如果您正苦于以下问题:Python get_plugin_asset函数的具体用法?Python get_plugin_asset怎么用?Python get_plugin_asset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_plugin_asset函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testGetPluginAsset
def testGetPluginAsset(self):
epa = plugin_asset.get_plugin_asset(_ExamplePluginAsset)
self.assertIsInstance(epa, _ExamplePluginAsset)
epa2 = plugin_asset.get_plugin_asset(_ExamplePluginAsset)
self.assertIs(epa, epa2)
opa = plugin_asset.get_plugin_asset(_OtherExampleAsset)
self.assertIsNot(epa, opa)
示例2: testRespectsGraphArgument
def testRespectsGraphArgument(self):
g1 = ops.Graph()
g2 = ops.Graph()
e1 = plugin_asset.get_plugin_asset(_ExamplePluginAsset, g1)
e2 = plugin_asset.get_plugin_asset(_ExamplePluginAsset, g2)
self.assertEqual(e1, plugin_asset.get_all_plugin_assets(g1)[0])
self.assertEqual(e2, plugin_asset.get_all_plugin_assets(g2)[0])
示例3: testEndpointsNoAssets
def testEndpointsNoAssets(self):
g = ops.Graph()
with g.as_default():
plugin_asset.get_plugin_asset(projector_plugin.ProjectorPluginAsset)
fw = writer.FileWriter(self.log_dir, graph=g)
fw.close()
self._SetupWSGIApp()
run_json = self._GetJson('/data/plugin/projector/runs')
self.assertEqual(run_json, [])
示例4: testSimplePluginCase
def testSimplePluginCase(self):
tempdir = self.get_temp_dir()
with ops.Graph().as_default() as g:
plugin_asset.get_plugin_asset(PluginAlpha)
fw = writer.FileWriter(tempdir)
fw.add_graph(g)
self.assertEqual(["Alpha"], plugin_asset_util.ListPlugins(tempdir))
assets = plugin_asset_util.ListAssets(tempdir, "Alpha")
self.assertEqual(["contents.txt"], assets)
contents = plugin_asset_util.RetrieveAsset(tempdir, "Alpha", "contents.txt")
self.assertEqual("hello world", contents)
示例5: testNoAssetsProperSerializationOnDisk
def testNoAssetsProperSerializationOnDisk(self):
logdir = self.get_temp_dir()
plugin_dir = os.path.join(logdir, writer._PLUGINS_DIR,
projector_plugin.ProjectorPluginAsset.plugin_name)
with ops.Graph().as_default() as g:
plugin_asset.get_plugin_asset(projector_plugin.ProjectorPluginAsset)
fw = writer.FileWriter(logdir)
fw.add_graph(g)
with gfile.Open(os.path.join(plugin_dir, 'projector_config.pbtxt')) as f:
content = f.read()
self.assertEqual(content, '')
示例6: testAddEmbeddingThumbnailListEntriesNot3DTensors
def testAddEmbeddingThumbnailListEntriesNot3DTensors(self):
manager = plugin_asset.get_plugin_asset(
projector_plugin.ProjectorPluginAsset)
with self.assertRaises(ValueError):
manager.add_embedding('test3', np.array([[1]]), thumbnails=[[1, 2, 3]],
thumbnail_dim=[1, 1])
示例7: testEndpointsMetadataForVariableAssets
def testEndpointsMetadataForVariableAssets(self):
self._GenerateProjectorTestData()
g = ops.Graph()
with g.as_default():
manager = plugin_asset.get_plugin_asset(
projector_plugin.ProjectorPluginAsset)
metadata = projector_plugin.EmbeddingMetadata(3)
metadata.add_column('labels', ['a', 'b', 'c'])
manager.add_metadata_for_embedding_variable('test', metadata)
fw = writer.FileWriter(self.log_dir, graph=g)
fw.close()
self._SetupWSGIApp()
run_json = self._GetJson('/data/plugin/projector/runs')
self.assertTrue(run_json)
run = run_json[0]
metedata_query = '/data/plugin/projector/metadata?run=%s&name=test' % run
metadata_tsv = self._Get(metedata_query).data
self.assertEqual(metadata_tsv, b'a\nb\nc\n')
unk_tensor_query = '/data/plugin/projector/tensor?run=%s&name=test' % run
response = self._Get(unk_tensor_query)
self.assertEqual(response.status_code, 400)
expected_tensor = np.array([[6, 6]], dtype=np.float32)
tensor_query = '/data/plugin/projector/tensor?run=%s&name=var1' % run
tensor_bytes = self._Get(tensor_query).data
self._AssertTensorResponse(tensor_bytes, expected_tensor)
示例8: text_summary
def text_summary(name, tensor, collections=None):
"""Summarizes textual data.
Text data summarized via this plugin will be visible in the Text Dashboard
in TensorBoard.
Args:
name: A name for the generated node. Will also serve as a series name in
TensorBoard.
tensor: a scalar string-type Tensor to summarize.
collections: Optional list of ops.GraphKeys. The collections to add the
summary to. Defaults to [_ops.GraphKeys.SUMMARIES]
Returns:
A TensorSummary op that is configured so that TensorBoard will recognize
that it contains textual data. The TensorSummary is a scalar `Tensor` of
type `string` which contains `Summary` protobufs.
Raises:
ValueError: If tensor has the wrong shape or type.
"""
if tensor.dtype != dtypes.string:
raise ValueError("Expected tensor %s to have dtype string, got %s" %
(tensor.name, tensor.dtype))
if tensor.shape.ndims != 0:
raise ValueError("Expected tensor %s to be scalar, has shape %s" %
(tensor.name, tensor.shape))
t_summary = tensor_summary(name, tensor, collections=collections)
text_assets = plugin_asset.get_plugin_asset(TextSummaryPluginAsset)
text_assets.register_tensor(t_summary.op.name)
return t_summary
示例9: testEndpointsComboTensorAssetsAndCheckpoint
def testEndpointsComboTensorAssetsAndCheckpoint(self):
self._GenerateProjectorTestData()
g = ops.Graph()
with g.as_default():
manager = plugin_asset.get_plugin_asset(
projector_plugin.ProjectorPluginAsset)
metadata = projector_plugin.EmbeddingMetadata(3)
metadata.add_column('labels', ['a', 'b', 'c'])
manager.add_metadata_for_embedding_variable('var1', metadata)
new_tensor_values = np.array([[1, 2], [3, 4], [5, 6]])
manager.add_embedding('new_tensor', new_tensor_values)
fw = writer.FileWriter(self.log_dir, graph=g)
fw.close()
self._SetupWSGIApp()
run_json = self._GetJson('/data/plugin/projector/runs')
self.assertTrue(run_json)
run = run_json[0]
var1_values = np.array([[6, 6]], dtype=np.float32)
var1_tensor_query = '/data/plugin/projector/tensor?run=%s&name=var1' % run
tensor_bytes = self._Get(var1_tensor_query).data
self._AssertTensorResponse(tensor_bytes, var1_values)
metadata_query = '/data/plugin/projector/metadata?run=%s&name=var1' % run
metadata_tsv = self._Get(metadata_query).data
self.assertEqual(metadata_tsv, b'a\nb\nc\n')
tensor_query = '/data/plugin/projector/tensor?run=%s&name=new_tensor' % run
tensor_bytes = self._Get(tensor_query).data
self._AssertTensorResponse(tensor_bytes, new_tensor_values)
示例10: testAddEmbeddingThumbnailListNotOfRank4
def testAddEmbeddingThumbnailListNotOfRank4(self):
manager = plugin_asset.get_plugin_asset(
projector_plugin.ProjectorPluginAsset)
with self.assertRaises(ValueError):
manager.add_embedding('test2', np.array([[1]]),
thumbnails=np.array([[1]]), thumbnail_dim=[1, 1])
示例11: text_summary
def text_summary(name, tensor, collections=None):
"""Summarizes textual data.
Text data summarized via this plugin will be visible in the Text Dashboard
in TensorBoard. The standard TensorBoard Text Dashboard will render markdown
in the strings, and will automatically organize 1d and 2d tensors into tables.
If a tensor with more than 2 dimensions is provided, a 2d subarray will be
displayed along with a warning message. (Note that this behavior is not
intrinsic to the text summary api, but rather to the default TensorBoard text
plugin.)
Args:
name: A name for the generated node. Will also serve as a series name in
TensorBoard.
tensor: a string-type Tensor to summarize.
collections: Optional list of ops.GraphKeys. The collections to add the
summary to. Defaults to [_ops.GraphKeys.SUMMARIES]
Returns:
A TensorSummary op that is configured so that TensorBoard will recognize
that it contains textual data. The TensorSummary is a scalar `Tensor` of
type `string` which contains `Summary` protobufs.
Raises:
ValueError: If tensor has the wrong type.
"""
if tensor.dtype != dtypes.string:
raise ValueError("Expected tensor %s to have dtype string, got %s" %
(tensor.name, tensor.dtype))
t_summary = tensor_summary(name, tensor, collections=collections)
text_assets = plugin_asset.get_plugin_asset(TextSummaryPluginAsset)
text_assets.register_tensor(t_summary.op.name)
return t_summary
示例12: testPluginAssetSerialized
def testPluginAssetSerialized(self):
with ops.Graph().as_default() as g:
plugin_asset.get_plugin_asset(ExamplePluginAsset)
logdir = self.get_temp_dir()
fw = writer.FileWriter(logdir)
fw.add_graph(g)
plugin_dir = os.path.join(logdir, writer._PLUGINS_DIR, "example")
with gfile.Open(os.path.join(plugin_dir, "foo.txt"), "r") as f:
content = f.read()
self.assertEqual(content, "foo!")
with gfile.Open(os.path.join(plugin_dir, "bar.txt"), "r") as f:
content = f.read()
self.assertEqual(content, "bar!")
示例13: testAddEmbeddingWithSpriteImageButNoThumbnailDim
def testAddEmbeddingWithSpriteImageButNoThumbnailDim(self):
manager = plugin_asset.get_plugin_asset(
projector_plugin.ProjectorPluginAsset)
thumbnails = np.array([[[1, 2, 3], [4, 5, 6], [7, 8, 9]]])
with self.assertRaises(ValueError):
manager.add_embedding(
'test', np.array([[1], [2], [3]]), thumbnails=thumbnails)
示例14: testAddEmbeddingThumbnailDimNotOfLength2
def testAddEmbeddingThumbnailDimNotOfLength2(self):
manager = plugin_asset.get_plugin_asset(
projector_plugin.ProjectorPluginAsset)
thumbnails = np.array([[[1, 2, 3], [4, 5, 6], [7, 8, 9]]])
with self.assertRaises(ValueError):
manager.add_embedding(
'test', np.array([[1], [2], [3]]), thumbnails=thumbnails,
thumbnail_dim=[4])
示例15: testAddEmbeddingWithMetadataOfIncorrectLength
def testAddEmbeddingWithMetadataOfIncorrectLength(self):
manager = plugin_asset.get_plugin_asset(
projector_plugin.ProjectorPluginAsset)
metadata = projector_plugin.EmbeddingMetadata(3)
metadata.add_column('labels', ['a', 'b', 'c'])
# values has length 2, while metadata has length 3.
values = np.array([[1], [2]])
with self.assertRaises(ValueError):
manager.add_embedding('test', values, metadata)