Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
rid Room
Browse files Browse the repository at this point in the history
  • Loading branch information
SichangHe committed Jul 27, 2023
1 parent 40d4d5a commit 2ecbfb9
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 186 deletions.
15 changes: 0 additions & 15 deletions client/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
}

android {
Expand All @@ -14,13 +13,6 @@ android {
targetSdkVersion 33
versionCode 1
versionName "1.0"

javaCompileOptions {
annotationProcessorOptions {
// Tell Room where to export schema so it can generate auto-migrations.
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
buildTypes {
debug { minifyEnabled false }
Expand Down Expand Up @@ -61,13 +53,6 @@ dependencies {
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

// Room.
def room_version = '2.5.2'
implementation("androidx.room:room-runtime:$room_version")
kapt("androidx.room:room-compiler:$room_version")
implementation("androidx.room:room-ktx:$room_version")
testImplementation("androidx.room:room-testing:$room_version")

// Local dependencies.
implementation project(path: ':FedCampus')

Expand Down
90 changes: 0 additions & 90 deletions client/app/schemas/flwr.android_client.Db/1.json

This file was deleted.

28 changes: 0 additions & 28 deletions client/app/src/main/java/flwr/android_client/Db.kt

This file was deleted.

3 changes: 0 additions & 3 deletions client/app/src/main/java/flwr/android_client/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.room.Room
import flwr.android_client.databinding.ActivityMainBinding
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
Expand All @@ -26,11 +25,9 @@ class MainActivity : AppCompatActivity() {
lateinit var flowerClient: FlowerClient<Float3DArray, FloatArray>
private lateinit var binding: ActivityMainBinding
val dateFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
lateinit var db: Db

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
db = Room.databaseBuilder(this, Db::class.java, "model-db").build()
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
Expand Down
8 changes: 0 additions & 8 deletions client/fedcampus/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'com.google.protobuf'
id 'kotlin-kapt'
}

android {
Expand Down Expand Up @@ -71,13 +70,6 @@ dependencies {
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'com.google.protobuf:protoc:3.23.4'

// Room.
def room_version = '2.5.2'
implementation("androidx.room:room-runtime:$room_version")
kapt("androidx.room:room-compiler:$room_version")
implementation("androidx.room:room-ktx:$room_version")
testImplementation("androidx.room:room-testing:$room_version")

// TensorFlow Lite.
implementation 'org.tensorflow:tensorflow-lite:2.13.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.13.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.util.Log
import io.grpc.ManagedChannel
import kotlinx.coroutines.*
import org.eu.fedcampus.train.db.ModelDao
import org.eu.fedcampus.train.db.TFLiteModel
import retrofit2.http.*
import java.io.File
Expand All @@ -15,7 +14,6 @@ class Train<X : Any, Y : Any> constructor(
val context: Context,
backendUrl: String,
val sampleSpec: SampleSpec<X, Y>,
val modelDao: ModelDao? = null
) {
var sessionId: Int? = null
var telemetry = false
Expand Down Expand Up @@ -52,9 +50,11 @@ class Train<X : Any, Y : Any> constructor(
return model
}

@Suppress("UNUSED_PARAMETER")
@Throws
suspend fun modelDownloaded(model: TFLiteModel): Boolean {
return modelDao?.findById(model.id)?.equals(model.toDbModel()) ?: false
fun modelDownloaded(model: TFLiteModel): Boolean {
// TODO: Save model to DB.
return false
}

/**
Expand All @@ -78,7 +78,6 @@ class Train<X : Any, Y : Any> constructor(
}
val fileDir = client.downloadFile(fileUrl, modelDir, fileName)
Log.i(downloadModelFileTag, "$fileUrl -> ${fileDir.absolutePath}")
modelDao?.upsertAll(model.toDbModel())
return fileDir
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import kotlinx.coroutines.withContext
import org.eu.fedcampus.train.FlowerClient
import org.eu.fedcampus.train.SampleSpec
import org.eu.fedcampus.train.Train
import org.eu.fedcampus.train.db.ModelDao
import org.eu.fedcampus.train.helpers.loadMappedFile
import java.util.concurrent.TimeUnit

Expand All @@ -35,7 +34,6 @@ open class BaseTrainWorker<X : Any, Y : Any>(
val dataType: String,
val loadData: suspend (Context, FlowerClient<X, Y>, Int) -> Unit,
val trainCallback: (String) -> Unit,
val modelDao: ModelDao? = null,
val useTLS: Boolean = false,
) : CoroutineWorker(context, params) {
val data = inputData
Expand All @@ -55,7 +53,7 @@ open class BaseTrainWorker<X : Any, Y : Any>(
val flowerHost = data.getString("flowerHost")!!
val participantId = data.getInt("participantId", 1)

train = Train(context, backendUrl, sampleSpec, modelDao)
train = Train(context, backendUrl, sampleSpec)
if (deviceId != 0L) train.enableTelemetry(deviceId)
Log.i(TAG, "Starting with backend $backendUrl for $dataType.")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.eu.fedcampus.train.db

import android.content.Context
import androidx.room.*
import java.io.File

// Always change together with Python `train.models.TFLiteModel`.
Expand All @@ -15,37 +14,4 @@ data class TFLiteModel(
fun getModelDir(context: Context): File {
return context.getExternalFilesDir("models/$name/")!!
}

fun toDbModel(): Model {
return Model(id, name, file_path, layers_sizes.size.toLong())
}
}

/**
* Simplified version of [TFLiteModel] to save in database.
*/
@Entity
data class Model(
@PrimaryKey val id: Long,
@ColumnInfo val name: String,
@ColumnInfo val file_path: String,
@ColumnInfo val n_layers: Long,
)

@Dao
interface ModelDao {
@Query("SELECT * FROM model")
suspend fun getAll(): List<Model>

@Query("SELECT * FROM model WHERE id = :id")
suspend fun findById(id: Long): Model?

@Query("SELECT * FROM model WHERE name LIKE :name")
suspend fun findByName(name: String): List<Model>

@Upsert
suspend fun upsertAll(vararg models: Model)

@Delete
suspend fun deleteAll(vararg models: Model)
}

0 comments on commit 2ecbfb9

Please sign in to comment.