@@ -53,7 +53,7 @@ private void configureHostedModelSource() {
53
53
private void configureLocalModelSource () {
54
54
// [START mlkit_local_model_source]
55
55
FirebaseLocalModelSource localSource =
56
- new FirebaseLocalModelSource .Builder ("my_local_model" ) // Assign a name for this model
56
+ new FirebaseLocalModelSource .Builder ("my_local_model" ) // Assign a name to this model
57
57
.setAssetFilePath ("my_model.tflite" )
58
58
.build ();
59
59
FirebaseModelManager .getInstance ().registerLocalModelSource (localSource );
@@ -78,7 +78,7 @@ private FirebaseModelInputOutputOptions createInputOutputOptions() throws Fireba
78
78
FirebaseModelInputOutputOptions inputOutputOptions =
79
79
new FirebaseModelInputOutputOptions .Builder ()
80
80
.setInputFormat (0 , FirebaseModelDataType .FLOAT32 , new int []{1 , 224 , 224 , 3 })
81
- .setOutputFormat (0 , FirebaseModelDataType .FLOAT32 , new int []{1 , 1000 })
81
+ .setOutputFormat (0 , FirebaseModelDataType .FLOAT32 , new int []{1 , 5 })
82
82
.build ();
83
83
// [END mlkit_create_io_options]
84
84
@@ -88,18 +88,19 @@ private FirebaseModelInputOutputOptions createInputOutputOptions() throws Fireba
88
88
private float [][][][] bitmapToInputArray () {
89
89
// [START mlkit_bitmap_input]
90
90
Bitmap bitmap = getYourInputImage ();
91
+ bitmap = Bitmap .createScaledBitmap (bitmap , 224 , 224 , true );
91
92
92
93
int batchNum = 0 ;
93
94
float [][][][] input = new float [1 ][224 ][224 ][3 ];
94
95
for (int x = 0 ; x < 224 ; x ++) {
95
96
for (int y = 0 ; y < 224 ; y ++) {
96
97
int pixel = bitmap .getPixel (x , y );
97
- // Normalize channel values to [0 .0, 1.0]. This requirement varies by
98
+ // Normalize channel values to [-1 .0, 1.0]. This requirement varies by
98
99
// 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 ;
100
+ // to the range [0 .0, 1.0] instead.
101
+ input [batchNum ][x ][y ][0 ] = ( Color .red (pixel ) - 127 ) / 128 .0f ;
102
+ input [batchNum ][x ][y ][1 ] = ( Color .green (pixel ) - 127 ) / 128 .0f ;
103
+ input [batchNum ][x ][y ][2 ] = ( Color .blue (pixel ) - 127 ) / 128 .0f ;
103
104
}
104
105
}
105
106
// [END mlkit_bitmap_input]
0 commit comments