Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fcc5e15

Browse files
Change some values to align with TF Poets
1 parent df29b4f commit fcc5e15

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

mlkit/app/src/main/java/com/google/firebase/example/mlkit/kotlin/CustomModelActivity.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CustomModelActivity : AppCompatActivity() {
5454

5555
private fun configureLocalModelSource() {
5656
// [START mlkit_local_model_source]
57-
val localSource = FirebaseLocalModelSource.Builder("my_local_model") // Assign a name for this model
57+
val localSource = FirebaseLocalModelSource.Builder("my_local_model") // Assign a name to this model
5858
.setAssetFilePath("my_model.tflite")
5959
.build()
6060
FirebaseModelManager.getInstance().registerLocalModelSource(localSource)
@@ -79,27 +79,27 @@ class CustomModelActivity : AppCompatActivity() {
7979
// [START mlkit_create_io_options]
8080
val inputOutputOptions = FirebaseModelInputOutputOptions.Builder()
8181
.setInputFormat(0, FirebaseModelDataType.FLOAT32, intArrayOf(1, 224, 224, 3))
82-
.setOutputFormat(0, FirebaseModelDataType.FLOAT32, intArrayOf(1, 1000))
82+
.setOutputFormat(0, FirebaseModelDataType.FLOAT32, intArrayOf(1, 5))
8383
.build()
8484
// [END mlkit_create_io_options]
8585
return inputOutputOptions
8686
}
8787

8888
private fun bitmapToInputArray(): Array<Array<Array<FloatArray>>> {
8989
// [START mlkit_bitmap_input]
90-
val bitmap = yourInputImage
90+
val bitmap = Bitmap.createScaledBitmap(yourInputImage, 224, 224, true)
9191

9292
val batchNum = 0
9393
val input = Array(1) { Array(224) { Array(224) { FloatArray(3) } } }
9494
for (x in 0..223) {
9595
for (y in 0..223) {
9696
val pixel = bitmap.getPixel(x, y)
97-
// Normalize channel values to [0.0, 1.0]. This requirement varies by
97+
// Normalize channel values to [-1.0, 1.0]. This requirement varies by
9898
// model. For example, some models might require values to be normalized
99-
// to the range [-1.0, 1.0] instead.
100-
input[batchNum][x][y][0] = Color.red(pixel) / 255.0f
101-
input[batchNum][x][y][1] = Color.green(pixel) / 255.0f
102-
input[batchNum][x][y][2] = Color.blue(pixel) / 255.0f
99+
// to the range [0.0, 1.0] instead.
100+
input[batchNum][x][y][0] = (Color.red(pixel) - 127) / 255.0f
101+
input[batchNum][x][y][1] = (Color.green(pixel) - 127) / 255.0f
102+
input[batchNum][x][y][2] = (Color.blue(pixel) - 127) / 255.0f
103103
}
104104
}
105105
// [END mlkit_bitmap_input]
@@ -146,4 +146,4 @@ class CustomModelActivity : AppCompatActivity() {
146146
}
147147
// [END mlkit_use_inference_result]
148148
}
149-
}
149+
}

0 commit comments

Comments
 (0)