def format_kv_recursive_flat(handler, kvs): if kvs is None or kvs == '': return '<pre>N/A</pre>' if not isinstance(kvs, dict): kvs = json.loads(kvs) return '<pre>' + kvformat( {k: v for k, v in dict_deep_kv(kvs) if not '__' in k}) + '</pre>'
def initialize(self): self.client.initialize() logger.info('Client started.') logger.info(' Name: {}'.format(self.name)) logger.info(' Identifier: {}'.format(self.identifier)) logger.info(' Conn info: {}'.format(self.conn_info)) logger.info(' Server name: {}'.format(self.get_server_name())) logger.info(' Server identifier: {}'.format( self.get_server_identifier())) logger.info(' Server signaature: {}'.format(self.get_signature())) configs = self.get_configs() if configs is not None: logger.info(' Server configs:\n' + kvformat(configs, indent=2))
def validate_epoch(epoch, model, val_dataloader, meters, meter_prefix='validation'): end = time.time() visualized = 0 vis = HTMLTableVisualizer(args.vis_dir, 'NSCL Execution Visualization') vis.begin_html() try: with tqdm_pbar(total=len(val_dataloader)) as pbar: for feed_dict in val_dataloader: if args.use_gpu: if not args.gpu_parallel: feed_dict = async_copy_to(feed_dict, 0) data_time = time.time() - end end = time.time() output_dict = model(feed_dict) monitors = { meter_prefix + '/' + k: v for k, v in as_float(output_dict['monitors']).items() } step_time = time.time() - end end = time.time() n = feed_dict['image'].size(0) meters.update(monitors, n=n) meters.update({'time/data': data_time, 'time/step': step_time}) feed_dict = GView(as_detached(as_cpu(feed_dict))) output_dict = GView(as_detached(as_cpu(output_dict))) for i in range(n): with vis.table( 'Visualize #{} Metainfo'.format(visualized), [ HTMLTableColumnDesc('id', 'QID', 'text', {'width': '50px'}), HTMLTableColumnDesc('image', 'Image', 'figure', {'width': '400px'}), HTMLTableColumnDesc('qa', 'QA', 'text', {'width': '200px'}), HTMLTableColumnDesc('p', 'Program', 'code', {'width': '200px'}) ]): image_filename = osp.join(args.data_image_root, feed_dict.image_filename[i]) image = Image.open(image_filename) fig, ax = vis_bboxes(image, feed_dict.objects_raw[i], 'object', add_text=False) _ = ax.set_title('object bounding box annotations') QA_string = """ <p><b>Q</b>: {}</p> <p><b>A</b>: {}</p> """.format(feed_dict.question_raw[i], feed_dict.answer[i]) P_string = '\n'.join( [repr(x) for x in feed_dict.program_seq[i]]) vis.row(id=i, image=fig, qa=QA_string, p=P_string) plt.close() with vis.table( 'Visualize #{} Metainfo'.format(visualized), [ HTMLTableColumnDesc('id', 'QID', 'text', {'width': '50px'}), HTMLTableColumnDesc('image', 'Image', 'figure', {'width': '400px'}), HTMLTableColumnDesc('mask', 'Mask', 'figure', {'width': '700px'}) ]): image_filename = osp.join(args.data_image_root, feed_dict.image_filename[i]) image = Image.open(image_filename) fig, ax = vis_bboxes(image, feed_dict.objects_raw[i], 'object', add_text=False) _ = ax.set_title('object bounding box annotations') if not args.show_mask: montage = fig else: num_slots = output_dict['monet/m'].shape[1] monet_fig = [ [ tensor2im(output_dict['monet/m'][i, k]) for k in range(num_slots) ], [ tensor2im(output_dict['monet/x'][i, k]) for k in range(num_slots) ], [ tensor2im(output_dict['monet/xm'][i, k]) for k in range(num_slots) ], [tensor2im(output_dict['monet/x_input'][i])] + [ tensor2im(output_dict['monet/x_tilde'][i]) for k in range(num_slots - 1) ] ] montage = montage_fig(monet_fig) vis.row(id=i, image=fig, mask=montage) plt.close() with vis.table('Visualize #{} Trace'.format(visualized), [ HTMLTableColumnDesc('id', 'Step', 'text', {'width': '50px'}), HTMLTableColumnDesc('image', 'Image', 'figure', {'width': '600px'}), HTMLTableColumnDesc('p', 'operation', 'text', {'width': '200px'}), HTMLTableColumnDesc('r', 'result', 'code', {'width': '200px'}) ]): # TODO(Jiayuan Mao @ 11/20): support output_dict.programs. for j, (prog, buf) in enumerate( zip(feed_dict.program_seq[i], output_dict.buffers[i])): if j != len(feed_dict.program_seq[i]) - 1 and ( buf > 0 ).long().sum().item() > 0 and buf.size( 0) == feed_dict.objects_raw[i].shape[0]: this_objects = feed_dict.objects_raw[i][ torch.nonzero(buf > 0)[:, 0].numpy()] fig, ax = vis_bboxes(image, this_objects, 'object', add_text=False) else: fig, ax = vis_bboxes(image, [], 'object', add_text=False) vis.row(id=j, image=fig, p=repr(prog), r=repr(buf)) plt.close() visualized += 1 if visualized > args.nr_visualize: raise StopIteration() pbar.set_description( meters.format_simple( 'Epoch {} (validation)'.format(epoch), { k: v for k, v in meters.val.items() if k.startswith('validation') and k.count('/') <= 1 }, compressed=True)) pbar.update() end = time.time() except StopIteration: pass from jacinle.utils.meta import dict_deep_kv from jacinle.utils.printing import kvformat with vis.table('Info', [ HTMLTableColumnDesc('name', 'Name', 'code', {}), HTMLTableColumnDesc('info', 'KV', 'code', {}) ]): vis.row(name='args', info=kvformat(args.__dict__, max_key_len=32)) vis.row(name='configs', info=kvformat(dict(dict_deep_kv(configs)), max_key_len=32)) vis.end_html() logger.info( 'Happy Holiday! You can find your result at "http://monday.csail.mit.edu/xiuming' + osp.realpath(args.vis_dir) + '".')
def dumps_kv(value): return kvformat(value)
def format(self, sep=': ', end='\n'): return kvformat(dict(dict_deep_kv(self)), sep=sep, end=end)
def format_kv(handler, kvs): if kvs is None or kvs == '': return '<pre>N/A</pre>' if not isinstance(kvs, dict): kvs = json.loads(kvs) return '<pre>' + kvformat(kvs) + '</pre>'
def format_args(args): return kvformat(args.__dict__)