MCPcopy Index your code
hub / github.com/tensorflow/tfjs / saveModelAndRandomInputs

Function saveModelAndRandomInputs

e2e/integration_tests/create_save_predict.js:47–73  ·  view source on GitHub ↗

* Generate random input(s), get predict() output(s), and save them along with * the model. * * @param model The `tf.LayersModel` instance in question. It may have one or * more inputs and one or more outputs. It is assumed that for each input, only * the first dimension (i.e., the batch dimen

(
    model, exportPathprefix, inputIntegerMax)

Source from the content-addressed store, hash-verified

45 * tensors. Used for models that take integer tensors as inputs.
46 */
47async function saveModelAndRandomInputs(
48 model, exportPathprefix, inputIntegerMax) {
49 await model.save(tfjsNode.io.fileSystem(exportPathprefix));
50
51 const xs = [];
52 const xsData = [];
53 const xsShapes = [];
54 for (const inputTensor of model.inputs) {
55 const inputShape = inputTensor.shape;
56 inputShape[0] = 1;
57 if (inputShape.indexOf(null) !== -1) {
58 throw new Error(
59 `It is assumed that the only the first dimension of the tensor ` +
60 `is undetermined, but the assumption is not satisfied for ` +
61 `input shape ${JSON.stringify(inputTensor.shape)}`);
62 }
63 const xTensor = inputIntegerMax == null ?
64 tfc.randomNormal(inputShape) :
65 tfc.floor(tfc.randomUniform(inputShape, 0, inputIntegerMax));
66 xs.push(xTensor);
67 xsData.push(Array.from(xTensor.dataSync()));
68 xsShapes.push(xTensor.shape);
69 }
70 fs.writeFileSync(exportPathprefix + '.xs-data.json', JSON.stringify(xsData));
71 fs.writeFileSync(
72 exportPathprefix + '.xs-shapes.json', JSON.stringify(xsShapes));
73}
74
75// Multi-layer perceptron (MLP).
76async function exportMLPModel(exportPath) {

Callers 9

exportMLPModelFunction · 0.85
exportCNNModelFunction · 0.85
exportDepthwiseCNNModelFunction · 0.85
exportSimpleRNNModelFunction · 0.85
exportGRUModelFunction · 0.85

Calls 4

floorMethod · 0.80
dataSyncMethod · 0.65
saveMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…