本文整理匯總了Python中mxboard.SummaryWriter方法的典型用法代碼示例。如果您正苦於以下問題:Python mxboard.SummaryWriter方法的具體用法?Python mxboard.SummaryWriter怎麽用?Python mxboard.SummaryWriter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mxboard
的用法示例。
在下文中一共展示了mxboard.SummaryWriter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: plot_mxboard
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def plot_mxboard(block, logdir='./logs'):
"""Plot network to visualize internal structures.
Parameters
----------
block : mxnet.gluon.HybridBlock
A hybridizable network to be visualized.
logdir : str
The directory to save.
"""
try:
from mxboard import SummaryWriter
except ImportError:
print('mxboard is required. Please install via `pip install mxboard` ' +
'or refer to https://github.com/awslabs/mxboard.')
raise
data = mx.sym.var('data')
sym = block(data)
if isinstance(sym, tuple):
sym = mx.sym.Group(sym)
with SummaryWriter(logdir=logdir) as sw:
sw.add_graph(sym)
usage = '`tensorboard --logdir={} --host=127.0.0.1 --port=8888`'.format(logdir)
print('Log saved. Use: {} to visualize it'.format(usage))
示例2: create_logger
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def create_logger(self):
"""
Create the logger including the file log and summary log
:return: logger and summary writer
"""
if self.args.training:
logger = Logger(self.args.log, '%s-%s' % (self.args.method, self.args.postfix),
rm_exist=self.args.start_epoch == 0)
logger.update_dict(vars(self.args))
if self.args.mxboard:
from mxboard import SummaryWriter
sw = SummaryWriter(logdir=self.args.log)
else:
sw = None
else:
logger, sw = None, None
return logger, sw
示例3: test_add_multiple_scalars
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def test_add_multiple_scalars():
sw = SummaryWriter(logdir=_LOGDIR)
sw.add_scalar(tag='test_multiple_scalars', value=np.random.uniform(), global_step=0)
sw.add_scalar(tag='test_multiple_scalars', value=('scalar1', np.random.uniform()), global_step=0)
sw.add_scalar(tag='test_multiple_scalars', value=['scalar2', np.random.uniform()], global_step=0)
sw.add_scalar(tag='test_multiple_scalars',
value={'scalar3': np.random.uniform(), 'scalar4': np.random.uniform()},
global_step=0)
items = os.listdir(_LOGDIR)
assert len(items) == 2
assert 'test_multiple_scalars' in items
items.remove('test_multiple_scalars')
assert items[0].startswith(_EVENT_FILE_PREFIX)
print(items[0])
assert file_exists(os.path.join(_LOGDIR, items[0]))
named_scalar_dir = os.path.join(_LOGDIR, 'test_multiple_scalars')
assert dir_exists(named_scalar_dir)
for i in range(1, 5):
sub_dir = os.path.join(named_scalar_dir, 'scalar%d' % i)
assert dir_exists(sub_dir)
sub_items = os.listdir(sub_dir)
assert len(sub_items) == 1
assert sub_items[0].startswith(_EVENT_FILE_PREFIX)
示例4: test_add_embedding
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def test_add_embedding():
def check_add_embedding(embedding, images=None, labels=None, global_step=None):
with SummaryWriter(logdir=_LOGDIR) as sw:
sw.add_embedding(tag='test_add_embedding', embedding=embedding, labels=labels,
images=images, global_step=global_step)
check_and_remove_for_embedding('test_add_embedding', images=images,
labels=labels, global_step=global_step)
batch_size = 10
embedding = mx.nd.uniform(shape=(batch_size, 20))
labels = mx.nd.uniform(low=1, high=2, shape=(batch_size,)).astype('int32')
images = mx.nd.uniform(shape=(batch_size, 3, 10, 10))
global_step = np.random.randint(low=0, high=999999)
check_add_embedding(embedding, labels=labels, images=images, global_step=global_step)
check_add_embedding(embedding.asnumpy(), labels=labels, images=images, global_step=global_step)
check_add_embedding(embedding, labels=labels.asnumpy(), images=images, global_step=global_step)
check_add_embedding(embedding, labels=labels.asnumpy(), images=images.asnumpy(), global_step=global_step)
check_add_embedding(embedding, labels=labels.asnumpy().tolist(), images=images, global_step=global_step)
check_add_embedding(embedding, images=images, global_step=global_step)
check_add_embedding(embedding, labels=labels, global_step=global_step)
check_add_embedding(embedding, labels=labels.asnumpy(), global_step=global_step)
check_add_embedding(embedding, labels=labels.asnumpy().tolist(), global_step=global_step)
check_add_embedding(embedding, global_step=global_step)
check_add_embedding(embedding)
示例5: __init__
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def __init__(self, logging_dir, prefix=None):
self.prefix = prefix
try:
from mxboard import SummaryWriter
self.summary_writer = SummaryWriter(logging_dir)
except ImportError:
logging.error('You can install mxboard via `pip install mxboard`.')
示例6: evaluate
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def evaluate(model, ctx, ground_truth, test_loader,
n_pred, mean, std, sw, step):
'''
evaluate model on testing set
Parameters
----------
ground_truth: np.ndarray,
shape is (num_of_samples, 1, n_pred, num_of_vertices)
test_loader: gluon.data.DataLoader, contains x and y
n_pred: int
mean: int
std: int
sw: mxboard.SummaryWriter
step: int
'''
predictions = predict(model, ctx, test_loader, n_pred).asnumpy()
pred = utils.math_utils.z_inverse(predictions, mean, std)
mape = utils.math_utils.masked_mape_np(ground_truth, pred, 0)
mae = utils.math_utils.MAE(ground_truth, pred)
rmse = utils.math_utils.RMSE(ground_truth, pred)
sw.add_scalar(tag='MAPE', value=mape, global_step=step)
sw.add_scalar(tag='MAE', value=mae, global_step=step)
sw.add_scalar(tag='RMSE', value=rmse, global_step=step)
print('step: {}, MAPE: {}, MAE: {}, RMSE: {}'.format(step, mape,
mae, rmse))
示例7: __init__
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def __init__(self,
logdir: str,
source_vocab: Optional[vocab.Vocab] = None,
target_vocab: Optional[vocab.Vocab] = None) -> None:
self.logdir = logdir
self.source_labels = vocab.get_ordered_tokens_from_vocab(source_vocab) if source_vocab is not None else None
self.target_labels = vocab.get_ordered_tokens_from_vocab(target_vocab) if target_vocab is not None else None
try:
import mxboard
logger.info("Logging training events for Tensorboard at '%s'", self.logdir)
self._writer = mxboard.SummaryWriter(logdir=self.logdir, flush_secs=60, verbose=False)
except ImportError:
logger.info("mxboard not found. Consider 'pip install mxboard' to log events to Tensorboard.")
self._writer = None
示例8: __init__
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def __init__(self, logging_dir, total_step=0, prefix=None):
self.prefix = prefix
self.step = total_step
try:
from mxboard import SummaryWriter
self.summary_writer = SummaryWriter(logging_dir)
except ImportError:
logging.error(
'You can install tensorboard via `pip install mxboard`.')
示例9: test_add_scalar
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def test_add_scalar():
sw = SummaryWriter(logdir=_LOGDIR)
sw.add_scalar(tag='test_add_scalar', value=np.random.uniform(), global_step=0)
sw.close()
check_event_file_and_remove_logdir()
示例10: test_add_histogram
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def test_add_histogram():
def check_add_histogram(data):
sw = SummaryWriter(logdir=_LOGDIR)
sw.add_histogram(tag='test_add_histogram', values=data, global_step=0, bins=100)
sw.close()
check_event_file_and_remove_logdir()
shape = rand_shape_nd(4)
data = mx.nd.random.normal(shape=shape)
check_add_histogram(data)
check_add_histogram(data.asnumpy())
示例11: test_add_image
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def test_add_image():
def check_add_image(data):
sw = SummaryWriter(logdir=_LOGDIR)
sw.add_image(tag='test_add_image', image=data, global_step=0)
sw.close()
check_event_file_and_remove_logdir()
shape = list(rand_shape_nd(4))
shape[1] = 3
shape = tuple(shape)
data = mx.nd.random.normal(shape=shape).clip(0, 1)
check_add_image(data)
check_add_image(data.asnumpy())
check_add_image(data.astype('float64'))
check_add_image((data * 255).astype('uint8'))
示例12: test_add_audio
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def test_add_audio():
def check_add_audio(data):
sw = SummaryWriter(logdir=_LOGDIR)
sw.add_audio(tag='test_add_audio', audio=data)
sw.close()
check_event_file_and_remove_logdir()
shape = (100,)
data = mx.nd.random.uniform(-1, 1, shape=shape)
check_add_audio(data)
check_add_audio(data.asnumpy())
示例13: test_add_pr_curve
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def test_add_pr_curve():
def check_add_pr_curve(labels, predictions, num_thresholds):
with SummaryWriter(_LOGDIR) as sw:
sw.add_pr_curve(tag='test_add_pr_curve', labels=labels, predictions=predictions, num_thresholds=num_threshodls)
check_event_file_and_remove_logdir()
shape = (100,)
predictions = mx.nd.uniform(low=0.0, high=1.0, shape=shape)
labels = mx.nd.uniform(low=0, high=2, shape=shape).astype('int32')
num_threshodls = 100
check_add_pr_curve(labels, predictions, num_threshodls)
check_add_pr_curve(labels.asnumpy(), predictions, num_threshodls)
check_add_pr_curve(labels.asnumpy(), predictions.asnumpy(), num_threshodls)
示例14: test_add_graph_symbol
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def test_add_graph_symbol():
data = mx.sym.Variable('data')
conv = mx.sym.Convolution(data, kernel=(2, 2), num_filter=2)
nodes = _get_nodes_from_symbol(conv)
expected_nodes = [NodeDef(name='data', op='null'),
NodeDef(name='convolution0/convolution0_weight', op='null',
attr={'param': AttrValue(
s='{ kernel : (2, 2) , num_filter : 2 }'.encode(encoding='utf-8'))}),
NodeDef(name='convolution0/convolution0_bias', op='null',
attr={'param': AttrValue(
s='{ kernel : (2, 2) , num_filter : 2 }'.encode(encoding='utf-8'))}),
NodeDef(name='convolution0/convolution0', op='Convolution',
input=['data', 'convolution0/convolution0_weight', 'convolution0/convolution0_bias'],
attr={'param': AttrValue(
s='{ kernel : (2, 2) , num_filter : 2 }'.encode(encoding='utf-8'))})]
# check _get_nodes_from_symbol
for expected_node, node in zip(expected_nodes, nodes):
assert expected_node == node
# check _sym2pb
expected_graph = GraphDef(node=expected_nodes, versions=VersionDef(producer=100))
graph = _net2pb(conv)
assert expected_graph == graph
# check add_graph
with SummaryWriter(logdir=_LOGDIR) as sw:
sw.add_graph(conv)
check_event_file_and_remove_logdir()
示例15: test_evaluate
# 需要導入模塊: import mxboard [as 別名]
# 或者: from mxboard import SummaryWriter [as 別名]
def test_evaluate(self):
from model import hybrid_model
from model import trainer
from data_loader.data_utils import data_gen
import numpy as np
from mxboard import SummaryWriter
import os
import shutil
ctx = mx.gpu(1)
num_of_vertices = 897
batch_size = 50
PeMS_dataset = data_gen('datasets/PeMSD7_V_897.csv', 24)
print('>> Loading dataset with Mean: {0:.2f}, STD: {1:.2f}'.format(
PeMS_dataset.mean,
PeMS_dataset.std
))
test = PeMS_dataset['test'].transpose((0, 3, 1, 2))
test_x, test_y = test[:100, :, : 12, :], test[:100, :, 12:, :]
test_loader = gluon.data.DataLoader(
gluon.data.ArrayDataset(nd.array(test_x), nd.array(test_y)),
batch_size=batch_size,
shuffle=False
)
print(test_x.shape, test_y.shape)
cheb_polys = nd.random_uniform(shape=(num_of_vertices,
num_of_vertices * 3))
blocks = [[1, 32, 64], [64, 32, 128]]
x = nd.random_uniform(shape=(batch_size, 1, 12, num_of_vertices),
ctx=ctx)
net = hybrid_model.STGCN(12, 3, 3, blocks, 1.0,
num_of_vertices, cheb_polys)
net.initialize(ctx=ctx)
net.hybridize()
net(x)
ground_truth = (np.concatenate([y.asnumpy() for x, y in test_loader],
axis=0) *
PeMS_dataset.std +
PeMS_dataset.mean)[:100]
if os.path.exists('test_logs'):
shutil.rmtree('test_logs')
sw = SummaryWriter('test_logs', flush_secs=5)
trainer.evaluate(net, ctx, ground_truth, test_loader,
12, PeMS_dataset.mean, PeMS_dataset.std, sw, 0)
self.assertEqual(os.path.exists('test_logs'), True)
sw.close()
if os.path.exists('test_logs'):
shutil.rmtree('test_logs')