-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluate_ecsam.py
More file actions
40 lines (32 loc) · 1.48 KB
/
evaluate_ecsam.py
File metadata and controls
40 lines (32 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import numpy as np
from edge_device import EdgeDevice
from cloud_server import CloudServer
def compute_iou(pred_mask, gt_mask):
intersection = np.logical_and(pred_mask, gt_mask).sum()
union = np.logical_or(pred_mask, gt_mask).sum()
if union == 0:
return 1.0 if intersection == 0 else 0.0
return intersection / union
def compute_pixel_accuracy(pred_mask, gt_mask):
return (pred_mask == gt_mask).sum() / pred_mask.size
def main():
# Initialize ECSAM system
edge = EdgeDevice()
cloud = CloudServer()
# Run ECSAM pipeline (simulate one run)
frames, prompts = edge.input_handler.receive_input()
visual_emb = edge.visual_prompt_encoder.encode(prompts)
split_point = edge.workload_partitioner.partition(model_layers=1000, resources=edge.resources, latency_constraint=edge.resources.max_latency_ms)
local_feat, cloud_state = edge.image_encoder.encode(frames, prompts, split_point)
edge.communicator.send_to_cloud(cloud_state)
cloud_emb = cloud.process_from_edge(cloud_state)
pred_mask = edge.embedding_decoder.decode(visual_emb, cloud_emb)
# Simulate a ground truth mask (random binary mask for demonstration)
gt_mask = np.random.randint(0, 2, size=pred_mask.shape, dtype=np.uint8)
# Compute evaluation metrics
iou = compute_iou(pred_mask, gt_mask)
acc = compute_pixel_accuracy(pred_mask, gt_mask)
print(f"[Eval] IoU: {iou:.4f}")
print(f"[Eval] Pixel Accuracy: {acc:.4f}")
if __name__ == "__main__":
main()