~ubuntu-branches/ubuntu/vivid/sphinxtrain/vivid

« back to all changes in this revision

Viewing changes to scripts/40.buildtrees/slave.treebuilder.pl

  • Committer: Package Import Robot
  • Author(s): Samuel Thibault
  • Date: 2013-01-02 04:10:21 UTC
  • Revision ID: package-import@ubuntu.com-20130102041021-ynsizmz33fx02hea
Tags: upstream-1.0.8
ImportĀ upstreamĀ versionĀ 1.0.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
## ====================================================================
 
3
##
 
4
## Copyright (c) 1996-2000 Carnegie Mellon University.  All rights 
 
5
## reserved.
 
6
##
 
7
## Redistribution and use in source and binary forms, with or without
 
8
## modification, are permitted provided that the following conditions
 
9
## are met:
 
10
##
 
11
## 1. Redistributions of source code must retain the above copyright
 
12
##    notice, this list of conditions and the following disclaimer. 
 
13
##
 
14
## 2. Redistributions in binary form must reproduce the above copyright
 
15
##    notice, this list of conditions and the following disclaimer in
 
16
##    the documentation and/or other materials provided with the
 
17
##    distribution.
 
18
##
 
19
## This work was supported in part by funding from the Defense Advanced 
 
20
## Research Projects Agency and the National Science Foundation of the 
 
21
## United States of America, and the CMU Sphinx Speech Consortium.
 
22
##
 
23
## THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 
 
24
## ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
 
25
## THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
26
## PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
 
27
## NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
28
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 
29
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 
30
## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 
31
## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 
32
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 
33
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
34
##
 
35
## ====================================================================
 
36
##
 
37
## Author: Ricky Houghton
 
38
##
 
39
 
 
40
use strict;
 
41
use File::Copy;
 
42
use File::Basename;
 
43
use File::Spec::Functions;
 
44
use File::Path;
 
45
 
 
46
use lib catdir(dirname($0), updir(), 'lib');
 
47
use SphinxTrain::Config;
 
48
use SphinxTrain::Util;
 
49
 
 
50
#*************************************************************************
 
51
# This script runs the build_tree script for each state of each basephone
 
52
#*************************************************************************
 
53
 
 
54
use vars qw($MLLT_FILE $MODEL_TYPE);
 
55
$MLLT_FILE = catfile($ST::CFG_MODEL_DIR, "${ST::CFG_EXPTNAME}.mllt");
 
56
$MODEL_TYPE = 'cd';
 
57
 
 
58
my ($phone,$state);
 
59
my $return_value = 0;
 
60
my $logdir = "${ST::CFG_LOG_DIR}/40.buildtrees";
 
61
 
 
62
Log("MODULE: 40 Build Trees\n");
 
63
Log("Phase 1: Cleaning up old log files...\n");
 
64
rmtree ("$logdir");
 
65
mkdir ($logdir,0777);
 
66
 
 
67
$| = 1; # Turn on autoflushing
 
68
if ($ST::CFG_MAKE_QUESTS eq 'no') {
 
69
    die "Question set $ST::CFG_QUESTION_SET not found, but CFG_MAKE_QUESTS is no"
 
70
        unless -e $ST::CFG_QUESTION_SET;
 
71
}
 
72
else {
 
73
    Log("Phase 2: Make Questions");
 
74
    if (RunScript('make_questions.pl')) {
 
75
        $return_value = 1;
 
76
        exit ($return_value);
 
77
    }
 
78
}
 
79
 
 
80
Log("Phase 3: Tree building\n");
 
81
my $mdef_file       = "${ST::CFG_BASE_DIR}/model_architecture/${ST::CFG_EXPTNAME}.untied.mdef";
 
82
my $mixture_wt_file = "${ST::CFG_BASE_DIR}/model_parameters/${ST::CFG_EXPTNAME}.${MODEL_TYPE}_${ST::CFG_DIRLABEL}_untied/mixture_weights";
 
83
my $tree_base_dir   = "${ST::CFG_BASE_DIR}/trees";
 
84
my $unprunedtreedir = "$tree_base_dir/${ST::CFG_EXPTNAME}.unpruned";
 
85
mkdir ($tree_base_dir,0777);
 
86
mkdir ($unprunedtreedir,0777);
 
87
 
 
88
# For every phone submit each possible state
 
89
my @jobs;
 
90
if ($ST::CFG_CROSS_PHONE_TREES eq 'yes') {
 
91
    Log("Processing all phones with each state\n", 'result');
 
92
    push @jobs, ['ALLPHONES' => LaunchScript("tree.all", ['buildtree.pl', 'ALLPHONES'])];
 
93
} else {
 
94
    Log ("Processing each phone with each state\n", 'result');
 
95
    open INPUT,"${ST::CFG_RAWPHONEFILE}";
 
96
    foreach $phone (<INPUT>) {
 
97
        if ($ST::CFG_QUEUE_TYPE eq "Queue::POSIX") {
 
98
            # Use @jobs as a queue (better than nothing for Queue::POSIX)
 
99
            if (@jobs > $ST::CFG_NPART) {
 
100
                my ($p, $j) = @{shift @jobs};
 
101
                WaitForScript($j);
 
102
            }
 
103
        }
 
104
        $phone = Trim($phone);
 
105
        if (($phone =~ m/^(\+).*(\+)$/) || ($phone =~ m/^SIL$/)) {
 
106
            Log ("Skipping $phone\n", 'result');
 
107
            next;
 
108
        }
 
109
 
 
110
        my $job = LaunchScript("tree.$phone", ['buildtree.pl', $phone]);
 
111
        push @jobs, [$phone => $job];
 
112
    }
 
113
    close INPUT;
 
114
}
 
115
 
 
116
# Wait for all the remaining phones to finish
 
117
# It doesn't really matter what order we do this in
 
118
foreach (@jobs) {
 
119
    my ($phone,$job) = @$_;
 
120
    WaitForScript($job);
 
121
}
 
122