Beispiel #1
0
        /// <summary>
        /// Creates network models based on ml configuration string or to create custom model in case
        /// custom model creation delegate function is defined
        /// </summary>
        /// <param name="strNetwork"></param>
        /// <param name="inputLayer"></param>
        /// <param name="outputVars"></param>
        /// <param name="customModel"></param>
        /// <param name="device"></param>
        /// <returns></returns>
        private static Function CreateNetworkModel(string strNetwork, List <Variable> inputLayer, List <Variable> outputVars, CreateCustomModel customModel, DeviceDescriptor device)
        {
            Function nnModel = null;

            //for custom implementation should use this string format
            if (strNetwork.StartsWith("|Custom") || strNetwork.StartsWith("|Layer:Custom"))
            {
                //Todo: Implementation of reflection needs to be implemented.
                //Two ways of calling customModels
                //by reflection when delegate is null mostly from Desktop application
                if (customModel == null)
                {
                    throw new Exception("Custom Model is not implemented!");
                }
                else//when using Console tool when the delegate is not null
                {
                    nnModel = customModel(inputLayer.Union(outputVars).ToList(), device);
                }
            }
            else
            {
                var Layers = MLFactory.CreateNetworkParameters(strNetwork);
                nnModel = MLFactory.CreateNetwrok(Layers, inputLayer, outputVars.First(), device);
            }

            return(nnModel);
        }