-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecsam_system_main.py
More file actions
51 lines (44 loc) · 2.06 KB
/
ecsam_system_main.py
File metadata and controls
51 lines (44 loc) · 2.06 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
41
42
43
44
45
46
47
48
49
50
51
# ECSAM Main Orchestrator
from edge_device import EdgeDevice
from cloud_server import CloudServer
from ecsam_modules import (
ECSAM_Context_Mgmt, ECSAM_VP_Trans, ECSAM_ImgEnc, ECSAM_Dec, ECSAM_Cloud_Reg, ECSAM_Cloud_Offloading
)
import numpy as np
if __name__ == "__main__":
# Initialize edge and cloud
edge = EdgeDevice()
cloud = CloudServer()
# 1. Context management (prompt encoding/session)
context_mgmt = ECSAM_Context_Mgmt()
prompt = {'type': 'point', 'coords': (100, 100)}
context_mgmt.encode_prompt(prompt)
print("[ECSAM] Context management and prompt encoding done.")
# 2. Visual prompt transformation
vp_trans = ECSAM_VP_Trans()
# Simulate a list of prompt objects (with dummy embeddings)
from visual_prompt_transformer import Prompt
prompts = [Prompt(embedding=np.random.rand(16), prompt_type='point', metadata=(i*10, i*10)) for i in range(3)]
transformed_prompts = vp_trans.transform(prompts, latency_constraint=2)
print(f"[ECSAM] Visual prompt transformation done. {len(transformed_prompts)} prompts after transformation.")
# 3. Image encoding with partitioning
img_enc = ECSAM_ImgEnc()
dummy_image = np.random.randint(0, 255, (224, 224, 3), dtype=np.uint8)
split_point = img_enc.model_partition(layers=list(range(100)), edge_costs=[1.0]*100, latency_constraint=60)
img_emb = img_enc.encode_image(dummy_image, split_point=split_point)
print(f"[ECSAM] Image encoding done. Split point: {split_point}")
# 4. Decoding
dec = ECSAM_Dec()
# Use dummy embeddings for demonstration
prompt_emb = np.random.rand(1, 16)
image_emb = np.random.rand(1, 32)
result = dec.decode(prompt_emb, image_emb)
print(f"[ECSAM] Decoding done. Result: {result}")
# 5. Cloud registration
cloud_reg = ECSAM_Cloud_Reg()
cloud_reg.register_edge(edge_id="edge-001")
print("[ECSAM] Cloud registration done.")
# 6. Cloud offloading
cloud_offload = ECSAM_Cloud_Offloading()
cloud_offload.offload_inference(data={'image': dummy_image})
print("[ECSAM] Cloud offloading done.")