ercanburak commited on
Commit
cebe383
1 Parent(s): 89de2dd

download files from drive

Browse files
Files changed (4) hide show
  1. app.py +18 -9
  2. gdrive.py +61 -0
  3. requirements.txt +1 -0
  4. utils.py +2 -2
app.py CHANGED
@@ -1,9 +1,11 @@
1
  import os
2
  import subprocess
 
3
 
4
  import streamlit as st
5
 
6
  from utils import get_configs, get_display_names, get_path_for_viz, get_video_height, get_text_str
 
7
 
8
  # st.header("EVREAL - Event-based Video Reconstruction Evaluation and Analysis Library")
9
  #
@@ -19,8 +21,6 @@ from utils import get_configs, get_display_names, get_path_for_viz, get_video_he
19
 
20
  st.title("Result Analysis Tool")
21
 
22
- data_base_path = "/home/bercan/ebv/evreal_data"
23
-
24
  font_path = "font/Ubuntu-B.ttf"
25
 
26
  dataset_cfg_path = os.path.join("cfg", "dataset")
@@ -105,6 +105,11 @@ crop_str = "crop=trunc(iw/2)*2:trunc(ih/2)*2"
105
  pad_str = "pad=ceil(iw/2)*2+{}:ceil(ih/2)*2+{}:{}:{}".format(padding*2, padding*2, padding, padding)
106
  num_elements = num_rows * num_cols
107
 
 
 
 
 
 
108
  w = selected_dataset["width"]
109
  h = selected_dataset["height"]
110
  input_filter_parts = []
@@ -123,17 +128,21 @@ for row_idx in range(num_rows):
123
  cur_model = selected_models[col_idx]
124
  if cur_model['name'] == "gt":
125
  if row_idx < len(gt_viz):
126
- video_path = get_path_for_viz(data_base_path, selected_dataset, selected_sequence, cur_model, gt_viz[row_idx])
127
- if not os.path.isfile(video_path):
128
- raise ValueError("Video path does not exist: " + video_path)
 
 
129
  gt_viz_indices.append(vid_idx)
130
  else:
131
  continue
132
  else:
133
  if row_idx < len(model_viz):
134
- video_path = get_path_for_viz(data_base_path, selected_dataset, selected_sequence, cur_model, model_viz[row_idx])
135
- if not os.path.isfile(video_path):
136
- raise ValueError("Video path does not exist: " + video_path)
 
 
137
  else:
138
  continue
139
 
@@ -155,7 +164,7 @@ for row_idx in range(num_rows):
155
  input_filter_parts.append(input_filter_part)
156
  xstack_input_part = "[v{}]".format(vid_idx)
157
  xstack_input_parts.append(xstack_input_part)
158
- video_paths.append(video_path)
159
  if row_idx == 0 or col_idx > 0:
160
  layout_w_parts = [str(left_pad)] + ["w{}".format(i) for i in range(col_idx)]
161
  layout_w = "+".join(layout_w_parts)
 
1
  import os
2
  import subprocess
3
+ import glob
4
 
5
  import streamlit as st
6
 
7
  from utils import get_configs, get_display_names, get_path_for_viz, get_video_height, get_text_str
8
+ from gdrive import download_file
9
 
10
  # st.header("EVREAL - Event-based Video Reconstruction Evaluation and Analysis Library")
11
  #
 
21
 
22
  st.title("Result Analysis Tool")
23
 
 
 
24
  font_path = "font/Ubuntu-B.ttf"
25
 
26
  dataset_cfg_path = os.path.join("cfg", "dataset")
 
105
  pad_str = "pad=ceil(iw/2)*2+{}:ceil(ih/2)*2+{}:{}:{}".format(padding*2, padding*2, padding, padding)
106
  num_elements = num_rows * num_cols
107
 
108
+ # remove previous temp data
109
+ files = glob.glob('temp_data/temp_*.mp4')
110
+ for f in files:
111
+ os.remove(f)
112
+
113
  w = selected_dataset["width"]
114
  h = selected_dataset["height"]
115
  input_filter_parts = []
 
128
  cur_model = selected_models[col_idx]
129
  if cur_model['name'] == "gt":
130
  if row_idx < len(gt_viz):
131
+ video_path = get_path_for_viz(selected_dataset, selected_sequence, cur_model, gt_viz[row_idx])
132
+ local_video_path = os.path.join("temp_data", "temp_{}.mp4".format(vid_idx))
133
+ download_file(video_path, local_video_path)
134
+ if not os.path.isfile(local_video_path):
135
+ raise ValueError("Failed to download video: " + video_path)
136
  gt_viz_indices.append(vid_idx)
