Subreport: TiledTexture_8ea2d5bf-de02-4ba0-8417-728fc669c52a_log_com.simiacryptus.ref.lang.ReferenceCountingBase
Code from TiledTexture.scala:68 executed in 0.00 seconds (0.000 gc):
() => {
implicit val implicitLog = log
// First, basic configuration so we publish to our s3 site
log.setArchiveHome(URI.create(s"s3://$s3bucket/$className/${log.getId}/"))
log.onComplete(() => upload(log): Unit)
// Fetch image (user upload prompt) and display a rescaled copy
loadImages(log, styleUrl, (maxResolution * Math.sqrt(magnification)).toInt).foreach(img => log.p(log.jpg(img, "Input Style")))
val canvas = new RefAtomicReference[Tensor](null)
// Generates a pretiled image (e.g. 3x3) to display
def tiledCanvas = {
val input = canvas.get()
if (null == input) input else {
val layer = new ImgTileAssemblyLayer(rowsAndCols, rowsAndCols)
val result = layer.eval((1 to (rowsAndCols * rowsAndCols)).map(_ => input.addRef()): _*)
input.freeRef()
layer.freeRef()
val tensorList = result.getData
result.freeRef()
val tensor = tensorList.get(0)
tensorList.freeRef()
tensor
}
}
// Tiling layer used by the optimization engine.
// Expands the canvas by a small amount, using tile wrap to draw in the expanded boundary.
def tilingLayer(dims: Seq[Int]) = {
val paddingX = Math.min(256, Math.max(16, dims(0) / 2))
val paddingY = Math.min(256, Math.max(16, dims(1) / 2))
val layer = new ImgViewLayer(dims(0) + paddingX, dims(1) + paddingY, true)
layer.setOffsetX(-paddingX / 2)
layer.setOffsetY(-paddingY / 2)
layer
}
// Execute the main process while registered with the site index
val registration = registerWithIndexJPG(() => tiledCanvas)
try {
// Display a pre-tiled image inside the report itself
withMonitoredJpg(() => tiledCanvas.toImage) {
// Display an additional, non-tiled image of the canvas
withMonitoredJpg(() => Option(canvas.get()).map(_.toRgbImage).orNull) {
log.subreport("Painting", (sub: NotebookOutput) => {
paint(
contentUrl = initUrl,
initUrl = initUrl,
canvas = canvas,
network = new VisualStyleNetwork(
styleLayers = List(
// We select all the lower-level layers to achieve a good balance between speed and accuracy.
VGG16.VGG16_0b,
VGG16.VGG16_1a,
VGG16.VGG16_1b1,
VGG16.VGG16_1b2,
VGG16.VGG16_1c1,
VGG16.VGG16_1c2,
VGG16.VGG16_1c3
),
styleModifiers = List(
// These two operators are a good combination for a vivid yet accurate style
new GramMatrixEnhancer(),
new MomentMatcher()
),
styleUrls = Option(styleUrl),
magnification = magnification,
viewLayer = tilingLayer
),
optimizer = new BasicOptimizer {
override val trainingMinutes: Int = 60
override val trainingIterations: Int = 15
override val maxRate = 1e9
},
aspect = Option(aspectRatio),
resolutions = new GeometricSequence {
override val min: Double = minResolution
override val max: Double = maxResolution
override val steps = TiledTexture.this.steps
}.toStream.map(_.round.toDouble)
)(sub)
null
})
}(log)
}
null
} finally {
registration.foreach(_.stop()(s3client, ec2client))
}
}
<function0>