Write scalars to a json file. It saves scalars as one json per line (instead of a big json) for easy parsing. Examples parsing such a json file: :: $ cat metrics.json | jq -s '.[0:2]' [ { "data_time": 0.008433341979980469, "iterati
| 47 | |
| 48 | |
| 49 | class JSONWriter(EventWriter): |
| 50 | """ |
| 51 | Write scalars to a json file. |
| 52 | |
| 53 | It saves scalars as one json per line (instead of a big json) for easy parsing. |
| 54 | |
| 55 | Examples parsing such a json file: |
| 56 | :: |
| 57 | $ cat metrics.json | jq -s '.[0:2]' |
| 58 | [ |
| 59 | { |
| 60 | "data_time": 0.008433341979980469, |
| 61 | "iteration": 19, |
| 62 | "loss": 1.9228371381759644, |
| 63 | "loss_box_reg": 0.050025828182697296, |
| 64 | "loss_classifier": 0.5316952466964722, |
| 65 | "loss_mask": 0.7236229181289673, |
| 66 | "loss_rpn_box": 0.0856662318110466, |
| 67 | "loss_rpn_cls": 0.48198649287223816, |
| 68 | "lr": 0.007173333333333333, |
| 69 | "time": 0.25401854515075684 |
| 70 | }, |
| 71 | { |
| 72 | "data_time": 0.007216215133666992, |
| 73 | "iteration": 39, |
| 74 | "loss": 1.282649278640747, |
| 75 | "loss_box_reg": 0.06222952902317047, |
| 76 | "loss_classifier": 0.30682939291000366, |
| 77 | "loss_mask": 0.6970193982124329, |
| 78 | "loss_rpn_box": 0.038663312792778015, |
| 79 | "loss_rpn_cls": 0.1471673548221588, |
| 80 | "lr": 0.007706666666666667, |
| 81 | "time": 0.2490077018737793 |
| 82 | } |
| 83 | ] |
| 84 | |
| 85 | $ cat metrics.json | jq '.loss_mask' |
| 86 | 0.7126231789588928 |
| 87 | 0.689423680305481 |
| 88 | 0.6776131987571716 |
| 89 | ... |
| 90 | |
| 91 | """ |
| 92 | |
| 93 | def __init__(self, json_file, window_size=20): |
| 94 | """ |
| 95 | Args: |
| 96 | json_file (str): path to the json file. New data will be appended if the file exists. |
| 97 | window_size (int): the window size of median smoothing for the scalars whose |
| 98 | `smoothing_hint` are True. |
| 99 | """ |
| 100 | self._file_handle = PathManager.open(json_file, "a") |
| 101 | self._window_size = window_size |
| 102 | self._last_write = -1 |
| 103 | |
| 104 | def write(self): |
| 105 | storage = get_event_storage() |
| 106 | to_save = defaultdict(dict) |
no outgoing calls
no test coverage detected