/// <summary> /// Use the generator to create a list of fake images/ /// </summary> /// <param name="generator">The generator to use.</param> /// <param name="batchSize">The batch size.</param> /// <param name="latentDimensions">The number of dimensions in the latent input vector.</param> /// <returns>A list of images created by the generator.</returns> public static IList <IList <float> > GenerateImages( CNTK.Function generator, int batchSize, int latentDimensions) { // set up a Gaussian random number generator var random = new Random(); var gaussianRandom = new GaussianRandom(random); // set up randomized input for the generator var random_latent_vectors = gaussianRandom.getFloatSamples(batchSize * latentDimensions); var random_latent_vectors_nd = new CNTK.NDArrayView(new int[] { latentDimensions, 1, batchSize }, random_latent_vectors, NetUtil.CurrentDevice); var generator_inputs = new Dictionary <CNTK.Variable, CNTK.Value>() { { generator.Arguments[0], new CNTK.Value(random_latent_vectors_nd) } }; var generator_outputs = new Dictionary <CNTK.Variable, CNTK.Value>() { { generator.Output, null } }; // run the generator and collect the images generator.Evaluate(generator_inputs, generator_outputs, NetUtil.CurrentDevice); return(generator_outputs[generator.Output].GetDenseData <float>(generator.Output)); }
public static (CNTK.Value featureBatch, CNTK.Value labelBatch) GetMisleadingBatch( CNTK.Function gan, int batchSize, int latentDimensions) { // set up a Gaussian random number generator var random = new Random(); var gaussianRandom = new GaussianRandom(random); // prepare a batch to fool the discriminator: we generate fake images // but we label them as real with label=0 var random_latent_vectors = gaussianRandom.getFloatSamples(batchSize * latentDimensions); var misleading_targets = new float[batchSize]; var random_latent_vectors_nd = new CNTK.NDArrayView(new int[] { latentDimensions, 1, batchSize }, random_latent_vectors, NetUtil.CurrentDevice); // return results return( new CNTK.Value(random_latent_vectors_nd), CNTK.Value.CreateBatch(new CNTK.NDShape(0), misleading_targets, NetUtil.CurrentDevice, true) ); }