Spanicin commited on
Commit
dd6f240
·
verified ·
1 Parent(s): 4c6735a

Update app_parallel.py

Browse files
Files changed (1) hide show
  1. app_parallel.py +20 -4
app_parallel.py CHANGED
@@ -109,7 +109,7 @@ def process_chunk(audio_chunk, preprocessed_data, args):
109
 
110
  first_coeff_path = preprocessed_data["first_coeff_path"]
111
  crop_pic_path = preprocessed_data["crop_pic_path"]
112
- crop_info_path = preprocessed_data["crop_info_path"]
113
  with open(crop_info_path , "rb") as f:
114
  crop_info = pickle.load(f)
115
 
@@ -225,15 +225,31 @@ def run_preprocessing(args):
225
  global path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting
226
  first_frame_dir = os.path.join(args.result_dir, 'first_frame_dir')
227
  os.makedirs(first_frame_dir, exist_ok=True)
228
- fixed_temp_dir = "/home/user/app/preprocess_data/"
229
- # os.makedirs(fixed_temp_dir, exist_ok=True)
 
 
230
  preprocessed_data_path = os.path.join(fixed_temp_dir, "preprocessed_data.pkl")
231
 
232
  if os.path.exists(preprocessed_data_path) and args.image_hardcoded == "yes":
233
- print("Loading preprocessed data...")
234
  with open(preprocessed_data_path, "rb") as f:
235
  preprocessed_data = pickle.load(f)
236
  print("Loaded existing preprocessed data from:", preprocessed_data_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
 
238
  return preprocessed_data
239
 
 
109
 
110
  first_coeff_path = preprocessed_data["first_coeff_path"]
111
  crop_pic_path = preprocessed_data["crop_pic_path"]
112
+ crop_info_path = preprocessed_data["crop_info"]
113
  with open(crop_info_path , "rb") as f:
114
  crop_info = pickle.load(f)
115
 
 
225
  global path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting
226
  first_frame_dir = os.path.join(args.result_dir, 'first_frame_dir')
227
  os.makedirs(first_frame_dir, exist_ok=True)
228
+
229
+ # Check if preprocessed data already exists
230
+ fixed_temp_dir = "C:/Users/fd01076/Downloads/preprocess_data"
231
+ os.makedirs(fixed_temp_dir, exist_ok=True)
232
  preprocessed_data_path = os.path.join(fixed_temp_dir, "preprocessed_data.pkl")
233
 
234
  if os.path.exists(preprocessed_data_path) and args.image_hardcoded == "yes":
 
235
  with open(preprocessed_data_path, "rb") as f:
236
  preprocessed_data = pickle.load(f)
237
  print("Loaded existing preprocessed data from:", preprocessed_data_path)
238
+ else:
239
+ preprocess_model = CropAndExtract(path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting, args.device)
240
+ first_coeff_path, crop_pic_path, crop_info = preprocess_model.generate(args.source_image, first_frame_dir, args.preprocess, source_image_flag=True)
241
+
242
+ if not first_coeff_path:
243
+ raise Exception("Failed to get coefficients")
244
+
245
+ # Save the preprocessed data
246
+ preprocessed_data = {
247
+ "first_coeff_path": first_coeff_path,
248
+ "crop_pic_path": crop_pic_path,
249
+ "crop_info": crop_info
250
+ }
251
+ with open(preprocessed_data_path, "wb") as f:
252
+ pickle.dump(preprocessed_data, f)
253
 
254
  return preprocessed_data
255