Creates a text window in visdom and logs output to it. The output can be formatted with fancy HTML, and it new output can be set to 'append' or 'replace' mode. Args: fields: Currently not used update_type: One of {'REPLACE', 'APPEND'}. Default 'REPLACE'. For exampl
| 1054 | |
| 1055 | |
| 1056 | class VisdomTextLogger(BaseVisdomLogger): |
| 1057 | '''Creates a text window in visdom and logs output to it. |
| 1058 | |
| 1059 | The output can be formatted with fancy HTML, and it new output can |
| 1060 | be set to 'append' or 'replace' mode. |
| 1061 | |
| 1062 | Args: |
| 1063 | fields: Currently not used |
| 1064 | update_type: One of {'REPLACE', 'APPEND'}. Default 'REPLACE'. |
| 1065 | |
| 1066 | For examples, make sure that your visdom server is running. |
| 1067 | |
| 1068 | Example: |
| 1069 | >>> notes_logger = VisdomTextLogger(update_type='APPEND') |
| 1070 | >>> for i in range(10): |
| 1071 | >>> notes_logger.log("Printing: {} of {}".format(i+1, 10)) |
| 1072 | # results will be in Visdom environment (default: http://localhost:8097) |
| 1073 | |
| 1074 | ''' |
| 1075 | valid_update_types = ['REPLACE', 'APPEND'] |
| 1076 | |
| 1077 | def __init__(self, fields=None, win=None, env=None, opts={}, update_type=valid_update_types[0], |
| 1078 | port=8097, server="localhost"): |
| 1079 | |
| 1080 | super(VisdomTextLogger, self).__init__(fields, win, env, opts, port, server) |
| 1081 | self.text = '' |
| 1082 | |
| 1083 | if update_type not in self.valid_update_types: |
| 1084 | raise ValueError("update type '{}' not found. Must be one of {}".format( |
| 1085 | update_type, self.valid_update_types)) |
| 1086 | self.update_type = update_type |
| 1087 | |
| 1088 | self.viz_logger = self._viz_prototype(self.viz.text) |
| 1089 | |
| 1090 | def log(self, msg, *args, **kwargs): |
| 1091 | text = msg |
| 1092 | if self.update_type == 'APPEND' and self.text: |
| 1093 | self.text = "<br>".join([self.text, text]) |
| 1094 | else: |
| 1095 | self.text = text |
| 1096 | self.viz_logger([self.text]) |
| 1097 | |
| 1098 | def _log_all(self, stats, log_fields, prefix=None, suffix=None, require_dict=False): |
| 1099 | results = [] |
| 1100 | for field_idx, field in enumerate(self.fields): |
| 1101 | parent, stat = None, stats |
| 1102 | for f in field: |
| 1103 | parent, stat = stat, stat[f] |
| 1104 | name, output = self._gather_outputs(field, log_fields, |
| 1105 | parent, stat, require_dict) |
| 1106 | if not output: |
| 1107 | continue |
| 1108 | self._align_output(field_idx, output) |
| 1109 | results.append((name, output)) |
| 1110 | if not results: |
| 1111 | return |
| 1112 | output = self._join_results(results) |
| 1113 | if prefix is not None: |
nothing calls this directly
no outgoing calls
no test coverage detected