/// <summary> /// Run DeepDream processing. This will run the docker container and execute the processing for DeepDream images. /// </summary> /// <param name="image">Image to process</param> /// <param name="iterations">Number of iterations</param> /// <param name="scale">Normalized Scale Factor. Calculate by normalizedScale = 1 - (100/ScaleFact) where ScaleFact is in % (100% Current Size, 200% Double, ...)</param> /// <param name="intensity">Intensity</param> /// <param name="octave">Octave</param> /// <param name="model">Processing Model</param> /// <param name="rotate">Rotation in degrees</param> public void DeepDream(BitmapImage image, int iterations, double scale, double intensity, int octave, string model, double rotate) { Task.Factory.StartNew(() => { PrepareTask(image).ContinueWith(task => { var argString = $"/c {DockerModel.DockerStartAddition} docker run -v {DockerModel.PathToDockerPath(DataPath)}:/data -e INPUT={Path.GetFileName(currentImage)} -e ITER={iterations} -e OCTAVE={octave} -e INTENSITY={intensity.ToString(CultureInfo.InvariantCulture)} -e SCALE={scale.ToString(CultureInfo.InvariantCulture)} -e MODEL={model} -e ROTATE={rotate.ToString(CultureInfo.InvariantCulture)} muelmx/neuralart_exec python -u /deepdream/deepdream.py "; RunTask(argString); }); }); }
/// <summary> /// Run NeuralArt processing. This will run the docker container and execute the processing for NeuralArt images. /// Enable reduceSize and set a small maxsidelength so speed up processing. /// </summary> /// <param name="image">Image to process</param> /// <param name="style">Image style to apply</param> /// <param name="iterations">Number of iterations</param> /// <param name="reduceSize">Enable changing (reducing) of image size.</param> /// <param name="maxsidelength">Reduce long edge of Image to this value. Proportionally reduces small edge.</param> public void NeuralArt(BitmapImage image, BitmapImage style, int iterations, bool reduceSize, int maxsidelength) { Task.Factory.StartNew(() => { PrepareTask(image, style).ContinueWith(task => { int size = reduceSize ? maxsidelength : 0; var argString = $"/c {DockerModel.DockerStartAddition} docker run -v {DockerModel.PathToDockerPath(DataPath)}:/data muelmx/neuralart_exec /home/torch/install/bin/qlua /neuralart/main.lua --style {"/data/" + Path.GetFileName(styleImage)} --display_interval 0 --output_dir /data/output --content {"/data/" + Path.GetFileName(currentImage)} --num_iters {iterations} --size {size} --cpu"; RunTask(argString); }); }); }
/// <summary> /// Force image processing to stop. /// </summary> /// <returns>Task Object containig the running cancellation. Can be awaited.</returns> public Task Kill() { return(Task.Factory.StartNew(() => { //Ignore next exit code, if process is running and killed. ignoreNextExitCode = current != null; DeleteFile(currentImage); currentImage = String.Empty; DeleteFile(styleImage); styleImage = String.Empty; DockerModel.KillAndDeleteDockerContainer(); if (current == null) { return; } current = null; })); }