func RunMultiTask(list string) { list_file := kaldi.TaskList(list) fl, err := os.Open(list_file) if err != nil { kaldi.Err().Println("Can not open task list:", list_file) } defer fl.Close() sc := bufio.NewScanner(fl) kaldi.Trace().Println("Task List File:", list_file) var wg sync.WaitGroup for sc.Scan() { str := sc.Text() kaldi.Trace().Println("Task String:", str) if strings.HasPrefix(str, "//") || len(str) == 0 { continue } wg.Add(1) go func(str string) { defer wg.Done() for _, field := range strings.Split(str, ";") { if len(strings.Trim(field, "\n ")) == 0 { continue } items := strings.Split(field, "#") RunTask(strings.Trim(items[0], " \n"), strings.Trim(items[1], " \n")) } }(str) } wg.Wait() }
func main() { var vars bool var feat, dy, tag string flag.StringVar(&feat, "feat", "mfcc", "mfcc, bnf(default)") flag.StringVar(&dy, "dy", "delta", "raw, delta(default) ") flag.StringVar(&tag, "tag", "", "anything, normal(default)") flag.BoolVar(&vars, "vars", false, "true, false(default)") flag.PrintDefaults() flag.Parse() kaldi.Init() defer kaldi.Uninit() kaldi.Trace().Println("train-dnn") dt := kaldi.NewDnnTask(feat) dt.TaskConf.Btrain = true dt.TaskConf.Bdecode = true dt.Dnn.ModelConf.Dynamic = dy dt.Dnn.ModelConf.Norm.Cmvn.Mean = true dt.Dnn.ModelConf.Norm.Cmvn.Vars = vars kaldi.WriteTask(dt) if err := dt.Run(); err != nil { kaldi.Err().Println() } }
func main() { var update bool flag.BoolVar(&update, "u", false, "update server") flag.Parse() kaldi.Init("", "") defer kaldi.Uninit() if !kaldi.GridClient().Inited() { kaldi.Err().Println("Grid Client no initlized!") return } if update { fmt.Println("Update grid nodes") kaldi.GridClient().Update() } fmt.Println("========= Gpu Sort =========") for _, n := range kaldi.GridClient().GpuSort() { fmt.Printf("Node:%s, GpuUsage:%04.2f, GpuMem:%04.2f \n", n.Node, n.GpuUsage(), n.GpuMem) } fmt.Println("========= Cpu Sort =========") for _, n := range kaldi.GridClient().CpuSort() { fmt.Printf("Node:%s, CpuUsage:%04.2f, CPU(s):%02d, CPU MHz: %04.2f, LoadAve:%02.2f\n", n.Node, n.CpuUsage(), n.CpuNum, n.CpuMHz, n.LoadAve) } }
func TasksFrom(identifier string) []kaldi.TaskRuner { file := kaldi.TaskFile(identifier) kaldi.Trace().Println("Selected Task:", file) fts, err := os.Open(file) if err != nil { kaldi.Err().Println("Can not open task:", file) } defer fts.Close() taskId := strings.Split(identifier, "_")[0] task_func := kaldi.TaskFromFunc(taskId) if task_func == nil { kaldi.Err().Println("No effective TaskFromFunc for ", taskId) return []kaldi.TaskRuner{} } return task_func(fts) }
func main() { var manual bool var gpu bool flag.BoolVar(&manual, "manual", false, "manual to control servers (default=false) ") flag.BoolVar(&gpu, "g", false, "gpu dependenc") flag.Parse() kaldi.Init("", "") defer kaldi.Uninit() if flag.NArg() == 0 { kaldi.Trace().Println("No enough args!") return } cmd := strings.Join(flag.Args(), " ") var err error if manual { err = kaldi.BashRun(cmd) } else { if gpu { err = kaldi.GpuBashRun(cmd) } else { err = kaldi.CpuBashRun(cmd) } } if err != nil { kaldi.Err().Println("Cmd Err:", cmd, "\t", err) os.Exit(1) } }
func ParseCFGFile(f string) []Config { fs, err := os.Open(f) defer fs.Close() if err != nil { kaldi.Err().Println("Open config file :", err) return []Config{} } return ParseCFGStream(fs) }
func main() { kaldi.Init() defer kaldi.Uninit() kaldi.Trace().Println("train-mono") m := kaldi.NewMonoTask() kaldi.WriteTask(m) if err := m.Run(); err != nil { kaldi.Err().Println() } }
func ApplyCmd(c Config) { file, err := os.Open(c.List) kaldi.Trace().Println("list :", c.List) if err != nil { kaldi.Err().Println("Open list file :", err) return } defer file.Close() scanner := bufio.NewScanner(file) for scanner.Scan() { item := strings.Trim(scanner.Text(), " \n") if len(item) != 0 { cmd := kaldi.JoinArgs(c.Cmd, c.Args, item) err := kaldi.CpuBashRun(cmd) if err != nil { kaldi.Err().Println("Cmd Err:", cmd, "\t", err) } } } }
func main() { var tag string flag.StringVar(&tag, "tag", "normal", "normal(default)") flag.PrintDefaults() flag.Parse() kaldi.Init() defer kaldi.Uninit() kaldi.Trace().Println("mk-cmvn") if flag.NArg() < 1 { kaldi.Err().Println("no enough args for feature type") } for _, feat := range flag.Args() { c := kaldi.NewCmvnTask() c.Feat = feat kaldi.WriteTask(c) if err := c.Run(); err != nil { kaldi.Err().Println() } } }
func ParseCFGStream(reader io.Reader) []Config { cfg := []Config{} for { dec := json.NewDecoder(reader) t := NewConfig() err := dec.Decode(t) kaldi.Trace().Println("config", t) if err != nil { kaldi.Err().Println("Parsing Config Error:", err) break } cfg = append(cfg, *t) } kaldi.Trace().Println("configs", cfg) return cfg }
func main() { kaldi.Init("", "") defer kaldi.Uninit() kaldi.DevInstance().AutoSync() kaldi.DevInstance().SortGpu() kaldi.DevInstance().PrintNodes(true) kaldi.DevInstance().SortCpu() kaldi.DevInstance().PrintNodes(false) rpc.Register(kaldi.DevInstance().RPC()) l, e := net.Listen("tcp", ":9001") if e != nil { kaldi.Err().Println("Grid Svr listen error:", e) } rpc.Accept(l) }
func RunTask(tag, scope string) error { idx_list, err := parseRange(scope) if err != nil { kaldi.Err().Println("Parse range:", err) return fmt.Errorf("Parse range:", err) } kaldi.Trace().Println("Range:", idx_list) var wg sync.WaitGroup for _, value := range idx_list { wg.Add(1) go func(tag string, idx int) { defer wg.Done() SingleTask(tag, idx) }(tag, value) } wg.Wait() return nil }
func main() { var name string flag.StringVar(&name, "name", "tri2.cmn", "tri2.cmn(default)") flag.PrintDefaults() flag.Parse() kaldi.Init() defer kaldi.Uninit() kaldi.Trace().Println("mk-fmllr") f := kaldi.NewFmllrTask() f.Src.Name = name f.Src.Exp = "GMM" kaldi.WriteTask(f) if err := f.Run(); err != nil { kaldi.Err().Println() } }
func main() { var vars bool var feat, dy string flag.StringVar(&feat, "feat", "mfcc", "mfcc, bnf(default)") flag.StringVar(&dy, "dy", "delta", "raw, delta(default) ") flag.BoolVar(&vars, "vars", false, "true, false(default)") flag.PrintDefaults() flag.Parse() kaldi.Init() defer kaldi.Uninit() kaldi.Trace().Println("train-gmm") g := kaldi.NewGmmTask(feat) g.ModelConf.Dynamic = dy g.ModelConf.Norm.Cmvn.Mean = true g.ModelConf.Norm.Cmvn.Vars = vars kaldi.WriteTask(g) if err := g.Run(); err != nil { kaldi.Err().Println() } }
func main() { var feat, dy, tag string flag.StringVar(&feat, "feat", "mfcc", "mfcc, bnf(default)") flag.StringVar(&dy, "dy", "delta", "raw, delta(default) ") flag.StringVar(&tag, "tag", "", "anything, normal(default)") flag.PrintDefaults() flag.Parse() kaldi.Init() defer kaldi.Uninit() kaldi.Trace().Println("mk-align") a := kaldi.NewAlignTask(feat) a.Dynamic = dy for _, name := range flag.Args() { kaldi.Trace().Println("Make alignment of name :", name) a.Name = name kaldi.WriteTask(a) if err := a.Run(); err != nil { kaldi.Err().Println() } } }
func SingleTask(tag string, idx int) { tasks := TasksFrom(tag) length := len(tasks) if idx >= length { kaldi.Err().Println("Out of task range :", length) return } if idx >= 0 { kaldi.Trace().Println("Task Idx:", idx) tasks[idx].Run() return } kaldi.Trace().Printf("%d Tasks in file [%s] will be run!\n", len(tasks), tag) var wg sync.WaitGroup for i, t := range tasks { wg.Add(1) go func(idx int, t kaldi.TaskRuner) { defer wg.Done() kaldi.Trace().Println("Task Idx:", idx) t.Run() }(i, t) } wg.Wait() }