(readonly logdir = './logs', args?: TensorBoardCallbackArgs)
| 222 | private readonly args: TensorBoardCallbackArgs; |
| 223 | |
| 224 | constructor(readonly logdir = './logs', args?: TensorBoardCallbackArgs) { |
| 225 | super({ |
| 226 | onBatchEnd: async (batch: number, logs?: Logs) => { |
| 227 | this.batchesSeen++; |
| 228 | if (this.args.updateFreq !== 'epoch') { |
| 229 | this.logMetrics(logs, 'batch_', this.batchesSeen); |
| 230 | } |
| 231 | }, |
| 232 | onEpochEnd: async (epoch: number, logs?: Logs) => { |
| 233 | this.logMetrics(logs, 'epoch_', epoch + 1); |
| 234 | if (this.args.histogramFreq > 0 && |
| 235 | epoch % this.args.histogramFreq === 0) { |
| 236 | this.logWeights(epoch); |
| 237 | } |
| 238 | }, |
| 239 | onTrainEnd: async (logs?: Logs) => { |
| 240 | if (this.trainWriter != null) { |
| 241 | this.trainWriter.flush(); |
| 242 | } |
| 243 | if (this.valWriter != null) { |
| 244 | this.valWriter.flush(); |
| 245 | } |
| 246 | } |
| 247 | }); |
| 248 | |
| 249 | this.args = args == null ? {} : args; |
| 250 | if (this.args.updateFreq == null) { |
| 251 | this.args.updateFreq = 'epoch'; |
| 252 | } |
| 253 | util.assert( |
| 254 | ['batch', 'epoch'].indexOf(this.args.updateFreq) !== -1, |
| 255 | () => `Expected updateFreq to be 'batch' or 'epoch', but got ` + |
| 256 | `${this.args.updateFreq}`); |
| 257 | if (this.args.histogramFreq == null) { |
| 258 | this.args.histogramFreq = 0; |
| 259 | } |
| 260 | util.assert( |
| 261 | Number.isInteger(this.args.histogramFreq) && |
| 262 | this.args.histogramFreq >= 0, |
| 263 | () => `Expected histogramFreq to be a positive integer, but got ` + |
| 264 | `${this.args.histogramFreq}`); |
| 265 | this.batchesSeen = 0; |
| 266 | } |
| 267 | |
| 268 | setModel(model: LayersModel): void { |
| 269 | // This method is inherited from BaseCallback. To avoid cyclical imports, |
nothing calls this directly
no test coverage detected