| 1 |
//--------------------------------------------------------------------- |
| 2 |
// name: mlp-load.ck |
| 3 |
// desc: loading an MLP model from file (created by MLP.save()) |
| 4 |
// |
| 5 |
// version: need chuck version 1.5.0.0 or higher |
| 6 |
// sorting: part of ChAI (ChucK for AI) |
| 7 |
// |
| 8 |
// uncomment for MLP API: |
| 9 |
// MLP.help(); |
| 10 |
// |
| 11 |
// author: Yikai Li |
| 12 |
// Ge Wang (https://ccrma.stanford.edu/~ge/) |
| 13 |
// date: Winter 2023 |
| 14 |
//--------------------------------------------------------------------- |
| 15 |
|
| 16 |
// instantiate a multilayer perception |
| 17 |
MLP mlp; |
| 18 |
|
| 19 |
// file name |
| 20 |
"model.txt" => string filename; |
| 21 |
// print |
| 22 |
<<< "loading model from file:", filename >>>; |
| 23 |
// load the model into network (created by MLP.save() elsewhere) |
| 24 |
if( !mlp.load( me.dir() + filename ) ) me.exit(); |
| 25 |
|
| 26 |
// predict given a new input |
| 27 |
[0.7, 0.8, 0.9] @=> float x[]; |
| 28 |
// array to how output |
| 29 |
float y[2]; |
| 30 |
|
| 31 |
// predict output given input |
| 32 |
mlp.predict(x, y); |
| 33 |
// print the output |
| 34 |
<<< y[0], y[1] >>>; |