gx
chenyc
2025-06-12 7b72ac13a83764a662159d4a49b7fffb90476ecb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */
import { CustomCallback, LayersModel } from '@tensorflow/tfjs';
type LogFunction = (message: string) => void;
export declare const progressBarHelper: {
    ProgressBar: any;
    log: LogFunction;
};
/**
 * Terminal-based progress bar callback for tf.Model.fit().
 */
export declare class ProgbarLogger extends CustomCallback {
    private numTrainBatchesPerEpoch;
    private progressBar;
    private currentEpochBegin;
    private epochDurationMillis;
    private usPerStep;
    private batchesInLatestEpoch;
    private terminalWidth;
    private readonly RENDER_THROTTLE_MS;
    /**
     * Construtor of LoggingCallback.
     */
    constructor();
    private formatLogsAsMetricsContent;
    private isFieldRelevant;
}
/**
 * Get a succint string representation of a number.
 *
 * Uses decimal notation if the number isn't too small.
 * Otherwise, use engineering notation.
 *
 * @param x Input number.
 * @return Succinct string representing `x`.
 */
export declare function getSuccinctNumberDisplay(x: number): string;
/**
 * Determine the number of decimal places to display.
 *
 * @param x Number to display.
 * @return Number of decimal places to display for `x`.
 */
export declare function getDisplayDecimalPlaces(x: number): number;
export interface TensorBoardCallbackArgs {
    /**
     * The frequency at which loss and metric values are written to logs.
     *
     * Currently supported options are:
     *
     * - 'batch': Write logs at the end of every batch of training, in addition
     *   to the end of every epoch of training.
     * - 'epoch': Write logs at the end of every epoch of training.
     *
     * Note that writing logs too often slows down the training.
     *
     * Default: 'epoch'.
     */
    updateFreq?: 'batch' | 'epoch';
    /**
     * The frequency (in epochs) at which to compute activation and weight
     * histograms for the layers of the model.
     *
     * If set to 0, histograms won't be computed.
     *
     * Validation data (or split) must be specified for histogram visualizations.
     *
     * Default: 0.
     */
    histogramFreq?: number;
}
/**
 * Callback for logging to TensorBoard during training.
 *
 * Users are expected to access this class through the `tensorBoardCallback()`
 * factory method instead.
 */
export declare class TensorBoardCallback extends CustomCallback {
    readonly logdir: string;
    private model;
    private trainWriter;
    private valWriter;
    private batchesSeen;
    private readonly args;
    constructor(logdir?: string, args?: TensorBoardCallbackArgs);
    setModel(model: LayersModel): void;
    private logMetrics;
    private logWeights;
    private ensureTrainWriterCreated;
    private ensureValWriterCreated;
}
/**
 * Callback for logging to TensorBoard during training.
 *
 * Writes the loss and metric values (if any) to the specified log directory
 * (`logdir`) which can be ingested and visualized by TensorBoard.
 * This callback is usually passed as a callback to `tf.Model.fit()` or
 * `tf.Model.fitDataset()` calls during model training. The frequency at which
 * the values are logged can be controlled with the `updateFreq` field of the
 * configuration object (2nd argument).
 *
 * Usage example:
 * ```js
 * // Constructor a toy multilayer-perceptron regressor for demo purpose.
 * const model = tf.sequential();
 * model.add(
 *     tf.layers.dense({units: 100, activation: 'relu', inputShape: [200]}));
 * model.add(tf.layers.dense({units: 1}));
 * model.compile({
 *   loss: 'meanSquaredError',
 *   optimizer: 'sgd',
 *   metrics: ['MAE']
 * });
 *
 * // Generate some random fake data for demo purpose.
 * const xs = tf.randomUniform([10000, 200]);
 * const ys = tf.randomUniform([10000, 1]);
 * const valXs = tf.randomUniform([1000, 200]);
 * const valYs = tf.randomUniform([1000, 1]);
 *
 * // Start model training process.
 * await model.fit(xs, ys, {
 *   epochs: 100,
 *   validationData: [valXs, valYs],
 *    // Add the tensorBoard callback here.
 *   callbacks: tf.node.tensorBoard('/tmp/fit_logs_1')
 * });
 * ```
 *
 * Then you can use the following commands to point tensorboard
 * to the logdir:
 *
 * ```sh
 * pip install tensorboard  # Unless you've already installed it.
 * tensorboard --logdir /tmp/fit_logs_1
 * ```
 *
 * @param logdir Directory to which the logs will be written.
 * @param args Optional configuration arguments.
 * @returns An instance of `TensorBoardCallback`, which is a subclass of
 *   `tf.CustomCallback`.
 *
 * @doc {heading: 'TensorBoard', namespace: 'node'}
 */
export declare function tensorBoard(logdir?: string, args?: TensorBoardCallbackArgs): TensorBoardCallback;
export {};