Android(kotlin), how getting assets file path? (at pytorch mobile)
I'm trying PyTorch Mobile tutorial by kotlin. I want to load module, "model.pt" in assets file. But no idea to load module in assets file.

Java (written in PyTorch Mobile Tutorial "hello world")

Module module = Module.load(assetFilePath(this, "model.pt"));


kotlin

val module = Module.load("?????")


Declare this function:

fun assetFilePath(context: Context, asset: String): String {
    val file = File(context.filesDir, asset)

    try {
        val inpStream: InputStream = context.assets.open(asset)
        try {
            val outStream = FileOutputStream(file, false)
            val buffer = ByteArray(4 * 1024)
            var read: Int

            while (true) {
                read = inpStream.read(buffer)
                if (read == -1) {
                    break
                }
                outStream.write(buffer, 0, read)
            }
            outStream.flush()
        } catch (ex: Exception) {
            e.printStackTrace()
        }
        return file.absolutePath
    } catch (e: Exception) {
        e.printStackTrace()
    }
    return ""
}


And then use it as:

val module = Module.load(assetFilePath(this, "model.pt"))

