diff --git a/orx-jvm/orx-tensorflow-gpu-natives-linux-x64/build.gradle.kts b/orx-jvm/orx-tensorflow-gpu-natives-linux-x64/build.gradle.kts deleted file mode 100644 index 79b59dcf..00000000 --- a/orx-jvm/orx-tensorflow-gpu-natives-linux-x64/build.gradle.kts +++ /dev/null @@ -1,6 +0,0 @@ -plugins { - org.openrndr.extra.convention.`kotlin-jvm` -} -dependencies { - runtimeOnly(variantOf(libs.tensorflow) { classifier("linux-x86_64-gpu") }) -} \ No newline at end of file diff --git a/orx-jvm/orx-tensorflow-gpu-natives-windows/build.gradle.kts b/orx-jvm/orx-tensorflow-gpu-natives-windows/build.gradle.kts deleted file mode 100644 index 85adcb0c..00000000 --- a/orx-jvm/orx-tensorflow-gpu-natives-windows/build.gradle.kts +++ /dev/null @@ -1,6 +0,0 @@ -plugins { - org.openrndr.extra.convention.`kotlin-jvm` -} -dependencies { - runtimeOnly(variantOf(libs.tensorflow) { classifier("windows-x86_64-gpu") }) -} \ No newline at end of file diff --git a/orx-jvm/orx-tensorflow-natives-linux-x64/build.gradle.kts b/orx-jvm/orx-tensorflow-natives-linux-x64/build.gradle.kts deleted file mode 100644 index 7fcedf92..00000000 --- a/orx-jvm/orx-tensorflow-natives-linux-x64/build.gradle.kts +++ /dev/null @@ -1,6 +0,0 @@ -plugins { - org.openrndr.extra.convention.`kotlin-jvm` -} -dependencies { - runtimeOnly(variantOf(libs.tensorflow) { classifier("linux-x86_64") }) -} \ No newline at end of file diff --git a/orx-jvm/orx-tensorflow-natives-macos/build.gradle.kts b/orx-jvm/orx-tensorflow-natives-macos/build.gradle.kts deleted file mode 100644 index 3bda1315..00000000 --- a/orx-jvm/orx-tensorflow-natives-macos/build.gradle.kts +++ /dev/null @@ -1,6 +0,0 @@ -plugins { - org.openrndr.extra.convention.`kotlin-jvm` -} -dependencies { - runtimeOnly(variantOf(libs.tensorflow) { classifier("macosx-x86_64") }) -} \ No newline at end of file diff --git a/orx-jvm/orx-tensorflow-natives-windows/build.gradle.kts b/orx-jvm/orx-tensorflow-natives-windows/build.gradle.kts deleted file mode 100644 index 4b13838c..00000000 --- a/orx-jvm/orx-tensorflow-natives-windows/build.gradle.kts +++ /dev/null @@ -1,6 +0,0 @@ -plugins { - org.openrndr.extra.convention.`kotlin-jvm` -} -dependencies { - runtimeOnly(variantOf(libs.tensorflow) { classifier("windows-x86_64") }) -} \ No newline at end of file diff --git a/orx-jvm/orx-tensorflow/build.gradle.kts b/orx-jvm/orx-tensorflow/build.gradle.kts deleted file mode 100644 index 9fdcbecd..00000000 --- a/orx-jvm/orx-tensorflow/build.gradle.kts +++ /dev/null @@ -1,10 +0,0 @@ -plugins { - org.openrndr.extra.convention.`kotlin-jvm` -} - -dependencies { - implementation(libs.gson) - implementation(libs.openrndr.application) - implementation(libs.openrndr.math) - api(libs.tensorflow) -} \ No newline at end of file diff --git a/orx-jvm/orx-tensorflow/src/main/kotlin/Tensor.kt b/orx-jvm/orx-tensorflow/src/main/kotlin/Tensor.kt deleted file mode 100644 index a495ad39..00000000 --- a/orx-jvm/orx-tensorflow/src/main/kotlin/Tensor.kt +++ /dev/null @@ -1,188 +0,0 @@ -package org.openrndr.extra.tensorflow - - -import org.openrndr.draw.ColorBuffer -import org.openrndr.draw.ColorFormat -import org.openrndr.draw.ColorType -import org.openrndr.draw.colorBuffer -import org.openrndr.extra.tensorflow.arrays.* -import org.tensorflow.ndarray.StdArrays -import org.tensorflow.ndarray.buffer.DataBuffers -import org.tensorflow.types.* -import org.tensorflow.types.family.TType -import java.nio.ByteBuffer -import java.nio.ByteOrder - -fun ColorBuffer.copyTo(tensor: TFloat32) { - val buffer = ByteBuffer.allocateDirect(effectiveWidth * effectiveHeight * format.componentCount * 4) - buffer.order(ByteOrder.nativeOrder()) - this.read(buffer, targetType = ColorType.FLOAT32) - buffer.rewind() - val dataBuffer = DataBuffers.of(buffer.asFloatBuffer()) - tensor.write(dataBuffer) -} - -@JvmName("copyToTUint8") -fun ColorBuffer.copyTo(tensor: TUint8) { - val buffer = ByteBuffer.allocateDirect(effectiveWidth * effectiveHeight * format.componentCount) - buffer.order(ByteOrder.nativeOrder()) - this.read(buffer, targetType = ColorType.UINT8) - buffer.rewind() - val dataBuffer = DataBuffers.of(buffer) - tensor.write(dataBuffer) -} - - - -fun TFloat32.copyTo(colorBuffer: ColorBuffer) { - val s = shape() - - val components = when { - s.numDimensions() == 2 -> 1 - s.numDimensions() == 3 -> s.get(2).toInt() - s.numDimensions() == 4 -> s.get(3).toInt() - else -> error("can't copy to colorbuffer from ${s.numDimensions()}D tensor") - } - - val format = when (components) { - 4 -> ColorFormat.RGBa - 3 -> ColorFormat.RGB - 2 -> ColorFormat.RG - 1 -> ColorFormat.R - else -> error("only supports 1, 2, 3, or 4 components") - } - val buffer = ByteBuffer.allocateDirect(this.numBytes().toInt()) - buffer.order(ByteOrder.nativeOrder()) - - val dataBuffer = DataBuffers.of(buffer.asFloatBuffer()) - - this.read(dataBuffer) - buffer.rewind() - colorBuffer.write(buffer, sourceFormat = format, sourceType = ColorType.FLOAT32) -} - -fun TType.summary() { - println("type: ${this.dataType().name}") - println("shape: [${this.shape().asArray().joinToString(", ")}]") -} - -fun TInt32.toIntArray(): IntArray { - val elementCount = this.numBytes() / 4 - val targetArray = IntArray(elementCount.toInt()) - StdArrays.copyFrom(this, targetArray) - return targetArray -} - -fun TInt64.toLongArray(): LongArray { - val elementCount = this.numBytes() / 8 - val targetArray = LongArray(elementCount.toInt()) - StdArrays.copyFrom(this, targetArray) - return targetArray -} - -fun TUint8.toByteArray(): ByteArray { - val elementCount = this.numBytes() / 8 - val targetArray = ByteArray(elementCount.toInt()) - StdArrays.copyFrom(this, targetArray) - return targetArray -} - - -fun TFloat32.toFloatArray(): FloatArray { - val elementCount = this.numBytes() / 4 - val targetArray = FloatArray(elementCount.toInt()) - StdArrays.copyFrom(this, targetArray) - return targetArray -} - -fun TFloat32.toFloatArray2D(): FloatArray2D { - val shape = this.shape() - require(shape.numDimensions() == 2) { - "tensor has ${shape.numDimensions()} dimensions, need 2" - } - val targetArray = floatArray2D(shape.get(0).toInt(), shape.get(1).toInt()) - StdArrays.copyFrom(this, targetArray) - return targetArray -} - -fun TFloat32.toFloatArray3D(): FloatArray3D { - val shape = this.shape() - require(shape.numDimensions() == 3) { - "tensor has ${shape.numDimensions()} dimensions, need 3" - } - val targetArray = floatArray3D(shape.get(0).toInt(), shape.get(1).toInt(), shape.get(2).toInt()) - StdArrays.copyFrom(this, targetArray) - return targetArray -} - -fun TFloat32.toFloatArray4D(): FloatArray4D { - val shape = this.shape() - require(shape.numDimensions() == 4) { - "tensor has ${shape.numDimensions()} dimensions, need 4" - } - val targetArray = floatArray4D(shape.get(0).toInt(), shape.get(1).toInt(), shape.get(2).toInt(), shape.get(3).toInt()) - StdArrays.copyFrom(this, targetArray) - return targetArray -} - -fun TFloat64.toDoubleArray(): DoubleArray { - val elementCount = this.numBytes() / 8 - val targetArray = DoubleArray(elementCount.toInt()) - StdArrays.copyFrom(this, targetArray) - return targetArray -} - -fun TFloat32.toColorBuffer(target: ColorBuffer? = null): ColorBuffer { - val s = shape() - require(s.numDimensions() == 2 || s.numDimensions() == 3) - - val width = (if (s.numDimensions() == 3) s.get(1) else s.get(0)).toInt() - val height = (if (s.numDimensions() == 3) s.get(2) else s.get(1)).toInt() - val components = if (s.numDimensions() == 3) s.get(0).toInt() else 1 - - val format = when (components) { - 4 -> ColorFormat.RGBa - 3 -> ColorFormat.RGB - 2 -> ColorFormat.RG - 1 -> ColorFormat.R - else -> error("only supports 1, 2, 3, or 4 components") - } - - val targetColorBuffer = target?: colorBuffer(width, height, format = format, type = ColorType.FLOAT32) - val floatArray = toFloatArray() - val bb = ByteBuffer.allocateDirect(width * height * components * 4) - bb.order(ByteOrder.nativeOrder()) - val fb = bb.asFloatBuffer() - fb.put(floatArray) - bb.rewind() - targetColorBuffer.write(bb) - return targetColorBuffer -} - - -@JvmName("toColorBufferTInt8") -fun TUint8.toColorBuffer(target: ColorBuffer? = null): ColorBuffer { - val s = shape() - require(s.numDimensions() == 2 || s.numDimensions() == 3) - - val width = (if (s.numDimensions() == 3) s.get(1) else s.get(0)).toInt() - val height = (if (s.numDimensions() == 3) s.get(2) else s.get(1)).toInt() - val components = if (s.numDimensions() == 3) s.get(0).toInt() else 1 - - val format = when (components) { - 4 -> ColorFormat.RGBa - 3 -> ColorFormat.RGB - 2 -> ColorFormat.RG - 1 -> ColorFormat.R - else -> error("only supports 1, 2, 3, or 4 components") - } - - val byteArray = toByteArray() - val targetColorBuffer = target?: colorBuffer(width, height, format = format, type = ColorType.UINT8) - val bb = ByteBuffer.allocateDirect(width * height * components ) - bb.order(ByteOrder.nativeOrder()) - bb.put(byteArray) - bb.rewind() - targetColorBuffer.write(bb) - return targetColorBuffer -} diff --git a/orx-jvm/orx-tensorflow/src/main/kotlin/arrays/Arrays.kt b/orx-jvm/orx-tensorflow/src/main/kotlin/arrays/Arrays.kt deleted file mode 100644 index db79826d..00000000 --- a/orx-jvm/orx-tensorflow/src/main/kotlin/arrays/Arrays.kt +++ /dev/null @@ -1,83 +0,0 @@ -package org.openrndr.extra.tensorflow.arrays - -typealias FloatArray2D = Array -typealias FloatArray3D = Array> -typealias FloatArray4D = Array>> -typealias FloatArray5D = Array>>> -typealias FloatArray6D = Array>>>> - -typealias IntArray2D = Array -typealias IntArray3D = Array> -typealias IntArray4D = Array>> -typealias IntArray5D = Array>>> -typealias IntArray6D = Array>>>> - -typealias BooleanArray2D = Array -typealias BooleanArray3D = Array> -typealias BooleanArray4D = Array>> -typealias BooleanArray5D = Array>>> -typealias BooleanArray6D = Array>>>> - -typealias LongArray2D = Array -typealias LongArray3D = Array> -typealias LongArray4D = Array>> -typealias LongArray5D = Array>>> -typealias LongArray6D = Array>>>> - -typealias ByteArray2D = Array -typealias ByteArray3D = Array> -typealias ByteArray4D = Array>> -typealias ByteArray5D = Array>>> -typealias ByteArray6D = Array>>>> - -typealias DoubleArray2D = Array -typealias DoubleArray3D = Array> -typealias DoubleArray4D = Array>> -typealias DoubleArray5D = Array>>> -typealias DoubleArray6D = Array>>>> - -fun floatArray2D(y: Int, x: Int): FloatArray2D = Array(y) { FloatArray(x) } -fun floatArray3D(z: Int, y: Int, x: Int): FloatArray3D = Array(z) { Array(y) { FloatArray(x) } } -fun floatArray4D(w: Int, z: Int, y: Int, x: Int): FloatArray4D = Array(w) { Array(z) { Array(y) { FloatArray(x) } } } - -fun doubleArray2D(y: Int, x: Int): DoubleArray2D = Array(y) { DoubleArray(x) } -fun doubleArray3D(z: Int, y: Int, x: Int): DoubleArray3D = Array(z) { Array(y) { DoubleArray(x) } } -fun doubleArray4D(w: Int, z: Int, y: Int, x: Int): DoubleArray4D = Array(w) { Array(z) { Array(y) { DoubleArray(x) } } } - -fun intArray2D(y: Int, x: Int): IntArray2D = Array(y) { IntArray(x) } -fun intArray3D(z: Int, y: Int, x: Int): IntArray3D = Array(z) { Array(y) { IntArray(x) } } -fun intArray4D(w: Int, z: Int, y: Int, x: Int): IntArray4D = Array(w) { Array(z) { Array(y) { IntArray(x) } } } - -fun longArray2D(y: Int, x: Int): LongArray2D = Array(y) { LongArray(x) } -fun longArray3D(z: Int, y: Int, x: Int): LongArray3D = Array(z) { Array(y) { LongArray(x) } } -fun longArray4D(w: Int, z: Int, y: Int, x: Int): LongArray4D = Array(w) { Array(z) { Array(y) { LongArray(x) } } } - -fun byteArray2D(y: Int, x: Int): ByteArray2D = Array(y) { ByteArray(x) } -fun byteArray3D(z: Int, y: Int, x: Int): ByteArray3D = Array(z) { Array(y) { ByteArray(x) } } -fun byteArray4D(w: Int, z: Int, y: Int, x: Int): ByteArray4D = Array(w) { Array(z) { Array(y) { ByteArray(x) } } } - -fun booleanArray2D(y: Int, x: Int): BooleanArray2D = Array(y) { BooleanArray(x) } -fun booleanArray3D(z: Int, y: Int, x: Int): BooleanArray3D = Array(z) { Array(y) { BooleanArray(x) } } -fun booleanArray4D(w: Int, z: Int, y: Int, x: Int): BooleanArray4D = Array(w) { Array(z) { Array(y) { BooleanArray(x) } } } - -operator fun FloatArray2D.get(y: Int, x: Int) = this[y][x] -operator fun FloatArray3D.get(z: Int, y: Int, x: Int) = this[z][y][x] -operator fun FloatArray4D.get(w: Int, z: Int, y: Int, x: Int) = this[w][z][y][x] - -operator fun DoubleArray2D.get(y: Int, x: Int) = this[y][x] -operator fun DoubleArray3D.get(z: Int, y: Int, x: Int) = this[z][y][x] -operator fun DoubleArray4D.get(w: Int, z: Int, y: Int, x: Int) = this[w][z][y][x] - -operator fun IntArray2D.get(y: Int, x: Int) = this[y][x] -operator fun IntArray3D.get(z: Int, y: Int, x: Int) = this[z][y][x] -operator fun IntArray4D.get(w: Int, z: Int, y: Int, x: Int) = this[w][z][y][x] - -operator fun LongArray2D.get(y: Int, x: Int) = this[y][x] -operator fun LongArray3D.get(z: Int, y: Int, x: Int) = this[z][y][x] -operator fun LongArray4D.get(w: Int, z: Int, y: Int, x: Int) = this[w][z][y][x] - -operator fun ByteArray2D.get(y: Int, x: Int) = this[y][x] -operator fun ByteArray3D.get(z: Int, y: Int, x: Int) = this[z][y][x] -operator fun ByteArray4D.get(w: Int, z: Int, y: Int, x: Int) = this[w][z][y][x] - - diff --git a/settings.gradle.kts b/settings.gradle.kts index 565a1f3a..08515b0b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -72,12 +72,6 @@ include( "orx-svg", "orx-jvm:orx-syphon", "orx-temporal-blur", - "orx-jvm:orx-tensorflow", - "orx-jvm:orx-tensorflow-gpu-natives-linux-x64", - "orx-jvm:orx-tensorflow-gpu-natives-windows", - "orx-jvm:orx-tensorflow-natives-linux-x64", - "orx-jvm:orx-tensorflow-natives-macos", - "orx-jvm:orx-tensorflow-natives-windows", "orx-timer", "orx-time-operators", "orx-triangulation",