增加物品采集功能,解决测试问题
This commit is contained in:
@@ -28,17 +28,18 @@ object FoodModule {
|
||||
private lateinit var classInfo: FoodClassInfo
|
||||
val NO_MEAN_RGB = floatArrayOf(0.0f, 0.0f, 0.0f)
|
||||
val NO_STD_RGB = floatArrayOf(1.0f, 1.0f, 1.0f)
|
||||
val DEFAULT_FOOD_INDEX = -1
|
||||
|
||||
fun init(context: Context) {
|
||||
Thread {
|
||||
module_mobile = Module.load(copyAssetToCache(context, "best_embedding_model_mobile.pt"))
|
||||
box = ObjectBox.boxStore.boxFor(Food::class)
|
||||
if (box.all.isNotEmpty()) {
|
||||
box.removeAll()
|
||||
}
|
||||
if (box.all.isEmpty()) {
|
||||
initFoodData(context)
|
||||
}
|
||||
//if (box.all.isNotEmpty()) {
|
||||
// box.removeAll()
|
||||
//}
|
||||
//if (box.all.isEmpty()) {
|
||||
// initDefFoodData(context)
|
||||
//}
|
||||
}.start()
|
||||
}
|
||||
|
||||
@@ -100,10 +101,10 @@ object FoodModule {
|
||||
}
|
||||
|
||||
|
||||
private fun initFoodData(context: Context) {
|
||||
if (box.all.isNotEmpty()) {
|
||||
return
|
||||
}
|
||||
fun initDefFoodData(context: Context, action:()-> Unit={}) {
|
||||
//if (box.all.isNotEmpty()) {
|
||||
// return
|
||||
//}
|
||||
val embeddingsJson = AssetsTool.readAssetsFile(context, "data/embeddings.json")
|
||||
val labelsJson = AssetsTool.readAssetsFile(context, "data/labels.json")
|
||||
val classInfoJson = AssetsTool.readAssetsFile(context, "data/class_info.json")
|
||||
@@ -119,8 +120,9 @@ object FoodModule {
|
||||
val classIdx = labelsList[index]
|
||||
val foodName = foodMap["$classIdx"]
|
||||
val array = floatList.toFloatArray()
|
||||
box.put(Food(name = foodName, foodVector = array, foodIdx = index))
|
||||
box.put(Food(name = foodName, foodVector = array, foodIdx = DEFAULT_FOOD_INDEX))
|
||||
}
|
||||
action()
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user