Ejemplo n.º 1
0
        public static IDataSource BuildTensors(GraphFactory graph, IDataSource existing, IReadOnlyList <Mnist.Image> images)
        {
            var dataTable = BrightWireProvider.CreateDataTableBuilder();

            dataTable.AddColumn(ColumnType.Tensor, "Image");
            dataTable.AddColumn(ColumnType.Vector, "Target", true);
            foreach (var image in images)
            {
                var data = image.AsFloatTensor;
                dataTable.Add(data.Tensor, data.Label);
            }
            if (existing != null)
            {
                return(existing.CloneWith(dataTable.Build()));
            }
            else
            {
                return(graph.CreateDataSource(dataTable.Build()));
            }
        }
Ejemplo n.º 2
0
        static IDataSource _BuildTensors(GraphFactory graph, IDataSource existing,
                                         IReadOnlyList <Mnist.Image> images)
        {
            // convolutional neural networks expect a 3D tensor => vector mapping
            var dataTable = BrightWireProvider.CreateDataTableBuilder();

            dataTable.AddColumn(ColumnType.Tensor, "Image");
            dataTable.AddColumn(ColumnType.Vector, "Target", isTarget: true);
            foreach (var image in images)
            {
                var data = image.AsFloatTensor;
                dataTable.Add(data.Tensor, data.Label);
            }

            // reuse the network used for training when building the test data source
            if (existing != null)
            {
                return(existing.CloneWith(dataTable.Build()));
            }
            return(graph.CreateDataSource(dataTable.Build()));
        }