MCPcopy
hub / github.com/tensorflow/tfjs / onBatchEnd

Method onBatchEnd

tfjs-layers/src/base_callbacks.ts:235–263  ·  view source on GitHub ↗
(batch: number, logs?: UnresolvedLogs)

Source from the content-addressed store, hash-verified

233 }
234
235 override async onBatchEnd(batch: number, logs?: UnresolvedLogs) {
236 if (logs == null) {
237 logs = {};
238 }
239 const batchSize = logs['size'] == null ? 0 : logs['size'] as number;
240 this.seen += batchSize;
241 for (const key in logs) {
242 const value = logs[key];
243 if (typeof value === 'number') {
244 if (!this.totals.hasOwnProperty(key)) {
245 this.totals[key] = 0;
246 }
247 this.totals[key] = this.totals[key] as number + value * batchSize;
248 } else {
249 let oldTotalsToDispose: Scalar;
250 if (key in this.totals) {
251 oldTotalsToDispose = this.totals[key] as Scalar;
252 } else {
253 this.totals[key] = 0;
254 }
255 const total: Scalar =
256 tidy(() => add((this.totals[key]), mul(value, batchSize)));
257 this.totals[key] = total;
258 if (oldTotalsToDispose != null) {
259 oldTotalsToDispose.dispose();
260 }
261 }
262 }
263 }
264
265 override async onEpochEnd(epoch: number, logs?: UnresolvedLogs) {
266 if (logs != null) {

Callers 3

history_test.tsFile · 0.45
onBatchEndMethod · 0.45

Calls 3

tidyFunction · 0.90
addFunction · 0.90
disposeMethod · 0.45

Tested by

no test coverage detected