Changeset 40376 for trunk/Ohana/src/opihi/cmd.data/nnet_commands.c
- Timestamp:
- Mar 26, 2018, 12:54:01 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.data/nnet_commands.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/nnet_commands.c
r40371 r40376 258 258 } 259 259 260 int nnet_write (int argc, char **argv) { 261 262 if (argc < 3) { 263 gprint (GP_ERR, "USAGE: nnet write (nnet) (filename) : save nnet weights and biases to a file\n"); 264 return FALSE; 265 } 266 267 Nnet *nnet = FindNnet (argv[1]); 268 if (nnet == NULL) { 269 gprint (GP_ERR, "nnet %s not found, create it first\n", argv[1]); 270 return FALSE; 271 } 272 273 // open the file and read the number of layers 274 FILE *f = fopen (argv[2], "w"); 275 if (f == NULL) { 276 gprint (GP_ERR, "USAGE: nnet write (nnet) (filename) : save nnet weights and biases to a file\n"); 277 gprint (GP_ERR, "file %s could not be opened\n", argv[2]); 278 return FALSE; 279 } 280 281 // write the number of layers 282 // NLAYER 3 283 fprintf (f, "NLAYER %d\n", nnet->Nlayer); 284 285 // write the number of nodes for each layer 286 // LAYERS 2 4 2 287 fprintf (f, "LAYERS"); 288 for (int i = 0; i < nnet->Nlayer; i++) { 289 fprintf (f, " %d", nnet->Nnodes[i]); 290 } 291 fprintf (f, "\n"); 292 293 // read the weights and biases from the data file 294 for (int L = 1; L < nnet[0].Nlayer; L++) { 295 296 fprintf (f, "LAYER %d NX %d NY %d\n", L - 1, nnet->Nnodes[L-1], nnet->Nnodes[L]); 297 298 for (int j = 0; j < nnet->Nnodes[L]; j++) { 299 for (int i = 0; i < nnet->Nnodes[L-1]; i++) { 300 int k = i + j*nnet[0].Nnodes[L-1]; 301 fprintf (f, "%f ", nnet[0].weight[L][k]); 302 } 303 fprintf (f, "%f\n", nnet[0].biases[L][j]); 304 } 305 } 306 fclose (f); 307 308 return TRUE; 309 } 310 260 311 int nnet_get (int argc, char **argv) { 261 312
Note:
See TracChangeset
for help on using the changeset viewer.
