Example #1
0
        private static void add_collection_def(MetaGraphDef meta_graph_def,
                                               string key,
                                               Graph graph         = null,
                                               string export_scope = "")
        {
            if (!meta_graph_def.CollectionDef.ContainsKey(key))
            {
                meta_graph_def.CollectionDef[key] = new CollectionDef();
            }
            var col_def = meta_graph_def.CollectionDef[key];

            col_def.NodeList  = new Types.NodeList();
            col_def.BytesList = new Types.BytesList();
            foreach (object value in graph.get_collection(key))
            {
                switch (value)
                {
                case RefVariable x:
                    var proto = x.to_proto(export_scope);
                    col_def.BytesList.Value.Add(proto.ToByteString());
                    break;

                case ITensorOrOperation x2:
                    col_def.NodeList.Value.Add(ops.strip_name_scope(x2.name, export_scope));
                    break;

                default:
                    break;
                }
            }
        }
Example #2
0
        private static void add_collection_def(MetaGraphDef meta_graph_def,
                                               string key,
                                               Graph graph         = null,
                                               string export_scope = "")
        {
            if (!meta_graph_def.CollectionDef.ContainsKey(key))
            {
                meta_graph_def.CollectionDef[key] = new CollectionDef();
            }
            var col_def = meta_graph_def.CollectionDef[key];

            switch (graph.get_collection(key))
            {
            case List <IVariableV1> collection_list:
                col_def.BytesList = new Types.BytesList();
                foreach (var x in collection_list)
                {
                    if (x is RefVariable x_ref_var)
                    {
                        var proto = x_ref_var.to_proto(export_scope);
                        col_def.BytesList.Value.Add(proto.ToByteString());
                    }
                    else if (x is ResourceVariable x_res_var)
                    {
                        var proto = x_res_var.to_proto(export_scope);
                        col_def.BytesList.Value.Add(proto.ToByteString());
                    }
                }
                break;

            case List <RefVariable> collection_list:
                col_def.BytesList = new Types.BytesList();
                foreach (var x in collection_list)
                {
                    var proto = x.to_proto(export_scope);
                    col_def.BytesList.Value.Add(proto.ToByteString());
                }

                break;

            case List <object> collection_list:
                col_def.NodeList = new Types.NodeList();
                foreach (var x in collection_list)
                {
                    if (x is ITensorOrOperation x2)
                    {
                        col_def.NodeList.Value.Add(ops.strip_name_scope(x2.name, export_scope));
                    }
                }
                break;

            case List <Operation> collection_list:
                break;
            }
        }