* 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)
| 45 | * tensors. Used for models that take integer tensors as inputs. |
| 46 | */ |
| 47 | async 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). |
| 76 | async function exportMLPModel(exportPath) { |
no test coverage detected
searching dependent graphs…