Exemple #1
0
        public static void RemoveUnused(Model model, HashSet <string> keepLayers)
        {
            // TODO: strip layers not useful to compute output
            var preserve = new HashSet <string>(
                model.memories.Select(mem => mem.input).Concat(
                    model.memories.Select(mem => mem.output)).Concat(
                    model.outputs));

            // Strip unused layers
            var unusedLayers = new HashSet <string>(ModelAnalyzer.FindUnusedLayers(model));

            if (keepLayers != null) // Except explicitly specified for keeping
            {
                unusedLayers.ExceptWith(keepLayers);
            }
            model.layers = model.layers.Where(l => !unusedLayers.Contains(l.name) || preserve.Contains(l.name)).ToList();
        }
Exemple #2
0
        static public Model Optimize(Model model, bool allowFusing, HashSet <string> keepLayers = null)
        {
            // Strip unused layers
            var unusedLayers = new HashSet <string>(ModelAnalyzer.FindUnusedLayers(model));

            if (keepLayers != null) // Except explicitly specified for keeping
            {
                unusedLayers.ExceptWith(keepLayers);
            }
            model.layers = model.layers.Where(l => !unusedLayers.Contains(l.name)).ToList();

            if (allowFusing)
            {
                FuseActivations(model);
            }

            return(model);
        }