diff --git a/app/src/main/java/ru/gordinmitya/dnnbenchmark/MainActivity.kt b/app/src/main/java/ru/gordinmitya/dnnbenchmark/MainActivity.kt index 882ace2..cef84bb 100644 --- a/app/src/main/java/ru/gordinmitya/dnnbenchmark/MainActivity.kt +++ b/app/src/main/java/ru/gordinmitya/dnnbenchmark/MainActivity.kt @@ -85,7 +85,7 @@ class MainActivity : AppCompatActivity() { delay(sleep) configurations.forEach { configuration -> logger.spoiler("Running with ${configuration.inferenceFramework} on ${configuration.inferenceType}…") - val result = + val result: InferenceResult = if (!configuration.inferenceType.isSupported) { NotSupportedResult(ConfigurationEntity(configuration)) } else { diff --git a/app/src/main/java/ru/gordinmitya/dnnbenchmark/benchmark/InferenceResult.kt b/app/src/main/java/ru/gordinmitya/dnnbenchmark/benchmark/InferenceResult.kt index 655f989..3739dea 100644 --- a/app/src/main/java/ru/gordinmitya/dnnbenchmark/benchmark/InferenceResult.kt +++ b/app/src/main/java/ru/gordinmitya/dnnbenchmark/benchmark/InferenceResult.kt @@ -9,7 +9,7 @@ sealed class InferenceResult : Parcelable { override fun toString(): String = configuration.run { val taskLetter = configuration.task[0].uppercaseChar() - return "$taskLetter $frameworkName $inferenceType" + return "$taskLetter $frameworkName-$frameworkVersion $inferenceType" } } diff --git a/app/src/main/java/ru/gordinmitya/dnnbenchmark/model/ConfigurationEntity.kt b/app/src/main/java/ru/gordinmitya/dnnbenchmark/model/ConfigurationEntity.kt index bf7a0d3..79c6fe4 100644 --- a/app/src/main/java/ru/gordinmitya/dnnbenchmark/model/ConfigurationEntity.kt +++ b/app/src/main/java/ru/gordinmitya/dnnbenchmark/model/ConfigurationEntity.kt @@ -1,7 +1,7 @@ package ru.gordinmitya.dnnbenchmark.model import android.os.Parcelable -import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parcelize import ru.gordinmitya.common.Configuration import ru.gordinmitya.dnnbenchmark.App import java.util.* @@ -9,6 +9,7 @@ import java.util.* @Parcelize class ConfigurationEntity( val frameworkName: String, + val frameworkVersion: String, val frameworkClassName: String, val inferenceType: String, val isSupported: Boolean, @@ -18,10 +19,11 @@ class ConfigurationEntity( constructor(configuration: Configuration) : this( frameworkName = configuration.inferenceFramework.name, + frameworkVersion = configuration.inferenceFramework.version.toString(), frameworkClassName = App.describeFramework(configuration.inferenceFramework.javaClass.kotlin), inferenceType = configuration.inferenceType.name, isSupported = configuration.inferenceType.isSupported, - task = configuration.model.task.name.toLowerCase(Locale.ROOT), + task = configuration.model.task.name.lowercase(Locale.ROOT), model = configuration.model.name ) @@ -35,4 +37,4 @@ class ConfigurationEntity( } return Configuration(frameworkInstance, type, model) } -} \ No newline at end of file +} diff --git a/common/src/main/java/ru/gordinmitya/common/InferenceFramework.kt b/common/src/main/java/ru/gordinmitya/common/InferenceFramework.kt index cbe60a0..1d7fda3 100644 --- a/common/src/main/java/ru/gordinmitya/common/InferenceFramework.kt +++ b/common/src/main/java/ru/gordinmitya/common/InferenceFramework.kt @@ -1,8 +1,18 @@ package ru.gordinmitya.common +class Version( + val name: String, + val commitHash: String? = null, +) { + override fun toString(): String { + if (commitHash == null) return name + return "$name ($commitHash)" + } +} + abstract class InferenceFramework( val name: String, - val description: String + val version: Version ) { abstract fun getModels(): List abstract fun getInferenceTypes(): List diff --git a/common/src/main/java/ru/gordinmitya/common/NativeHelper.kt b/common/src/main/java/ru/gordinmitya/common/NativeHelper.kt index 3103437..39c6bf6 100644 --- a/common/src/main/java/ru/gordinmitya/common/NativeHelper.kt +++ b/common/src/main/java/ru/gordinmitya/common/NativeHelper.kt @@ -5,7 +5,7 @@ import android.util.Log import java.io.* object NativeHelper { - private fun processName(): String? { + private fun processName(): String { val path = "/proc/" + Process.myPid() + "/cmdline" BufferedReader(InputStreamReader(FileInputStream(path), "iso-8859-1")).use { reader -> var c: Int @@ -26,4 +26,4 @@ object NativeHelper { ) System.loadLibrary(libname!!) } -} \ No newline at end of file +} diff --git a/common/src/test/java/ru/gordinmitya/common/ConfigurationTest.kt b/common/src/test/java/ru/gordinmitya/common/ConfigurationTest.kt index 74619a7..519d666 100644 --- a/common/src/test/java/ru/gordinmitya/common/ConfigurationTest.kt +++ b/common/src/test/java/ru/gordinmitya/common/ConfigurationTest.kt @@ -1,11 +1,9 @@ package ru.gordinmitya.common -import android.content.Context import io.mockk.mockk import org.junit.jupiter.api.Assertions.assertDoesNotThrow import org.junit.jupiter.api.Assertions.assertThrows import org.junit.jupiter.api.Test -import ru.gordinmitya.common.classification.Classifier internal class ConfigurationTest { private fun createFramework(): InferenceFramework { @@ -17,15 +15,10 @@ internal class ConfigurationTest { mockk(), mockk() ) - return object : InferenceFramework("", "") { + return object : InferenceFramework("", Version("?")) { override fun getInferenceTypes(): List = types override fun getModels(): List = models - - override fun createClassifier( - context: Context, - configuration: Configuration - ): Classifier = mockk() } } @@ -55,4 +48,4 @@ internal class ConfigurationTest { Configuration(framework, otherInferenceType, framework.getModels()[0]) } } -} \ No newline at end of file +} diff --git a/mnn/src/main/java/ru/gordinmitya/mnn/MNNFramework.kt b/mnn/src/main/java/ru/gordinmitya/mnn/MNNFramework.kt index bb9ff29..5e92c86 100644 --- a/mnn/src/main/java/ru/gordinmitya/mnn/MNNFramework.kt +++ b/mnn/src/main/java/ru/gordinmitya/mnn/MNNFramework.kt @@ -9,7 +9,7 @@ import ru.gordinmitya.common.segmentation.SegmentationFramework import ru.gordinmitya.common.segmentation.SegmentationModel import ru.gordinmitya.common.segmentation.Segmentator -class MNNFramework : InferenceFramework("MNN", "by Alibaba"), ClassificationFramework, +class MNNFramework : InferenceFramework("MNN", Version("?")), ClassificationFramework, SegmentationFramework { private val TYPES = arrayListOf( CPU, @@ -42,4 +42,4 @@ class MNNFramework : InferenceFramework("MNN", "by Alibaba"), ClassificationFram } override fun getDataOrder(): DataOrder = DataOrder.NCWH -} \ No newline at end of file +} diff --git a/ncnn/src/main/java/ru/gordinmitya/ncnn/NCNNFramework.kt b/ncnn/src/main/java/ru/gordinmitya/ncnn/NCNNFramework.kt index fab93f7..47e0ba3 100644 --- a/ncnn/src/main/java/ru/gordinmitya/ncnn/NCNNFramework.kt +++ b/ncnn/src/main/java/ru/gordinmitya/ncnn/NCNNFramework.kt @@ -1,14 +1,11 @@ package ru.gordinmitya.ncnn import android.content.Context -import ru.gordinmitya.common.Configuration -import ru.gordinmitya.common.InferenceFramework -import ru.gordinmitya.common.InferenceType -import ru.gordinmitya.common.Model +import ru.gordinmitya.common.* import ru.gordinmitya.common.classification.ClassificationFramework import ru.gordinmitya.common.classification.Classifier -class NCNNFramework : InferenceFramework("NCNN", "by Tencent"), ClassificationFramework { +class NCNNFramework : InferenceFramework("NCNN", Version("?")), ClassificationFramework { private val types = arrayListOf( NCNN_CPU, NCNN_VULKAN @@ -27,4 +24,4 @@ class NCNNFramework : InferenceFramework("NCNN", "by Tencent"), ClassificationFr return NCNNClassifier(context, configuration, convertedModel, inferenceType) } -} \ No newline at end of file +} diff --git a/onnxruntime/src/main/java/ru/gordinmitya/onnxruntime/ONNXFramework.kt b/onnxruntime/src/main/java/ru/gordinmitya/onnxruntime/ONNXFramework.kt index 644a274..048ca78 100644 --- a/onnxruntime/src/main/java/ru/gordinmitya/onnxruntime/ONNXFramework.kt +++ b/onnxruntime/src/main/java/ru/gordinmitya/onnxruntime/ONNXFramework.kt @@ -1,14 +1,11 @@ package ru.gordinmitya.onnxruntime import android.content.Context -import ru.gordinmitya.common.Configuration -import ru.gordinmitya.common.InferenceFramework -import ru.gordinmitya.common.InferenceType -import ru.gordinmitya.common.Model +import ru.gordinmitya.common.* import ru.gordinmitya.common.classification.ClassificationFramework import ru.gordinmitya.common.classification.Classifier -class ONNXFramework : InferenceFramework("onnxruntime", "by Microsoft"), ClassificationFramework { +class ONNXFramework : InferenceFramework("onnxruntime", Version("?")), ClassificationFramework { private val types = arrayListOf( ONNX_CPU, ONNX_NNAPI @@ -27,4 +24,4 @@ class ONNXFramework : InferenceFramework("onnxruntime", "by Microsoft"), Classif return ONNXClassifier(context, configuration, convertedModel, inferenceType) } -} \ No newline at end of file +} diff --git a/opencv/src/main/java/ru/gordinmitya/opencv/OpenCVFramework.kt b/opencv/src/main/java/ru/gordinmitya/opencv/OpenCVFramework.kt index a869861..f199489 100644 --- a/opencv/src/main/java/ru/gordinmitya/opencv/OpenCVFramework.kt +++ b/opencv/src/main/java/ru/gordinmitya/opencv/OpenCVFramework.kt @@ -1,12 +1,13 @@ package ru.gordinmitya.opencv import android.content.Context +import org.opencv.android.OpenCVLoader.OPENCV_VERSION import ru.gordinmitya.common.* import ru.gordinmitya.common.classification.ClassificationFramework import ru.gordinmitya.common.classification.ClassificationModel import ru.gordinmitya.common.classification.Classifier -class OpenCVFramework : InferenceFramework("OpenCV DNN", "by OpenCV"), ClassificationFramework { +class OpenCVFramework : InferenceFramework("OpenCV DNN", Version(OPENCV_VERSION)), ClassificationFramework { private val TYPES = listOf(OPENCV_CPU) override fun getInferenceTypes(): List = TYPES @@ -22,4 +23,4 @@ class OpenCVFramework : InferenceFramework("OpenCV DNN", "by OpenCV"), Classific return OpenCVClassifier(context, configuration, convertedModel, inferenceType) } -} \ No newline at end of file +} diff --git a/pytorch/src/main/java/ru/gordinmitya/pytorch/PytorchFramework.kt b/pytorch/src/main/java/ru/gordinmitya/pytorch/PytorchFramework.kt index eb6058f..4513e79 100644 --- a/pytorch/src/main/java/ru/gordinmitya/pytorch/PytorchFramework.kt +++ b/pytorch/src/main/java/ru/gordinmitya/pytorch/PytorchFramework.kt @@ -1,15 +1,12 @@ package ru.gordinmitya.pytorch import android.content.Context -import ru.gordinmitya.common.Configuration -import ru.gordinmitya.common.InferenceFramework -import ru.gordinmitya.common.InferenceType -import ru.gordinmitya.common.Model +import ru.gordinmitya.common.* import ru.gordinmitya.common.classification.ClassificationFramework import ru.gordinmitya.common.classification.ClassificationModel import ru.gordinmitya.common.classification.Classifier -class PytorchFramework : InferenceFramework("Pytorch", "by Facebook"), ClassificationFramework { +class PytorchFramework : InferenceFramework("Pytorch", Version("1.5.0")), ClassificationFramework { private val TYPES = listOf(PYTORCH_CPU) override fun getInferenceTypes(): List = TYPES @@ -25,4 +22,4 @@ class PytorchFramework : InferenceFramework("Pytorch", "by Facebook"), Classific return PytorchClassifier(context, configuration, convertedModel, inferenceType) } -} \ No newline at end of file +} diff --git a/tflite/src/main/java/ru/gordinmitya/tflite/TFLiteFramework.kt b/tflite/src/main/java/ru/gordinmitya/tflite/TFLiteFramework.kt index 373a2da..97443e9 100644 --- a/tflite/src/main/java/ru/gordinmitya/tflite/TFLiteFramework.kt +++ b/tflite/src/main/java/ru/gordinmitya/tflite/TFLiteFramework.kt @@ -9,7 +9,7 @@ import ru.gordinmitya.common.segmentation.SegmentationFramework import ru.gordinmitya.common.segmentation.SegmentationModel import ru.gordinmitya.common.segmentation.Segmentator -class TFLiteFramework : InferenceFramework("TFLite", "by Google"), +class TFLiteFramework : InferenceFramework("TFLite", Version("2.3.0")), ClassificationFramework, SegmentationFramework { @@ -46,4 +46,4 @@ class TFLiteFramework : InferenceFramework("TFLite", "by Google"), } override fun getDataOrder(): DataOrder = DataOrder.NHWC -} \ No newline at end of file +}