def img2img_rnd(): cli_train = tw.WatcherClient() cli = tw.WatcherClient() imgs = cli_train.create_stream( event_name='batch', expr= "top(l, out_xform=pyt_img_img_out_xform, group_key=lambda x:'', topk=2, order='rnd')", throttle=1) img_plot = tw.mpl.ImagePlot() img_plot.show(imgs, img_width=100, img_height=100, viz_img_scale=3, cols=1) utils.wait_key()
def show_mpl(): cli = tw.WatcherClient() p = tw.mpl.LinePlot(title='Demo') s1 = cli.create_stream(expr='lambda v:(v.i, v.sum)') p.subscribe(s1, xtitle='Index', ytitle='sqrt(ev_i)') p.show() tw.plt_loop()
def plotly_history_graph(): cli = tw.WatcherClient() p = tw.plotly.line_plot.LinePlot(title='Demo') s2 = cli.create_stream(event_name='ev_j', expr='map(lambda v:(v.x, v.val), l)') p.subscribe(s2, ytitle='ev_j', history_len=15) p.show() utils.wait_key()
def text_stats(): train_cli = tw.WatcherClient() stream = train_cli.create_stream( event_name="batch", expr='lambda d:(d.x, d.metrics.batch_loss)') trl = tw.Visualizer(stream, vis_type=None) trl.show() input('Paused...')
def mpl_line_plot(): cli = tw.WatcherClient() p = tw.LinePlot(title='Demo') s1 = cli.create_stream(event_name='ev_i', expr='map(lambda v:math.sqrt(v.val)*2, l)') p.subscribe(s1, xtitle='Index', ytitle='sqrt(ev_i)') p.show() tw.plt_loop()
def show_mpl(): cli = tw.WatcherClient(r'c:\temp\sum.log') s1 = cli.open_stream('sum') p = tw.LinePlot(title='Demo') p.subscribe(s1, xtitle='Index', ytitle='sqrt(ev_i)') s1.load() p.show() tw.plt_loop()
def show_find_lr(): cli_train = tw.WatcherClient() plot = tw.mpl.LinePlot() train_batch_loss = cli_train.create_stream( event_name='batch', expr='lambda d:(d.tt.scheduler.get_lr()[0], d.metrics.batch_loss)') plot.subscribe(train_batch_loss, xtitle='Epoch', ytitle='Loss') utils.wait_key()
def plotly_line_graph(): cli = tw.WatcherClient() s1 = cli.create_stream(event_name="ev_i", expr='map(lambda v:(v.x, math.sqrt(v.val)), l)') p = tw.plotly.line_plot.LinePlot() p.subscribe(s1) p.show() utils.wait_key()
def dlc_show_rand_outputs(): cli = cli_train = tw.WatcherClient() imgs = cli.create_stream( event_name='batch', expr= "top(l, out_xform=pyt_img_img_out_xform, group_key=lambda x:'', topk=10, order='rnd')", throttle=1) img_plot = tw.mpl.ImagePlot() img_plot.show(imgs, img_width=39, img_height=69, viz_img_scale=10) utils.wait_key()
def show_mpl(): cli = tw.WatcherClient() st_isum = cli.open_stream('isums') st_rsum = cli.open_stream('rsums') line_plot = tw.Visualizer(st_isum, vis_type='line', xtitle='i', ytitle='isum') line_plot.show() line_plot2 = tw.Visualizer(st_rsum, vis_type='line', host=line_plot, ytitle='rsum') tw.plt_loop()
def img_in_class(): cli_train = tw.WatcherClient() imgs = cli_train.create_stream( event_name='batch', expr="top(l, out_xform=pyt_img_class_out_xform, order='rnd')", throttle=1) img_plot = tw.mpl.ImagePlot() img_plot.subscribe(imgs, viz_img_scale=3) img_plot.show() tw.image_utils.plt_loop()
def epoch_stats(): train_cli = tw.WatcherClient(port=0) test_cli = tw.WatcherClient(port=1) plot = tw.mpl.LinePlot() train_loss = train_cli.create_stream( event_name="epoch", expr='lambda v:(v.metrics.epoch_index, v.metrics.epoch_loss)') plot.subscribe(train_loss, xtitle='Epoch', ytitle='Train Loss') test_acc = test_cli.create_stream( event_name="epoch", expr='lambda v:(v.metrics.epoch_index, v.metrics.epoch_accuracy)') plot.subscribe(test_acc, xtitle='Epoch', ytitle='Test Accuracy', ylim=(0, 1)) plot.show() tw.plt_loop()
def mpl_history_plot(): cli = tw.WatcherClient() p2 = tw.LinePlot(title='History Demo') p2s1 = cli.create_stream( event_name='ev_j', expr='map(lambda v:(v.val, math.sqrt(v.val)*2), l)') p2.subscribe(p2s1, xtitle='Index', ytitle='sqrt(ev_j)', clear_after_end=True, history_len=15) p2.show() tw.plt_loop()
def plot_grads_plotly(): train_cli = tw.WatcherClient() grads = train_cli.create_stream(event_name='batch', expr='lambda d:grads_abs_mean(d.model)', throttle=1) p = tw.plotly.line_plot.LinePlot('Demo') p.subscribe(grads, xtitle='Layer', ytitle='Gradients', history_len=30, new_on_eval=True) utils.wait_key()
def plot_grads(): train_cli = tw.WatcherClient() grads = train_cli.create_stream( event_name='batch', expr= 'lambda d:agg_params(d.model, lambda p: p.grad.abs().mean().item())', throttle=1) p = tw.plotly.LinePlot('Demo') p.subscribe(grads, xtitle='Epoch', ytitle='Gradients', history_len=30, new_on_eval=True) utils.wait_key()
def img_in_class(): cli_train = tw.WatcherClient() imgs = cli_train.create_stream( event_name='batch', expr= "topk_all(l, batch_vals=lambda b: (b.batch.loss_all, (b.batch.input, b.batch.output), b.batch.target), \ out_f=image_class_outf, order='dsc')", throttle=1) img_plot = tw.ImagePlot() img_plot.subscribe(imgs, viz_img_scale=3) img_plot.show() tw.image_utils.plt_loop()
def plot_grads(): train_cli = tw.WatcherClient() grads = train_cli.create_stream(event_name='batch', expr='lambda d:grads_abs_mean(d.model)', throttle=1) grad_plot = tw.LinePlot() grad_plot.subscribe(grads, xtitle='Layer', ytitle='Gradients', clear_after_each=1, history_len=40, dim_history=True) grad_plot.show() tw.plt_loop()
def plot_weight(): train_cli = tw.WatcherClient() params = train_cli.create_stream(event_name='batch', expr='lambda d:weights_abs_mean(d.model)', throttle=1) params_plot = tw.LinePlot() params_plot.subscribe(params, xtitle='Layer', ytitle='avg |params|', clear_after_each=1, history_len=40, dim_history=True) params_plot.show() tw.plt_loop()
def plot_weight(): train_cli = tw.WatcherClient() params = train_cli.create_stream( event_name='batch', expr='lambda d:agg_params(d.model, lambda p: p.abs().mean().item())', throttle=1) params_plot = tw.mpl.LinePlot() params_plot.subscribe(params, xtitle='Epoch', ytitle='avg |params|', clear_after_each=1, history_len=40, dim_history=True) params_plot.show() tw.plt_loop()
def batch_stats(): train_cli = tw.WatcherClient() stream = train_cli.create_stream( event_name="batch", expr='lambda v:(v.metrics.epochf, v.metrics.batch_loss)', throttle=0.75) train_loss = tw.Visualizer(stream, clear_after_end=False, vis_type='mpl-line', xtitle='Epoch', ytitle='Train Loss') #train_acc = tw.Visualizer('lambda v:(v.metrics.epochf, v.metrics.epoch_loss)', event_name="batch", # xtitle='Epoch', ytitle='Train Accuracy', clear_after_end=False, yrange=(0,1), # vis=train_loss, vis_type='mpl-line') train_loss.show() tw.image_utils.plt_loop()
def show_stream(): cli = tw.WatcherClient() print("Subscribing to event ev_i...") s1 = cli.create_stream(event_name="ev_i", expr='map(lambda v:math.sqrt(v.val), l)') r1 = tw.TextVis(title='L1') r1.subscribe(s1) r1.show() print("Subscribing to event ev_j...") s2 = cli.create_stream(event_name="ev_j", expr='map(lambda v:v.val*v.val, l)') r2 = tw.TextVis(title='L2') r2.subscribe(s2) r2.show() print("Waiting for key...") utils.wait_key()
plot_defaults = dict(figure_fn=bk_figure, width=800, height=400) defaults_streams = ['train_' + n for n in metrics] +\ ['eval_' + n for n in metrics] if len(args.experiments) > 1: exp_names = args.legend or [ exp.replace('./results', '') for exp in args.experiments ] else: exp_names = [''] results = OrderedDict() for exp_name, exp in zip(exp_names, args.experiments): client = tw.WatcherClient( filename=os.path.join(exp, 'tensorwatch.log')) epoch_steps = [x for x, _ in dump_stream(client, 'epoch')] prefix = exp_name + ' - ' if exp_name != '' else '' for metric_name in metrics: results.setdefault(metric_name, {}) train_metrics = dump_stream(client, 'train_%s' % metric_name) val_metrics = dump_stream(client, 'eval_%s' % metric_name) if not args.all: train_metrics = reduce_ranges(train_metrics, epoch_steps) val_metrics = reduce_ranges(val_metrics, epoch_steps) if args.x_axis == 'epochs': train_metrics = annotate_indices(train_metrics, epoch_steps, interpolate=args.all) val_metrics = annotate_indices(val_metrics,
import tensorwatch as tw import objgraph, time #pip install objgraph cli = tw.WatcherClient() time.sleep(10) del cli import gc gc.collect() import time time.sleep(2) objgraph.show_backrefs(objgraph.by_type('WatcherClient'), refcounts=True, filename='b.png')
def show_text(): cli = tw.WatcherClient(r'c:\temp\sum.log') s1 = cli.open_stream('sum_2') text = tw.Visualizer(s1) text.show() input('Waiting')
def show_text(): cli = tw.WatcherClient() text_vis = tw.Visualizer(st_isum, vis_type='text') text_vis.show() input('Waiting')
def show_text(): cli = tw.WatcherClient() s1 = cli.create_stream(expr='lambda v:(v.i, v.sum)') text = tw.Visualizer(s1) text.show() input('Waiting')