Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GaussianMixture"/> class.
 /// </summary>
 /// <param name="mixtureWeights">The mixture weights for this senone in LogMath log base.</param>
 /// <param name="mixtureComponents">The mixture components for this senone.</param>
 /// <param name="id">The identifier.</param>
 public GaussianMixture(GaussianWeights mixtureWeights, MixtureComponent[] mixtureComponents, int id)
 {
     LogMath            = LogMath.GetLogMath();
     _mixtureComponents = mixtureComponents;
     MixtureWeights     = mixtureWeights;
     _Id = id;
 }
Пример #2
0
        /**
         * /// Loads the mixture weights (Binary).
         * ///
         * /// @param path
         * ///            the path to the mixture weight file
         * /// @param floor
         * ///            the minimum mixture weight allowed
         * /// @return a pool of mixture weights
         * /// @throws FileNotFoundException
         * ///             if a file cannot be found
         * /// @throws IOException
         * ///             if an error occurs while loading the data
         */
        protected GaussianWeights LoadMixtureWeights(String path, float floor)
        {
            this.LogInfo("Loading mixture weights from: " + path);

            var props = new Dictionary <String, Object>(); //TODO: Use JProperties here

            var dis = ReadS3BinaryHeader(path, props);

            var version = props["version"].ToString();

            if (version == null || !version.Equals(MixwFileVersion))
            {
                throw new IOException("Unsupported version in " + path);
            }

            var checksum   = props["chksum0"].ToString();
            var doCheckSum = (checksum != null && checksum.Equals("yes"));

            ResetChecksum();

            var numStates            = readInt(dis);
            var numStreams           = readInt(dis);
            var numGaussiansPerState = readInt(dis);
            var numValues            = readInt(dis);
            var mixtureWeights       = new GaussianWeights(path, numStates, numGaussiansPerState, numStreams);

            this.LogInfo("Number of states " + numStates);
            this.LogInfo("Number of streams " + numStreams);
            this.LogInfo("Number of gaussians per state " + numGaussiansPerState);

            Debug.Assert(numValues == numStates * numStreams * numGaussiansPerState);

            for (var i = 0; i < numStates; i++)
            {
                for (var j = 0; j < numStreams; j++)
                {
                    var logStreamMixtureWeight = ReadFloatArray(dis,
                                                                numGaussiansPerState);
                    Utilities.Normalize(logStreamMixtureWeight);
                    Utilities.floorData(logStreamMixtureWeight, floor);
                    LogMath.LinearToLog(logStreamMixtureWeight);
                    mixtureWeights.Put(i, j, logStreamMixtureWeight);
                }
            }

            ValidateChecksum(dis, doCheckSum);

            dis.Close();
            return(mixtureWeights);
        }
Пример #3
0
        /// <summary>
        ///  Loads the AcousticModel from a directory in the file system.
        /// </summary>
        /// <param name="modelDef">the name of the acoustic modelDef; if null we just load from the default location</param>
        protected void LoadModelFiles(String modelDef)
        {
            this.LogInfo("Loading Sphinx3 acoustic model: " + modelDef);
            this.LogInfo("    modelName: " + Model);
            this.LogInfo("    dataLocation   : " + DataLocation);

            //TODO: datalocation is being ignored here

            MeansPool          = LoadDensityFile(Path.Combine(Location.Path, "means"), -Float.MAX_VALUE);
            VariancePool       = LoadDensityFile(Path.Combine(Location.Path, "variances"), VarianceFloor);
            MixtureWeightsPool = LoadMixtureWeights(Path.Combine(Location.Path, "mixture_weights"), MixtureWeightFloor);
            MatrixPool         = LoadTransitionMatrices(Path.Combine(Location.Path, "transition_matrices"));
            TransformMatrix    = LoadTransformMatrix(Path.Combine(Location.Path, "feature_transform"));
            Properties         = LoadModelProps(Path.Combine(Location.Path, "feat.params"));


            if (HasTiedMixtures())
            {
                GetSenoneToCIPhone();
                SenonePool = CreateTiedSenonePool(DistFloor, VarianceFloor);
            }
            else
            {
                //create regular senone poll
                SenonePool = CreateSenonePool(DistFloor, VarianceFloor);
            }

            // load the HMM modelDef file
            var modelStream = GetDataStream(Path.Combine(Location.Path, Model));

            if (modelStream == null)
            {
                throw new IOException("can't find modelDef " + Model);
            }
            LoadHMMPool(UseCDUnits, modelStream, Path.Combine(Location.Path, Model));

            // modelProps = loadModelProps(CurrentDir + "\\feat.params");
        }