Currently in its initial development phase, this lightweight model is designed to run entirely offline on Android edge devices to analyze live camera feeds, identifying both the type of disaster and the severity of the damage simultaneously.
To support cross-platform development and strict mobile deployment, the model has been exported into the following formats:
1import os
2os.environ["TF_LITE_DISABLE_XNNPACK"] = "1"
3
4import numpy as np
5import tensorflow as tf
6from PIL import Image
7
8# 1. Load Model
9model_path = r"mrbean_tf_model\mrbean_vision_float16.tflite"
10interpreter = tf.lite.Interpreter(model_path=model_path)
11interpreter.allocate_tensors()
12
13input_details = interpreter.get_input_details()[0]
14output_details = interpreter.get_output_details()
15
16# 2. Preprocess Image
17def preprocess_image(image_path, expected_shape):
18 img = Image.open(image_path).convert('RGB').resize((224, 224))
19 img_array = np.array(img, dtype=np.float32) / 255.0
20
21 mean = np.array([0.485, 0.456, 0.406], dtype=np.float32)
22 std = np.array([0.229, 0.224, 0.225], dtype=np.float32)
23 img_array = (img_array - mean) / std
24
25 if expected_shape[1] == 3: # NCHW fallback
26 img_array = np.transpose(img_array, (2, 0, 1))
27
28 return np.expand_dims(img_array, axis=0)
29
30# 3. Inference
31input_data = preprocess_image("test_image.jpg", input_details['shape']).astype(input_details['dtype'])
32interpreter.set_tensor(input_details['index'], input_data)
33interpreter.invoke()
34
35# 4. Extract Results
36out_0 = interpreter.get_tensor(output_details[0]['index'])[0]
37out_1 = interpreter.get_tensor(output_details[1]['index'])[0]
38
39pred_disaster = np.argmax(out_0) if len(out_0) == 6 else np.argmax(out_1)
40pred_severity = np.argmax(out_1) if len(out_0) == 6 else np.argmax(out_0)
41
42print(f"Disaster Class ID: {pred_disaster}")
43print(f"Severity Class ID: {pred_severity}")