137
  else:
138
  continue
139
  else:
140
  if row_idx < len(model_viz):
141
+ video_path = get_path_for_viz(selected_dataset, selected_sequence, cur_model, model_viz[row_idx])
142
+ local_video_path = os.path.join("temp_data", "temp_{}.mp4".format(vid_idx))
143
+ download_file(video_path, local_video_path)
144
+ if not os.path.isfile(local_video_path):
145
+ raise ValueError("Failed to download video: " + video_path)
146
  else:
147
  continue
148
 
 
164
  input_filter_parts.append(input_filter_part)
165
  xstack_input_part = "[v{}]".format(vid_idx)
166
  xstack_input_parts.append(xstack_input_part)
167
+ video_paths.append(local_video_path)
168
  if row_idx == 0 or col_idx > 0:
169
  layout_w_parts = [str(left_pad)] + ["w{}".format(i) for i in range(col_idx)]
170
  layout_w = "+".join(layout_w_parts)
gdrive.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ from pydrive2.auth import GoogleAuth
4
+ from pydrive2.drive import GoogleDrive
5
+ from oauth2client.service_account import ServiceAccountCredentials
6
+
7
+
8
+ def login_with_service_account():
9
+ scope = ["https://www.googleapis.com/auth/drive"]
10
+ gauth = GoogleAuth()
11
+ gauth.auth_method = 'service'
12
+ gauth.credentials = ServiceAccountCredentials.from_json_keyfile_name('evreal-bf06ca1ac056.json', scope)
13
+ return gauth
14
+
15
+
16
+ gauth = login_with_service_account()
17
+ drive = GoogleDrive(gauth)
18
+
19
+
20
+ def get_file_id_inside_folder(drive, folder_id, file_name):
21
+ file_list = drive.ListFile({'q': "'{}' in parents and trashed=false".format(folder_id)}).GetList()
22
+ for file in file_list:
23
+ if file['title'] == file_name:
24
+ return file['id']
25
+ return None
26
+
27
+
28
+ def get_file_id_for_file_path(drive, file_path):
29
+ # file_parts = os.path.split(file_path)
30
+ path = os.path.normpath(file_path)
31
+ file_parts = path.split(os.sep)
32
+ file_id = '1-5zmRu3Od9s2dYu1S01u4aC2ihAmo1K2'
33
+ for file_part in file_parts:
34
+ if file_part == '':
35
+ continue
36
+ file_id = get_file_id_inside_folder(drive, file_id, file_part)
37
+ if file_id is None:
38
+ return None
39
+
40
+ return file_id
41
+
42
+
43
+ def download_file(file_path, local_path):
44
+ file_id = get_file_id_for_file_path(drive, file_path)
45
+ if file_id is None:
46
+ return False
47
+ file = drive.CreateFile({'id': file_id})
48
+ os.makedirs(os.path.dirname(local_path), exist_ok=True)
49
+ file.GetContentFile(local_path)
50
+ return True
51
+
52
+
53
+ # test if main
54
+ if __name__ == "__main__":
55
+ drive_file_path = "0000_000000/ECD_calibration/videos/recon.mp4"
56
+ # drive_file_path = "test.txt"
57
+ local_file_path = os.path.join("temp_data", drive_file_path)
58
+ # gauth = login_with_service_account()
59
+ # drive = GoogleDrive(gauth)
60
+ os.makedirs(os.path.dirname(local_file_path), exist_ok=True)
61
+ download_file(drive_file_path, local_file_path)
requirements.txt CHANGED
@@ -1 +1,2 @@
1
  ffmpeg-python
 
 
1
  ffmpeg-python
2
+ PyDrive2
utils.py CHANGED
@@ -31,9 +31,9 @@ def get_display_names(configs):
31
  return display_names
32
 
33
 
34
- def get_path_for_viz(base_path, dataset, sequence, model, viz):
35
  dat_seq = "_".join([dataset["name"], sequence])
36
- video_path = os.path.join(base_path, model['model_id'], dat_seq, "videos", viz["name"] + ".mp4")
37
  return video_path
38
 
39
 
 
31
  return display_names
32
 
33
 
34
+ def get_path_for_viz(dataset, sequence, model, viz):
35
  dat_seq = "_".join([dataset["name"], sequence])
36
+ video_path = os.path.join(model['model_id'], dat_seq, "videos", viz["name"] + ".mp4")
37
  return video_path
38
 
39