sicara / tf-explain

Interpretability Methods for tf.keras models with Tensorflow 2.x
https://tf-explain.readthedocs.io
MIT License
1.02k stars 112 forks source link

can tf-expain explain tf-lite models? #174

Open showkeyjar opened 2 years ago

showkeyjar commented 2 years ago

can tf-expain explain tf-lite models?

if can, how to explain?

if not, would you have some advice or suggestion?

showkeyjar commented 2 years ago

I fig it out, would you please check this idea is right?

I rewrite a OcclusionSensitivity class and use python read tf.lite model then predict

the key codes:

` def get_sensitivity_map(self, interpreter, image, class_index, patch_size):

interpreter is tf.lite model

    ...
    interpreter.allocate_tensors()
    for patch in tqdm(patches):
        interpreter.set_tensor(interpreter.get_input_details()[0]['index'], [patch])
        interpreter.invoke()
        preds = interpreter.get_tensor(interpreter.get_output_details()[0]['index'])
        predictions.extend(preds)

    target_class_predictions = [
        prediction[class_index] for prediction in predictions
    ]
    ...

`

beacause I can't find how to batch predict image use tf.lite model, so I make a for loop and set a bigger patch_size