Mananpoddarm
06/18/2020, 5:42 AMTfLiteTensorCopyFromBuffer(input_tensor, inputs as CValuesRef<*>, inputs.size as ULong)
"inputs" is of type Array<Any>. I want to extract the data from this "inputs" and feed it to tensorflow function(I am using cinterop to access tensorflow C API) but in runtime it throws me error as Array<Any> cannot be typecasted to CValuesRef<*>. I am asssuming there must be some function like "inputs.data" or something which can do the job. could anyone help me here please?Artyom Degtyarev [JB]
06/18/2020, 5:57 AMStableRef
class to create a reference onto your array, and then send it to C. Also, remember to dispose StableRef instance when it will become unnecessary.Mananpoddarm
06/18/2020, 6:17 AMArtyom Degtyarev [JB]
06/18/2020, 7:14 AMByteArray
for similar purposes, which is a) easier to get size measured with ordinary .size()
and b) can be converted to COpaquePointer by ByteArray.toCValues()
without StableRef usage.Mananpoddarm
06/18/2020, 7:54 AMArtyom Degtyarev [JB]
06/18/2020, 8:14 AMArray<Any>
here. If there is no such option, please tell me more about this collection content. Maybe the simplest would be just multiplying its byte size over array size.Mananpoddarm
06/18/2020, 10:12 AMval stableRef1 = StableRef.create(inputs)
val voidPtr1 = stableRef1.asCPointer()
TfLiteTensorCopyFromBuffer(input_tensor, voidPtr1 , 5u)
inputs is "Array<Any>" here. I am using 5u just to run the code but actually inputs.size() should go there and that size should be of type ULong and I think it should be the size of bytes inputs holdsArtyom Degtyarev [JB]
06/18/2020, 11:35 AMval a1: IntArray = intArrayOf(0,1)
val a2: Array<IntArray> = arrayOf(a1, a1)
val a3: Array<Array<IntArray>> = arrayOf(a2, a2)
val a4: Array<Array<Array<IntArray>>> = arrayOf(a3, a3)
val flatty: IntArray = a4.flatMap { return@flatMap it.map { it.map{it.toList()} } }.flatten().flatten().toIntArray()
println(flatty)
Then I was able to measure array size in bytes(as the documentation states here, Kotlin Int has size 4). Also, IntArray has .toCValues()
method, which might help.