Search the web
Sign In
New User? Sign Up
icsi-speech-tools
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
hidden layer output   Message List  
Reply | Forward Message #138 of 162 |
Re: hidden layer output

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);
}




Thu Oct 25, 2007 8:49 am

p.fousek
Offline Offline
Send Email Send Email

Forward
Message #138 of 162 |
Expand Messages Author Sort by Date

Hi all, 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...
Eric
jefosler
Offline Send Email
Oct 25, 2007
12:39 am

... Eric> Hi all, I started looking at all of the new options (woo Eric> hoo) in v 3.20, and am curious: is there a way on the Eric> command line to take a...
David Johnson
st0nka
Offline Send Email
Oct 25, 2007
12:53 am

Yes, Matlab-formatted weights are definitely the way to go. ... In addition to Barry's HATs setup, you can do neat things like "bottleneck" features from Brno:...
Arlo Faria
arlo@...
Send Email
Oct 25, 2007
1:17 am

... Wow! That ain't rocket science! Thanks for the tip. ... Very cool, looking forward to it. -Eric...
Eric Fosler-Lussier
jefosler
Offline Send Email
Oct 25, 2007
1:25 am

... aha. I still have old rap3 weights (from qnstrn) so I can use qncopywts to convert to matlab. I guess I could hack the rap3 weights file rather easily...
Eric Fosler-Lussier
jefosler
Offline Send Email
Oct 25, 2007
1:18 am

... Rejecting frames is no joke! We've recently found that it's a great way to speed up training if you reject them in such a way as to leave a subset of data...
Arlo Faria
arlo@...
Send Email
Oct 25, 2007
1:27 am

... Arlo> Rejecting frames is no joke! We've recently found that it's Arlo> a great way to speed up training if you reject them in such Arlo> a way as to leave...
David Johnson
st0nka
Offline Send Email
Oct 25, 2007
1:33 am

... Yeah, that's similar to the kind of thing that Jun Hou and Larry Rabiner were seeing in their TDNN trainings, if I interpret what you're saying to mean...
Eric Fosler-Lussier
jefosler
Offline Send Email
Oct 25, 2007
1:43 am

... Yes, that's the idea in principle. In practice, I actually somewhat over-sample the more frequent classes for performance reasons. ... I randomly sample...
Arlo Faria
arlo@...
Send Email
Oct 25, 2007
2:08 am

... Eric> Or, does someone have some code to munge the weight files Eric> for me? ... Eric> aha. I still have old rap3 weights (from qnstrn) so I can Eric>...
David Johnson
st0nka
Offline Send Email
Oct 25, 2007
1:29 am

Hi Eric, ... 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...
Petr Fousek
p.fousek
Offline Send Email
Oct 25, 2007
8:56 am

Ooops, I attached an old version of the c code. I uploaded the right version in the "Files" section. Petr....
Petr Fousek
p.fousek
Offline Send Email
Oct 25, 2007
9:13 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help