[Scons-users] Help needed with "Options"

Sophie Lagarde lagarde at gfz-potsdam.de
Tue Jan 14 08:13:19 EST 2020


Hi,

I am using a code I did not develop by myself. It is basically a python 
code, I am working on python 3 with anaconda. I installed the scons 
package with anaconda, and when I am making "conda list", it does appear 
in the list (version 3.1.2).

My problem is that when I want to run the code, scons is not happy (in 
my SConstruct file) with the following line:

opts = Options(config)
scons: Reading SConscript files ...
NameError: name 'Options' is not defined

And I don't know why. My guess is that this function ("Options") existed 
in previous version, but does not exist anymore (I found references to 
it in SCons User Guide 0.97 and 0.98 
(https://scons.org/doc/0.98.2/HTML/scons-user/x1687.html) but none in 
the 3.1.2).

I am really new in using python and this code I am using is a big black 
box, so I am sure there is a way to make it work but I have no idea how. 
I will be very pleased if someone can help me, I searched on internet 
about the options stuff but did not find any hint.

Attached is the SConstruct file.

Regards,

-------------- next part --------------
#!/usr/bin/env python
#------------------------------------------
# Filename: SConstruct_dummy_mixtures
#  Purpose: Train Hidden Markov Models using HTK
#   Author: Moritz Beyreuther
#           Conny Hammer
#    Email: moritz.beyreuther at geophysik.uni-muenchen.de
#           conny.hammer at geo.uni-potsdam.de
#
# Copyright (C) 2008-2013 Moritz Beyreuther, Conny Hammer
#-------------------------------------------------------------------

import os, sys, glob 
pJoin = os.path.join
sys.path.append(pJoin(os.getcwd(),'shells'))
import htk_easywrite
import htk_compare_tied_duration
from htk_util import *
import htk_prewhite_transform
import htk_easywrite_prewhiten

#
# reading in give config file
#
config = ARGUMENTS.get('CONFIG','')
#
opts = Options(config)
opts.AddOptions(
	('CLASSES','Set comma seperated classnames','nn'), # also passed to htk_easy_write
	('ACLASSES','Set comma seperated classnames','eb'),
	('STATES','Set number of states','5'),
	('STATION','Give station name','MUO'),
	('HEREST','Use HERest instead of HRest, True=1 or False=0','1'),
	('CYCLES','Set number of training cycles','34'),
	('FRAMERATE','Give framerate of cssan files','0.05'), # for htk_easy_write
        ('ROTATION','Use rotation bevore transforming freatures False=0', '0'),
	('FEATURES','Set comma seperated index of features to use from 3cssan_file',
		'0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29')
)

#
env = Environment(options = opts)

env.Append(ENV={'PATH': os.environ.get('PATH')})
help = """\nProgram to compute and evaluate hmm for keyword spotting\n"""
Help(help+opts.GenerateHelpText(env))
exe = env.Command

#
cList = env['CLASSES'].split(',')
evcList = env['ACLASSES'].split(',')
#map(evcList.remove,["dn"])
features = env['FEATURES']
station = env['STATION']
nStates = int(env['STATES'])
nCycles = int(env['CYCLES'])
nFeatures = len(features.split(','))
use_herest = int(env['HEREST'])
framerate = float(env['FRAMERATE'])
use_rotation = int(env['ROTATION'])


hmm       = {}
trainData = {}
evData    = {}
trainList = []
evList    = []
ecl	  = []
traindir  = pJoin('train_data','fv%i' % nFeatures)
labeldir  = pJoin('label')
modeldir  = pJoin('model',station,'fv%i' % nFeatures)
resultdir = pJoin('results',station,'fv%i' % nFeatures)
hmmList   = pJoin('def','hmmlistnoise.txt')
hmmEvList = pJoin('def','hmmlistev.txt')
hmmListall= pJoin('def','hmmlistall.txt')
trainFile = pJoin('logs','train_data_fv%i_%s.txt' % (nFeatures,station))
evFile    = pJoin('logs','event_data_fv%i_%s.txt' % (nFeatures,station))

env['EIGENVALUES']=nFeatures
if use_rotation:
    traindir = traindir.replace('fv', 'rot-fv')
    trainFile = trainFile.replace('fv', 'rot-fv')
    modeldir = modeldir.replace('fv', 'rot-fv')
    resultdir = resultdir.replace('fv', 'rot-fv')
    evFile = evFile.replace('fv', 'rot-fv')
    env['EIGENVALUES'] = nFeatures

#
# Include prewhitening if necessary
#
if use_rotation:
    exe(["eigenvalues-fv%i.txt"%nFeatures,"rot_matrix-fv%i.txt"%nFeatures],
         glob.glob('raw_data/3cssan*.*.*.%s'% station),
         htk_prewhite_transform.main)

def make_list(clist,itr,addToClass=[],dir=modeldir,hdir='hmm'):
	tdir = pJoin(dir,hdir + str(itr + 1))
	slist = [pJoin(dir,hdir + str(itr),x) for x in clist]
	clist = addToClass + clist
	tlist = [pJoin(tdir,x) for x in clist]
	return (tdir,tlist,slist)

#
# convert the trainList to htk format (.user), this will only convert
# the according features specified in features variable (log for hob 
# is taken, and in the same step generate the trainData list for the whole
# SConstruct file
#
for class_ in cList:
        trainData[class_] = []
        for cssanFile in glob.glob('raw_data/3cssan.%s.*.%s'% (class_,station)):
                cssanBase = os.path.basename(cssanFile)
                htkFile = pJoin(traindir,'%s.user'% cssanBase)
                trainData[class_].append(htkFile)
                if use_rotation:
                   exe(htkFile,
                   [cssanFile,"eigenvalues-fv%i.txt"%nFeatures,"rot_matrix-fv%i.txt"%nFeatures],
                   htk_easywrite_prewhiten.main)
                else:
                   exe(htkFile,cssanFile,htk_easywrite.htk_easywrite)
        trainList += trainData[class_]

for class_ in evcList:
        evData[class_] = []
        for cssanFile1 in glob.glob('raw_data/3cssan.%s.*.%s'% (class_,station)):
                cssanBase1 = os.path.basename(cssanFile1)
                htkFile1 = pJoin(traindir,'%s.user'% cssanBase1)
                evData[class_].append(htkFile1)
                if use_rotation:
                   exe(htkFile1,
                   [cssanFile1,"eigenvalues-fv%i.txt"%nFeatures,"rot_matrix-fv%i.txt"%nFeatures],
                   htk_easywrite_prewhiten.main)
                else:
                   exe(htkFile1,cssanFile1,htk_easywrite.htk_easywrite)
                ecl.append(cssanFile1)
        evList += evData[class_]

# write HMM and trainList
# make tmp dir if not existing
# as list are not written with exe

ccList = cList+evcList
if not os.path.isdir('logs'):
	os.mkdir('logs')
writeList(hmmList,cList)
writeList(hmmEvList,evcList)
writeList(trainFile,trainList)
writeList(evFile,evList)
writeList(hmmListall,ccList)

#
# generate prototype HMM
#
for class_ in ccList:
	exe(pJoin(modeldir,'proto',class_),'',
		"""shells/htk_proto.pl -o $TARGET -s 3 -v %i -c %s"""
		% (nFeatures,class_))

# initialize the HMM, only update -u mt: mean, transition matrix
# Option Hinit -u mt doesn't work with htk_3.4!!
#
vfloorFile = pJoin(modeldir,'hmm0','vFloors')
for class_ in cList:
	source = pJoin(modeldir,'proto',class_)
	tdir = pJoin(modeldir,'hmm0')
	exe( pJoin(tdir,class_),trainList+[source],
                """HCompV -S %s -T 1 -m -M %s -f 0.99 -v 0.99e-08 -H %s %s""" %
		(trainFile,tdir,source,class_))
		
for class_ in evcList:
	source = pJoin(modeldir,'proto',class_)
	tdir = pJoin(modeldir,'hmm0')
	exe( pJoin(tdir,class_),evList+[source],
                """HCompV -S %s -T 1 -m -M %s -f 0.99 -v 0.99e-08 -H %s %s""" %
		(evFile,tdir,source,class_))		
#
# train target HMM 1-5 and 7, 6 is accomplished by HHEd below
# increased the convergence factor epsilon from 1E-4 to 6E-4
#
for itr in range(0,4)+range(5,9)+range(10,14)+range(15,19)+range(20,24)+range(25,29):
	(tdir,tList,sList)=make_list(ccList,itr)
	exe(tList,sList,
		"""HERest -S %s -u tmvw -v 0.99e-08 -L %s -M %s -H %s %s"""
		% (trainFile,labeldir,tdir, " -H ".join(sList),hmmListall))

itr = 4
hhedFile = pJoin('def','split_variance1.txt')
(tdir,tList,sList)=make_list(ccList,itr)
exe(tList,sList+[hhedFile,trainFile,evFile],
	"""HHEd -M %s -H %s %s %s """
	% (tdir," -H ".join(sList),hhedFile,hmmListall))

itr = 9
hhedFile = pJoin('def','split_variance2.txt')
(tdir,tList,sList)=make_list(ccList,itr)
exe(tList,sList+[hhedFile,trainFile,evFile],
	"""HHEd -M %s -H %s %s %s """
	% (tdir," -H ".join(sList),hhedFile,hmmListall))

itr = 14
hhedFile = pJoin('def','split_variance3.txt')
(tdir,tList,sList)=make_list(ccList,itr)
exe(tList,sList+[hhedFile,trainFile,evFile],
	"""HHEd -M %s -H %s %s %s """
	% (tdir," -H ".join(sList),hhedFile,hmmListall))

itr = 19
hhedFile = pJoin('def','split_variance4.txt')
(tdir,tList,sList)=make_list(ccList,itr)
exe(tList,sList+[hhedFile,trainFile,evFile],
	"""HHEd -M %s -H %s %s %s """
	% (tdir," -H ".join(sList),hhedFile,hmmListall))

itr = 24
hhedFile = pJoin('def','split_variance4.txt')
(tdir,tList,sList)=make_list(ccList,itr)
exe(tList,sList+[hhedFile,trainFile,evFile],
	"""HHEd -M %s -H %s %s %s """
	% (tdir," -H ".join(sList),hhedFile,hmmListall))

itr = 29
hhedFile = pJoin('def','tie_noise_mixtures.txt')
(tdir,tList,sList)=make_list(cList,itr,addToClass=['mix'])
cList.insert(0,'mix') #gvar2 after gvar
exe(tList,sList+[hhedFile,trainFile],
	"""HHEd -M %s -H %s %s %s """
	% (tdir," -H ".join(sList),hhedFile,hmmList))

source = [pJoin (modeldir,"hmm%i" % itr, x ) for x in evcList]
itr = 30
markedEvent = ecl
mix_source = [pJoin (modeldir,"hmm%i" % itr, x ) for x in ['mix']]
target = [pJoin(modeldir,"hmm%i" % itr, x ) for x in evcList]
exe(target,[markedEvent]+source+mix_source,htk_compare_tied_duration.htk_compare_tied_duration)
evcList.insert(0,'stateeb')

for itr in range(30,34):
        (tdir,tList,sList)=make_list(evcList,itr,addToClass=['stateeb'])
        exe(tList,sList,
                #"""HERest -S %s -u tmvwap -L %s -M %s -H %s %s"""
                """HERest -S %s -m 1 -u m -L %s -M %s -H %s %s"""
                % (evFile,labeldir,tdir, " -H ".join(sList),hmmEvList))

for itr in range(30,34):
        (tdir,tList,sList)=make_list(cList,itr)
        exe(tList,sList,
                #"""HERest -S %s -u tmvwap -L %s -M %s -H %s %s"""
                """HERest -S %s -u tmvw -L %s -M %s -H %s %s"""
                % (trainFile,labeldir,tdir, " -H ".join(sList),hmmList))


nCycles = itr + 1



More information about the Scons-users mailing list