use of com.simiacryptus.mindseye.models.MultiLayerVGG19 in project MindsEye by SimiaCryptus.
the class StyleTransfer_VGG19 method run.
/**
* Test.
*
* @param log the log
*/
public void run(@Nonnull NotebookOutput log) {
StyleTransfer.VGG19 styleTransfer = new StyleTransfer.VGG19();
init(log);
Precision precision = Precision.Float;
int imageSize = 400;
styleTransfer.parallelLossFunctions = true;
double growthFactor = Math.sqrt(1.5);
CharSequence lakeAndForest = "H:\\SimiaCryptus\\Artistry\\Owned\\IMG_20170624_153541213-EFFECTS.jpg";
String monkey = "H:\\SimiaCryptus\\Artistry\\capuchin-monkey-2759768_960_720.jpg";
CharSequence vanGogh1 = "H:\\SimiaCryptus\\Artistry\\portraits\\vangogh\\Van_Gogh_-_Portrait_of_Pere_Tanguy_1887-8.jpg";
CharSequence vanGogh2 = "H:\\SimiaCryptus\\Artistry\\portraits\\vangogh\\800px-Vincent_van_Gogh_-_Dr_Paul_Gachet_-_Google_Art_Project.jpg";
CharSequence threeMusicians = "H:\\SimiaCryptus\\Artistry\\portraits\\picasso\\800px-Pablo_Picasso,_1921,_Nous_autres_musiciens_(Three_Musicians),_oil_on_canvas,_204.5_x_188.3_cm,_Philadelphia_Museum_of_Art.jpg";
CharSequence maJolie = "H:\\SimiaCryptus\\Artistry\\portraits\\picasso\\Ma_Jolie_Pablo_Picasso.jpg";
Map<List<CharSequence>, StyleTransfer.StyleCoefficients> styles = new HashMap<>();
double coeff_mean = 1e1;
double coeff_cov = 1e0;
styles.put(Arrays.asList(// threeMusicians, maJolie
vanGogh1, vanGogh2), new StyleTransfer.StyleCoefficients(StyleTransfer.CenteringMode.Origin).set(MultiLayerVGG19.LayerType.Layer_1b, coeff_mean, coeff_cov).set(MultiLayerVGG19.LayerType.Layer_1d, coeff_mean, coeff_cov));
StyleTransfer.ContentCoefficients contentCoefficients = new StyleTransfer.ContentCoefficients().set(MultiLayerVGG19.LayerType.Layer_1c, 1e0);
int trainingMinutes = 90;
log.h1("Phase 0");
BufferedImage canvasImage = ArtistryUtil.load(monkey, imageSize);
canvasImage = TestUtil.resize(canvasImage, imageSize, true);
canvasImage = TestUtil.resize(TestUtil.resize(canvasImage, 25, true), imageSize, true);
// canvasImage = randomize(canvasImage, x -> 10 * (FastRandom.INSTANCE.random()) * (FastRandom.INSTANCE.random() < 0.9 ? 1 : 0));
canvasImage = ArtistryUtil.randomize(canvasImage, x -> x + 2 * 1 * (FastRandom.INSTANCE.random() - 0.5));
// canvasImage = randomize(canvasImage, x -> 10*(FastRandom.INSTANCE.random()-0.5));
// canvasImage = randomize(canvasImage, x -> x*(FastRandom.INSTANCE.random()));
Map<CharSequence, BufferedImage> styleImages = new HashMap<>();
styleImages.clear();
styleImages.putAll(styles.keySet().stream().flatMap(x -> x.stream()).collect(Collectors.toMap(x -> x, file -> ArtistryUtil.load(file))));
StyleTransfer.StyleSetup styleSetup = new StyleTransfer.StyleSetup(precision, ArtistryUtil.load(monkey, canvasImage.getWidth(), canvasImage.getHeight()), contentCoefficients, styleImages, styles);
StyleTransfer.NeuralSetup measureStyle = styleTransfer.measureStyle(styleSetup);
canvasImage = styleTransfer.styleTransfer(server, log, canvasImage, styleSetup, trainingMinutes, measureStyle);
for (int i = 1; i < 10; i++) {
log.h1("Phase " + i);
imageSize = (int) (imageSize * growthFactor);
canvasImage = TestUtil.resize(canvasImage, imageSize, true);
canvasImage = styleTransfer.styleTransfer(server, log, canvasImage, styleSetup, trainingMinutes, measureStyle);
}
log.setFrontMatterProperty("status", "OK");
}
use of com.simiacryptus.mindseye.models.MultiLayerVGG19 in project MindsEye by SimiaCryptus.
the class DeepDream_VGG19 method run.
/**
* Test.
*
* @param log the log
*/
public void run(@Nonnull NotebookOutput log) {
DeepDream<MultiLayerVGG19.LayerType, MultiLayerVGG19> dreamBase = new DeepDream.VGG19();
init(log);
Precision precision = Precision.Float;
int imageSize = 800;
String lakeAndForest = "H:\\SimiaCryptus\\Artistry\\Owned\\IMG_20170624_153541213-EFFECTS.jpg";
CharSequence vanGogh = "H:\\SimiaCryptus\\Artistry\\portraits\\picasso\\800px-Pablo_Picasso,_1921,_Nous_autres_musiciens_(Three_Musicians),_oil_on_canvas,_204.5_x_188.3_cm,_Philadelphia_Museum_of_Art.jpg";
CharSequence threeMusicians = "H:\\SimiaCryptus\\Artistry\\portraits\\picasso\\800px-Pablo_Picasso,_1921,_Nous_autres_musiciens_(Three_Musicians),_oil_on_canvas,_204.5_x_188.3_cm,_Philadelphia_Museum_of_Art.jpg";
Map<MultiLayerVGG19.LayerType, DeepDream.ContentCoefficients> contentCoefficients = new HashMap<>();
contentCoefficients.put(MultiLayerVGG19.LayerType.Layer_1d, new DeepDream.ContentCoefficients(0, 1e-1));
// contentCoefficients.put(MultiLayerVGG19.LayerType.Layer_1e, new ContentCoefficients(0, 1e0));
contentCoefficients.put(MultiLayerVGG19.LayerType.Layer_2b, new DeepDream.ContentCoefficients(0, 1e0));
contentCoefficients.put(MultiLayerVGG19.LayerType.Layer_3a, new DeepDream.ContentCoefficients(0, 1e1));
int trainingMinutes = 180;
log.h1("Phase 0");
BufferedImage canvasImage = ArtistryUtil.load(lakeAndForest, imageSize);
// canvasImage = randomize(canvasImage);
canvasImage = TestUtil.resize(canvasImage, imageSize, true);
BufferedImage contentImage = ArtistryUtil.load(lakeAndForest, canvasImage.getWidth(), canvasImage.getHeight());
dreamBase.deepDream(server, log, canvasImage, new DeepDream.StyleSetup(precision, contentImage, contentCoefficients), trainingMinutes);
log.setFrontMatterProperty("status", "OK");
}
Aggregations