forked from dailystudio/tensorflow-lite-examples-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tensorfloe-lite-examples-common][DEV]: update to Devbricks X 1.1.0;
[tensorfloe-lite-examples-common][DEV]: update settings implementation; [example-image-classification][DEV]: adapt to latest example framework;
- Loading branch information
1 parent
9bf5be5
commit f136f10
Showing
27 changed files
with
258 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...n/java/com/dailystudio/tflite/example/image/classification/ImageClassificationSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.dailystudio.tflite.example.image.classification | ||
|
||
import com.dailystudio.devbricksx.annotations.PreferenceValue | ||
import com.dailystudio.devbricksx.annotations.SharedPreference | ||
import com.dailystudio.tflite.example.common.ui.InferenceSettings | ||
import org.tensorflow.lite.support.model.Model | ||
|
||
@SharedPreference | ||
class ImageClassificationSettings(@PreferenceValue | ||
val tfLiteModel: String? = null, | ||
device: String = Model.Device.CPU.toString(), | ||
numOfThread: Int = 1) | ||
: InferenceSettings(device, numOfThread) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...tudio/tflite/example/image/classification/fragment/ImageClassificationSettingsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.dailystudio.tflite.example.image.classification.fragment | ||
|
||
import android.content.Context | ||
import com.dailystudio.devbricksx.settings.AbsSetting | ||
import com.dailystudio.devbricksx.settings.RadioSetting | ||
import com.dailystudio.devbricksx.settings.SimpleRadioSettingItem | ||
import com.dailystudio.tflite.example.common.ui.InferenceSettingsFragment | ||
import com.dailystudio.tflite.example.common.ui.InferenceSettingsPrefs | ||
import com.dailystudio.tflite.example.image.classification.ImageClassificationSettingsPrefs | ||
import com.dailystudio.tflite.example.image.classification.R | ||
import org.tensorflow.lite.examples.classification.tflite.Classifier | ||
|
||
class ImageClassificationSettingsFragment : InferenceSettingsFragment() { | ||
|
||
override fun createSettings(context: Context): Array<AbsSetting> { | ||
val settings: MutableList<AbsSetting> = | ||
super.createSettings(context).toMutableList() | ||
|
||
val settingsPrefs = getInferenceSettingsPrefs() | ||
if (settingsPrefs !is ImageClassificationSettingsPrefs) { | ||
return settings.toTypedArray() | ||
} | ||
|
||
val models = arrayOf( | ||
SimpleRadioSettingItem(context, | ||
Classifier.Model.QUANTIZED_MOBILENET.toString(), | ||
R.string.model_quantized_mobile_net), | ||
SimpleRadioSettingItem(context, | ||
Classifier.Model.FLOAT_MOBILENET.toString(), | ||
R.string.model_float_mobile_net), | ||
SimpleRadioSettingItem(context, | ||
Classifier.Model.QUANTIZED_EFFICIENTNET.toString(), | ||
R.string.model_quantized_efficient_net), | ||
SimpleRadioSettingItem(context, | ||
Classifier.Model.FLOAT_EFFICIENTNET.toString(), | ||
R.string.model_float_efficient_net) | ||
) | ||
|
||
val modelSetting = object: RadioSetting<SimpleRadioSettingItem>( | ||
context, | ||
ImageClassificationSettingsPrefs.PREF_TF_LITE_MODEL, | ||
R.drawable.ic_setting_models, | ||
R.string.setting_model, | ||
models) { | ||
override val selectedId: String? | ||
get() = settingsPrefs.tfLiteModel | ||
|
||
override fun setSelected(selectedId: String?) { | ||
settingsPrefs.tfLiteModel = selectedId | ||
} | ||
} | ||
|
||
settings.add(modelSetting) | ||
|
||
return settings.toTypedArray() | ||
} | ||
|
||
override fun getInferenceSettingsPrefs(): InferenceSettingsPrefs { | ||
return ImageClassificationSettingsPrefs.instance | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
example-image-classification/src/main/res/drawable-anydpi/ic_setting_models.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="#FF9900" | ||
android:alpha="0.8"> | ||
<group android:scaleX="0.71428573" | ||
android:scaleY="0.71428573" | ||
android:translateX="3.4285715" | ||
android:translateY="3.4285715"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M22,11V3h-7v3H9V3H2v8h7V8h2v10h4v3h7v-8h-7v3h-2V8h2v3z"/> | ||
</group> | ||
</vector> |
Binary file added
BIN
+197 Bytes
example-image-classification/src/main/res/drawable-hdpi/ic_setting_models.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+205 Bytes
example-image-classification/src/main/res/drawable-mdpi/ic_setting_models.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+269 Bytes
example-image-classification/src/main/res/drawable-xhdpi/ic_setting_models.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+287 Bytes
example-image-classification/src/main/res/drawable-xxhdpi/ic_setting_models.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
<resources> | ||
<string name="app_name">Image Classification</string> | ||
<string name="app_desc">Test an image classification solution with a pre-trained model that can recognize 1000 different types of items from input frames on a mobile camera.</string> | ||
|
||
<string name="setting_model">TensorFlow Lite models</string> | ||
|
||
<string name="model_float_mobile_net">MobileNet (Float32)</string> | ||
<string name="model_quantized_mobile_net">MobileNet (Quantized)</string> | ||
<string name="model_float_efficient_net">Efficient (Float32)</string> | ||
<string name="model_quantized_efficient_net">Efficient (Quantized)</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.