why tensorflow lite model not working after converting from keras model?

Viewed 19

I converted a keras model in to tenserflow lite model using the code

model = tf.keras.models.load_model('liveness.model')

# Convert the model.
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()

# Save the model.
with open('model.tflite', 'wb') as f:
  f.write(tflite_model)

But it not working and always giving same output for all inputs. I tried with android i am adding my android code as well.

bitmap = getBitmapImageWith32();

int inputSize=32;
int OUTPUT_SIZE=2;
float[][] embeedings;
int[] intValues;

ByteBuffer imgData = ByteBuffer.allocateDirect(1 * inputSize * inputSize * 3 * 4);
imgData.order(ByteOrder.nativeOrder());

bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());

imgData.rewind();

int p = 0;
for (int i = 0; i < inputSize; ++i) {
    for (int j = 0; j < inputSize; ++j) {
        int pixelValue = intValues[pixel++];
        imgData.putFloat((((pixelValue >> 16) & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
        imgData.putFloat((((pixelValue >> 8) & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
        imgData.putFloat(((pixelValue & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
        p++;
    }
}

Object[] inputArray = {imgData};
Map<Integer, Object> outputMap = new HashMap<>();
embeedings = new float[1][OUTPUT_SIZE];
outputMap.put(0, embeedings);
tfLiteLiveness.runForMultipleInputsOutputs(inputArray, outputMap);

Log.e("first val", String.valueOf(embeedings[0][0]));
Log.e("second val", String.valueOf(embeedings[0][1]));

This is the model I am using

https://github.com/birdowl21/Face-Liveness-Detection-Anti-Spoofing-Web-App/blob/main/liveness.model
0 Answers
Related