Upgrade to OPENRNDR 0.3.47, Javacpp 1.5.5, Tensorflow 0.3.1, Gradle 7.0

This commit is contained in:
Edwin Jakobs
2021-04-13 08:52:17 +02:00
parent d2c77a0ba4
commit a43a95b702
3 changed files with 37 additions and 42 deletions

View File

@@ -10,7 +10,7 @@ buildscript {
} }
} }
plugins { plugins {
id 'org.jetbrains.kotlin.jvm' version '1.4.31' id 'org.jetbrains.kotlin.jvm' version '1.4.32'
} }
def openrndrUseSnapshot = false def openrndrUseSnapshot = false
@@ -18,15 +18,15 @@ def openrndrUseSnapshot = false
apply plugin: 'org.jetbrains.dokka' apply plugin: 'org.jetbrains.dokka'
project.ext { project.ext {
openrndrVersion = openrndrUseSnapshot? "0.4.0-SNAPSHOT" : "0.3.47-rc.2" openrndrVersion = openrndrUseSnapshot? "0.4.0-SNAPSHOT" : "0.3.47"
kotlinVersion = "1.4.31" kotlinVersion = "1.4.31"
spekVersion = "2.0.15" spekVersion = "2.0.15"
libfreenectVersion = "0.5.7-1.5.4" libfreenectVersion = "0.5.7-1.5.5"
librealsense2Version = "2.29.0-1.5.4" librealsense2Version = "2.40.0-1.5.5"
gsonVersion = "2.8.6" gsonVersion = "2.8.6"
antlrVersion = "4.9.1" antlrVersion = "4.9.1"
tensorflowVersion = "0.2.0" tensorflowVersion = "0.3.1"
mklDnnVersion = "0.21.5-1.5.4" mklDnnVersion = "0.21.5-1.5.5"
} }
switch (org.gradle.internal.os.OperatingSystem.current()) { switch (org.gradle.internal.os.OperatingSystem.current()) {

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@@ -6,35 +6,38 @@ import org.openrndr.draw.ColorFormat
import org.openrndr.draw.ColorType import org.openrndr.draw.ColorType
import org.openrndr.draw.colorBuffer import org.openrndr.draw.colorBuffer
import org.openrndr.extra.tensorflow.arrays.* import org.openrndr.extra.tensorflow.arrays.*
import org.tensorflow.Output
import org.tensorflow.Tensor import org.tensorflow.Tensor
import org.tensorflow.ndarray.StdArrays import org.tensorflow.ndarray.StdArrays
import org.tensorflow.ndarray.buffer.DataBuffers import org.tensorflow.ndarray.buffer.DataBuffers
import org.tensorflow.op.math.Add
import org.tensorflow.types.* import org.tensorflow.types.*
import org.tensorflow.types.family.TType import org.tensorflow.types.family.TType
import java.nio.ByteBuffer import java.nio.ByteBuffer
import java.nio.ByteOrder import java.nio.ByteOrder
fun ColorBuffer.copyTo(tensor: Tensor<TFloat32>) { fun ColorBuffer.copyTo(tensor: TFloat32) {
val buffer = ByteBuffer.allocateDirect(effectiveWidth * effectiveHeight * format.componentCount * 4) val buffer = ByteBuffer.allocateDirect(effectiveWidth * effectiveHeight * format.componentCount * 4)
buffer.order(ByteOrder.nativeOrder()) buffer.order(ByteOrder.nativeOrder())
this.read(buffer, targetType = ColorType.FLOAT32) this.read(buffer, targetType = ColorType.FLOAT32)
buffer.rewind() buffer.rewind()
val dataBuffer = DataBuffers.of(buffer.asFloatBuffer()) val dataBuffer = DataBuffers.of(buffer.asFloatBuffer())
tensor.data().write(dataBuffer) tensor.write(dataBuffer)
} }
@JvmName("copyToTUint8") @JvmName("copyToTUint8")
fun ColorBuffer.copyTo(tensor: Tensor<TUint8>) { fun ColorBuffer.copyTo(tensor: TUint8) {
val buffer = ByteBuffer.allocateDirect(effectiveWidth * effectiveHeight * format.componentCount) val buffer = ByteBuffer.allocateDirect(effectiveWidth * effectiveHeight * format.componentCount)
buffer.order(ByteOrder.nativeOrder()) buffer.order(ByteOrder.nativeOrder())
this.read(buffer, targetType = ColorType.UINT8) this.read(buffer, targetType = ColorType.UINT8)
buffer.rewind() buffer.rewind()
val dataBuffer = DataBuffers.of(buffer) val dataBuffer = DataBuffers.of(buffer)
tensor.data().write(dataBuffer) tensor.write(dataBuffer)
} }
fun Tensor<TFloat32>.copyTo(colorBuffer: ColorBuffer) {
fun TFloat32.copyTo(colorBuffer: ColorBuffer) {
val s = shape() val s = shape()
val components = when { val components = when {
@@ -54,92 +57,84 @@ fun Tensor<TFloat32>.copyTo(colorBuffer: ColorBuffer) {
val buffer = ByteBuffer.allocateDirect(this.numBytes().toInt()) val buffer = ByteBuffer.allocateDirect(this.numBytes().toInt())
buffer.order(ByteOrder.nativeOrder()) buffer.order(ByteOrder.nativeOrder())
val dataBuffer = DataBuffers.of(buffer.asFloatBuffer()) val dataBuffer = DataBuffers.of(buffer.asFloatBuffer())
data().read(dataBuffer)
this.read(dataBuffer)
buffer.rewind() buffer.rewind()
colorBuffer.write(buffer, sourceFormat = format, sourceType = ColorType.FLOAT32) colorBuffer.write(buffer, sourceFormat = format, sourceType = ColorType.FLOAT32)
} }
fun TType.summary() {
fun <T : TType> Tensor<T>.summary() { println("type: ${this.dataType().name}")
println("type: ${this.dataType().name()}")
println("shape: [${this.shape().asArray().joinToString(", ")}]") println("shape: [${this.shape().asArray().joinToString(", ")}]")
} }
fun Tensor<TInt32>.toIntArray(): IntArray { fun TInt32.toIntArray(): IntArray {
val elementCount = this.numBytes() / 4 val elementCount = this.numBytes() / 4
val tensorData = data()
val targetArray = IntArray(elementCount.toInt()) val targetArray = IntArray(elementCount.toInt())
StdArrays.copyFrom(tensorData, targetArray) StdArrays.copyFrom(this, targetArray)
return targetArray return targetArray
} }
fun Tensor<TInt64>.toLongArray(): LongArray { fun TInt64.toLongArray(): LongArray {
val elementCount = this.numBytes() / 8 val elementCount = this.numBytes() / 8
val tensorData = data()
val targetArray = LongArray(elementCount.toInt()) val targetArray = LongArray(elementCount.toInt())
StdArrays.copyFrom(tensorData, targetArray) StdArrays.copyFrom(this, targetArray)
return targetArray return targetArray
} }
fun Tensor<TUint8>.toByteArray(): ByteArray { fun TUint8.toByteArray(): ByteArray {
val elementCount = this.numBytes() / 8 val elementCount = this.numBytes() / 8
val tensorData = data()
val targetArray = ByteArray(elementCount.toInt()) val targetArray = ByteArray(elementCount.toInt())
StdArrays.copyFrom(tensorData, targetArray) StdArrays.copyFrom(this, targetArray)
return targetArray return targetArray
} }
fun Tensor<TFloat32>.toFloatArray(): FloatArray { fun TFloat32.toFloatArray(): FloatArray {
val elementCount = this.numBytes() / 4 val elementCount = this.numBytes() / 4
val tensorData = data()
val targetArray = FloatArray(elementCount.toInt()) val targetArray = FloatArray(elementCount.toInt())
StdArrays.copyFrom(tensorData, targetArray) StdArrays.copyFrom(this, targetArray)
return targetArray return targetArray
} }
fun Tensor<TFloat32>.toFloatArray2D(): FloatArray2D { fun TFloat32.toFloatArray2D(): FloatArray2D {
val shape = this.shape() val shape = this.shape()
require(shape.numDimensions() == 2) { require(shape.numDimensions() == 2) {
"tensor has ${shape.numDimensions()} dimensions, need 2" "tensor has ${shape.numDimensions()} dimensions, need 2"
} }
val tensorData = data()
val targetArray = floatArray2D(shape.size(0).toInt(), shape.size(1).toInt()) val targetArray = floatArray2D(shape.size(0).toInt(), shape.size(1).toInt())
StdArrays.copyFrom(tensorData, targetArray) StdArrays.copyFrom(this, targetArray)
return targetArray return targetArray
} }
fun Tensor<TFloat32>.toFloatArray3D(): FloatArray3D { fun TFloat32.toFloatArray3D(): FloatArray3D {
val shape = this.shape() val shape = this.shape()
require(shape.numDimensions() == 3) { require(shape.numDimensions() == 3) {
"tensor has ${shape.numDimensions()} dimensions, need 3" "tensor has ${shape.numDimensions()} dimensions, need 3"
} }
val tensorData = data()
val targetArray = floatArray3D(shape.size(0).toInt(), shape.size(1).toInt(), shape.size(2).toInt()) val targetArray = floatArray3D(shape.size(0).toInt(), shape.size(1).toInt(), shape.size(2).toInt())
StdArrays.copyFrom(tensorData, targetArray) StdArrays.copyFrom(this, targetArray)
return targetArray return targetArray
} }
fun Tensor<TFloat32>.toFloatArray4D(): FloatArray4D { fun TFloat32.toFloatArray4D(): FloatArray4D {
val shape = this.shape() val shape = this.shape()
require(shape.numDimensions() == 4) { require(shape.numDimensions() == 4) {
"tensor has ${shape.numDimensions()} dimensions, need 4" "tensor has ${shape.numDimensions()} dimensions, need 4"
} }
val tensorData = data()
val targetArray = floatArray4D(shape.size(0).toInt(), shape.size(1).toInt(), shape.size(2).toInt(), shape.size(3).toInt()) val targetArray = floatArray4D(shape.size(0).toInt(), shape.size(1).toInt(), shape.size(2).toInt(), shape.size(3).toInt())
StdArrays.copyFrom(tensorData, targetArray) StdArrays.copyFrom(this, targetArray)
return targetArray return targetArray
} }
fun Tensor<TFloat64>.toDoubleArray(): DoubleArray { fun TFloat64.toDoubleArray(): DoubleArray {
val elementCount = this.numBytes() / 8 val elementCount = this.numBytes() / 8
val tensorData = data()
val targetArray = DoubleArray(elementCount.toInt()) val targetArray = DoubleArray(elementCount.toInt())
StdArrays.copyFrom(tensorData, targetArray) StdArrays.copyFrom(this, targetArray)
return targetArray return targetArray
} }
fun Tensor<TFloat32>.toColorBuffer(target: ColorBuffer? = null): ColorBuffer { fun TFloat32.toColorBuffer(target: ColorBuffer? = null): ColorBuffer {
val s = shape() val s = shape()
require(s.numDimensions() == 2 || s.numDimensions() == 3) require(s.numDimensions() == 2 || s.numDimensions() == 3)
@@ -168,7 +163,7 @@ fun Tensor<TFloat32>.toColorBuffer(target: ColorBuffer? = null): ColorBuffer {
@JvmName("toColorBufferTInt8") @JvmName("toColorBufferTInt8")
fun Tensor<TUint8>.toColorBuffer(target: ColorBuffer? = null): ColorBuffer { fun TUint8.toColorBuffer(target: ColorBuffer? = null): ColorBuffer {
val s = shape() val s = shape()
require(s.numDimensions() == 2 || s.numDimensions() == 3) require(s.numDimensions() == 2 || s.numDimensions() == 3)