Hi Eric,
> I started looking at all of the new options (woo hoo) in v 3.20, and
> am curious: is there a way on the command line to take a 3-layer MLP
> and strip off the output layer (thus leaving the input-hidden layer)
> for forward processing purposes?
Arlo already proposed a good solution. I cooperate with Brno guys on
the new shiny Bottle-Neck features :) (hopefully more in ICASSP'08
paper) and I need to change the weights format quite often. I do not
want to launch matlab every time so I wrote a small c code to do it,
which compiles using matlab libraries. It still needs matlab shared
libs to run, but at least it is just one binary, which can be called
from any shell script. The code is below (I dont know how to attach it).
Note that I use 4 layers or 5 layers MLP for training and for the
forward pass I use linear outputs of the third layer. The code below
naturally works also for 4-layers MLP despite its name...
Hope it helps.
Petr.
-------------
/*
* This converts QuickNet 3.20 weights file in Matlab format from
* 4- or 5-layers to only three layers (basically it drops the rest o
f the data)
* (C) 2007 Petr Fousek, fousek@...
*
* It is based on the matlab example file matcreat.c (included in the
distribution),
* it definitely could have been better written, but...
*
compile:
mex -f <path>/matopts.sh 5to3layers.c
run:
./5to3layers
*/
#include <stdio.h>
#include <string.h> /* For strcmp() */
#include <stdlib.h> /* For EXIT_FAILURE, EXIT_SUCCESS */
#include "mat.h"
#define BUFSIZE 256
int main() {
MATFile *fin,*fout;
mxArray *bias2, *bias3, *weights12, *weights23;
const char *in = "weights";
const char *out = "out.mat";
int status;
/* open IN file */
fin = matOpen(in, "r");
if (fin == NULL) {
printf("Error opening file %s\n", in);
return(EXIT_FAILURE);
}
/* read */
bias2 = matGetVariable(fin, "bias2");
if (bias2 == NULL) {
printf("Error reading existing matrix bias2\n");
return(EXIT_FAILURE);
}
if (mxGetNumberOfDimensions(bias2) != 2) {
printf("Bias2 does not have two dimensions\n");
return(EXIT_FAILURE);
}
bias3 = matGetVariable(fin, "bias3");
if (bias3 == NULL) {
printf("Error reading existing matrix bias3\n");
return(EXIT_FAILURE);
}
if (mxGetNumberOfDimensions(bias3) != 2) {
printf("Bias3 does not have two dimensions\n");
return(EXIT_FAILURE);
}
weights12 = matGetVariable(fin, "weights12");
if (weights12 == NULL) {
printf("Error reading existing matrix weights12\n");
return(EXIT_FAILURE);
}
if (mxGetNumberOfDimensions(weights12) != 2) {
printf("weights12 does not have two dimensions\n");
return(EXIT_FAILURE);
}
weights23 = matGetVariable(fin, "weights23");
if (weights23 == NULL) {
printf("Error reading existing matrix weights23\n");
return(EXIT_FAILURE);
}
if (mxGetNumberOfDimensions(weights23) != 2) {
printf("weights23 does not have two dimensions\n");
return(EXIT_FAILURE);
}
/* open out */
printf("Creating file in matlab v4 format: %s...\n\n", out);
fout = matOpen(out, "w4");
if (fout == NULL) {
printf("Error creating file %s\n", out);
return(EXIT_FAILURE);
}
/* put the stuff */
status = matPutVariable(fout, "bias2", bias2);
if (status != 0) {
printf("%s : Error using matPutVariable on line %d\n", __FILE__,
__LINE__);
return(EXIT_FAILURE);
}
status = matPutVariable(fout, "bias3", bias3);
if (status != 0) {
printf("Error using matPutVariable\n");
return(EXIT_FAILURE);
}
status = matPutVariable(fout, "weights12", weights12);
if (status != 0) {
printf("%s : Error using matPutVariable on line %d\n", __FILE__,
__LINE__);
return(EXIT_FAILURE);
}
status = matPutVariable(fout, "weights23", weights23);
if (status != 0) {
printf("%s : Error using matPutVariable on line %d\n", __FILE__,
__LINE__);
return(EXIT_FAILURE);
}
mxDestroyArray(bias2);
mxDestroyArray(bias3);
mxDestroyArray(weights12);
mxDestroyArray(weights23);
if (matClose(fout) != 0) {
printf("Error closing file %s\n",fout);
return(EXIT_FAILURE);
}
if (matClose(fin) != 0) {
printf("Error closing file %s\n",fin);
return(EXIT_FAILURE);
}
printf("Done\n");
return(EXIT_SUCCESS);
}