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 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 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 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 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 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()
import tensorwatch as tw import time from tensorwatch.zmq_wrapper import ZmqWrapper from tensorwatch import utils class A: def on_event(self, obj): print(obj) a = A() utils.set_debug_verbosity(10) sub = ZmqWrapper.Subscription(40859, "Topic1", a.on_event) print("subscriber is waiting") clisrv = ZmqWrapper.ClientServer(40860, False) clisrv.send_obj("hello 1") print('sleeping..') time.sleep(10) clisrv.send_obj("hello 2") print('waiting for key..') utils.wait_key()