Beispiel #1
0
        public static float train_networks(Network[] nets, int n, Data d, int interval)
        {
            int i;
            int batch        = nets[0].Batch;
            int subdivisions = nets[0].Subdivisions;

            Thread[]  threads = new Thread[n];
            float[][] errors  = new float[n][];

            float sum = 0;

            for (i = 0; i < n; ++i)
            {
                Data p = Data.get_data_part(d, i, n);
                errors[i]  = new float[1];
                threads[i] = train_network_in_thread(nets[i], p, errors[i]);
            }
            for (i = 0; i < n; ++i)
            {
                threads[i].Join();
                sum += errors[i][0];
            }
            //cudaDeviceSynchronize();
            if (get_current_batch(nets[0]) % interval == 0)
            {
                Console.Write("Syncing... ");
                sync_nets(nets, n, interval);
                Console.Write("Done!\n");
            }
            return(sum / (n));
        }