abreza commited on
Commit
ba85228
1 Parent(s): 033c8ba

try to load et data

Browse files
Files changed (2) hide show
  1. app.py +68 -46
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,55 +1,77 @@
1
  import gradio as gr
2
- from gradio_rerun import Rerun
3
- from data.loader import load_simulation_data
 
 
 
4
  from visualization.visualizer import visualize_simulation
5
 
6
 
7
- def update_simulation_dropdown(file):
8
- simulations, descriptions = load_simulation_data(file)
9
- return gr.Dropdown(
10
- choices=descriptions if descriptions else [],
11
- value=None,
12
- allow_custom_value=False
 
 
 
 
 
 
 
13
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- def create_app():
17
- with gr.Blocks() as demo:
18
- gr.Markdown("""
19
- # Camera Simulation Visualizer
20
- Upload a JSON file containing camera simulation data and select a simulation to visualize.
21
- """)
22
-
23
- with gr.Row():
24
- file_input = gr.File(
25
- label="Upload Simulation JSON",
26
- file_types=[".json"]
27
- )
28
- simulation_dropdown = gr.Dropdown(
29
- label="Select Simulation",
30
- choices=[],
31
- type="index",
32
- scale=2
33
- )
34
-
35
- with gr.Row():
36
- viewer = Rerun(streaming=False)
37
-
38
- file_input.change(
39
- update_simulation_dropdown,
40
- inputs=[file_input],
41
- outputs=[simulation_dropdown]
42
- )
43
-
44
- simulation_dropdown.change(
45
- visualize_simulation,
46
- inputs=[file_input, simulation_dropdown],
47
- outputs=[viewer]
48
- )
49
-
50
- return demo
51
-
52
 
53
  if __name__ == "__main__":
54
- demo = create_app()
55
- demo.queue().launch(share=False)
 
1
  import gradio as gr
2
+ import numpy as np
3
+ import torch
4
+ import torch.nn.functional as F
5
+ from evo.tools.file_interface import read_kitti_poses_file
6
+ from pathlib import Path
7
  from visualization.visualizer import visualize_simulation
8
 
9
 
10
+ def load_trajectory_data(traj_file, char_file, num_cams=30):
11
+ trajectory = read_kitti_poses_file(traj_file)
12
+ matrix_trajectory = torch.from_numpy(np.array(trajectory.poses_se3)).to(torch.float32)
13
+
14
+ raw_trans = torch.clone(matrix_trajectory[:, :3, 3])
15
+ raw_rot = matrix_trajectory[:, :3, :3]
16
+ rot6d = raw_rot[:, :, :2].permute(0, 2, 1).reshape(-1, 6)
17
+
18
+ trajectory_feature = torch.hstack([rot6d, raw_trans]).permute(1, 0)
19
+
20
+ padded_trajectory_feature = F.pad(
21
+ trajectory_feature,
22
+ (0, num_cams - trajectory_feature.shape[1])
23
  )
24
+
25
+ padding_mask = torch.ones((num_cams))
26
+ padding_mask[trajectory_feature.shape[1]:] = 0
27
+
28
+ char_feature = torch.from_numpy(np.load(char_file)).to(torch.float32)
29
+ padding_size = num_cams - char_feature.shape[0]
30
+ padded_char_feature = F.pad(char_feature, (0, 0, 0, padding_size)).permute(1, 0)
31
+
32
+ return {
33
+ "traj_filename": Path(traj_file).name,
34
+ "char_filename": Path(char_file).name,
35
+ "traj_feat": padded_trajectory_feature,
36
+ "char_feat": padded_char_feature,
37
+ "padding_mask": padding_mask,
38
+ "raw_matrix_trajectory": matrix_trajectory
39
+ }
40
 
41
+ def create_trajectory_interface():
42
+ """Create Gradio interface for loading trajectory data"""
43
+
44
+ def process_files(traj_file, char_file):
45
+ try:
46
+ result = load_trajectory_data(traj_file.name, char_file.name)
47
+
48
+ # Convert tensors to numpy for display
49
+ info = {
50
+ "Trajectory filename": result["traj_filename"],
51
+ "Character filename": result["char_filename"],
52
+ "Trajectory shape": result["traj_feat"].shape,
53
+ "Character shape": result["char_feat"].shape,
54
+ "Valid frames": int(result["padding_mask"].sum().item())
55
+ }
56
+
57
+ return str(info)
58
+
59
+ except Exception as e:
60
+ return f"Error processing files: {str(e)}"
61
 
62
+ interface = gr.Interface(
63
+ fn=process_files,
64
+ inputs=[
65
+ gr.File(label="Trajectory File (.txt)"),
66
+ gr.File(label="Character File (.npy)")
67
+ ],
68
+ outputs=gr.Textbox(label="Results"),
69
+ title="Trajectory Data Loader",
70
+ description="Upload trajectory (.txt) and character (.npy) files to load and process them."
71
+ )
72
+
73
+ return interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  if __name__ == "__main__":
76
+ interface = create_trajectory_interface()
77
+ interface.launch()
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  gradio_rerun
2
- scipy==1.14.1
 
 
1
  gradio_rerun
2
+ scipy==1.14.1
3
+ evo==1.30.3