TextureTiledRotor.scala:79 executed in 0.00 seconds (0.000 gc):
() => {
implicit val implicitLog = log
// First, basic configuration so we publish to our s3 site
if (Option(s3bucket).filter(!_.isEmpty).isDefined) {
log.setArchiveHome(URI.create(s"s3://$s3bucket/$className/${log.getId}/"))
log.onComplete(() => upload(log): Unit)
}
ImageArtUtil.loadImages(log, styleUrl, (maxResolution * Math.sqrt(magnification)).toInt)
.foreach(img => log.p(log.jpg(img, "Input Style")))
(1 to repeat).map(_ => {
val canvas = new RefAtomicReference[Tensor](null)
def rotatedCanvas = {
var input = canvas.get()
if (null == input) input else {
val viewLayer = getKaleidoscope(input.getDimensions)
val result = viewLayer.eval(input)
viewLayer.freeRef()
val data = result.getData
result.freeRef()
val tensor = data.get(0)
data.freeRef()
tensor
}
}
// Generates a pretiled image (e.g. 3x3) to display
def tiledCanvas = {
var input = rotatedCanvas
if (null == input) input else {
val layer = new ImgTileAssemblyLayer(rowsAndCols, rowsAndCols)
val result = layer.eval((1 to (rowsAndCols * rowsAndCols)).map(_ => input.addRef()): _*)
layer.freeRef()
input.freeRef()
val data = result.getData
result.freeRef()
val tensor = data.get(0)
data.freeRef()
tensor
}
}
// Kaleidoscope+Tiling layer used by the optimization engine.
// Expands the canvas by a small amount, using tile wrap to draw in the expanded boundary.
def viewLayer(dims: Seq[Int]) = {
val rotor = getKaleidoscope(dims.toArray)
val paddingX = Math.min(max_padding, Math.max(min_padding, dims(0) * border_factor)).toInt
val paddingY = Math.min(max_padding, Math.max(min_padding, dims(1) * border_factor)).toInt
val tiling = new ImgViewLayer(dims(0) + paddingX, dims(1) + paddingY, true)
tiling.setOffsetX(-paddingX / 2)
tiling.setOffsetY(-paddingY / 2)
rotor.add(tiling).freeRef()
rotor
}
// 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(() => {
val tiledCanvas1 = tiledCanvas
val toImage = tiledCanvas1.toImage
tiledCanvas1.freeRef()
toImage
}) {
// Display an additional, non-tiled image of the canvas
withMonitoredJpg(() => Option(rotatedCanvas).map(tensor => {
val image = tensor.toRgbImage
tensor.freeRef()
image
}).orNull) {
log.subreport("Painting", (sub: NotebookOutput) => {
paint(
contentUrl = initUrl,
initUrl = initUrl,
canvas = canvas.addRef(),
network = getStyle(viewLayer _),
optimizer = new BasicOptimizer {
override val trainingMinutes: Int = 90
override val trainingIterations: Int = iterations
override val maxRate = 1e9
override def trustRegion(layer: Layer): TrustRegion = null
override def renderingNetwork(dims: Seq[Int]) = getKaleidoscope(dims.toArray)
},
aspect = Option(aspectRatio),
resolutions = new GeometricSequence {
override val min: Double = minResolution
override val max: Double = maxResolution
override val steps = TextureTiledRotor.this.steps
}.toStream.map(_.round.toDouble))(sub)
null
})
uploadAsync(log)
}(log)
}
canvas.get()
} finally {
registration.foreach(_.stop()(s3client, ec2client))
}
})
}
Returns
{ }