Code from TextureGrowth.scala:72 executed in 0.00 seconds (0.000 gc):
implicit val _ = log
log.setArchiveHome(URI.create(s"s3://$s3bucket/${getClass.getSimpleName.stripSuffix("$")}/${log.getId}/"))
log.onComplete(() => upload(log): Unit)
log.out(log.jpg(ImageArtUtil.load(log, styleUrl, (maxResolution * Math.sqrt(magnification)).toInt), "Input Style"))
val renderedCanvases = new ArrayBuffer[() => BufferedImage]
val registration = registerWithIndexGIF(renderedCanvases.map(_ ()), delay = animationDelay)
NotebookRunner.withMonitoredGif(() => {
renderedCanvases.map(_ ())
}, delay = animationDelay) {
try {
val pipeline = VGG16.getVisionPipeline
import scala.collection.JavaConverters._
for (layer <- pipeline.getLayers.asScala.keys) {
log.h1(layer.name())
for (numberOfSteps <- List(1, 2, 5)) {
log.h2(s"$numberOfSteps steps")
val canvas = new AtomicReference[Tensor](null)
renderedCanvases += (() => {
val image = ImageUtil.resize(canvas.get().toImage, maxResolution)
if (null == image) image else {
val graphics = image.getGraphics.asInstanceOf[Graphics2D]
graphics.setFont(new Font("Calibri", Font.BOLD, 24))
graphics.drawString(layer.name(), 10, 25)
graphics.drawString(s"$numberOfSteps steps", 10, image.getHeight - 10)
image
}
})
withMonitoredJpg(() => Option(canvas.get()).map(_.toRgbImage).orNull) {
var steps = 0
Try {
log.subreport(s"$numberOfSteps steps", (sub: NotebookOutput) => {
paint(styleUrl, initUrl, canvas, new VisualStyleNetwork(
styleLayers = List(layer),
styleModifiers = List(
new GramMatrixEnhancer(),
new MomentMatcher()
),
styleUrl = List(styleUrl),
magnification = magnification
), new BasicOptimizer {
override val trainingMinutes: Int = 60 / numberOfSteps
override val trainingIterations: Int = 30 / numberOfSteps
override val maxRate = 1e9
override def onStepComplete(trainable: Trainable, currentPoint: Step): Boolean = {
steps = steps + 1
super.onStepComplete(trainable, currentPoint)
}
}, new GeometricSequence {
override val min: Double = minResolution
override val max: Double = maxResolution
override val steps = numberOfSteps
}.toStream.map(_.round.toDouble): _*)(sub)
null
})
}
if (steps < 3 && !renderedCanvases.isEmpty) {
renderedCanvases.remove(renderedCanvases.size - 1)
}
uploadAsync(log)
}(log)
}
}
null
} finally {
registration.foreach(_.stop()(s3client, ec2client))
}
}
}
<function0>