I have trained a SVM in Python with scikit and used probabilities=true
model = svm.SVC(gamma=params["gamma"], C=params["C"], probability=True)
model.fit(X_train, y_train)
initial_type = [('float_input', FloatTensorType([None, X_train.shape[1]]))]
onnx_model = convert_sklearn(model, initial_types=initial_type,options={"zipmap": False}, target_opset=12)
And i have wrote a Android Class in kotlin for using it:
class Classifier(context: Context, modelFileName: String="") {
private val session: OrtSession
private val env: OrtEnvironment
init {
val modelBytes = context.resources.openRawResource(R.raw.svm_model2).readBytes()
env = OrtEnvironment.getEnvironment()
session = try {
env.createSession(modelBytes)
} catch (e: Exception) {
Log.e("Classifier", "Error initializing model: ${e.message}")
throw e
}
}
suspend fun runInference(inputData: FloatArray): String {
val inputName = session.inputNames?.iterator()?.next()
val floatBufferInputs = FloatBuffer.wrap(inputData)
val inputTensor = OnnxTensor.createTensor(env, floatBufferInputs, longArrayOf(1,inputData.size.toLong()))
val result = session.run(mapOf(inputName to inputTensor))
val re = result[0].value as Array<*>
val outputArray = re.map { it.toString() }.toTypedArray()
Log.v("classifier", outputArray.contentToString())
return outputArray.contentToString()
}
}
So when i use the kotlin Class, i get the correct label, but i want to get the probabilities as well, how can i do this?