multimodalart HF staff commited on
Commit
c08e39f
·
1 Parent(s): 53d1f76

Update script.py

Browse files
Files changed (1) hide show
  1. script.py +6 -2
script.py CHANGED
@@ -9,8 +9,10 @@ import torch
9
  import re
10
  import argparse
11
  import os
 
12
 
13
  def do_preprocess(class_data_dir):
 
14
  zip_file_path = f"{class_data_dir}/class_images.zip"
15
  with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
16
  zip_ref.extractall(class_data_dir)
@@ -20,7 +22,9 @@ def do_preprocess(class_data_dir):
20
  def do_train(script_args):
21
  # Pass all arguments to trainer.py
22
  print("Starting training...")
23
- subprocess.run(['python', 'trainer.py'] + script_args)
 
 
24
 
25
  def do_inference(dataset_name, output_dir, num_tokens):
26
  widget_content = []
@@ -107,8 +111,8 @@ def main():
107
 
108
  # Proceed with training and inference
109
  if args.class_data_dir:
110
- print("Unzipping dataset")
111
  do_preprocess(args.class_data_dir)
 
112
  do_train(script_args)
113
  print("Training finished!")
114
  do_inference(args.dataset_name, args.output_dir, args.num_new_tokens_per_abstraction)
 
9
  import re
10
  import argparse
11
  import os
12
+ import zipfile
13
 
14
  def do_preprocess(class_data_dir):
15
+ print("Unzipping dataset")
16
  zip_file_path = f"{class_data_dir}/class_images.zip"
17
  with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
18
  zip_ref.extractall(class_data_dir)
 
22
  def do_train(script_args):
23
  # Pass all arguments to trainer.py
24
  print("Starting training...")
25
+ result = subprocess.run(['python', 'trainer.py'] + script_args)
26
+ if result.returncode != 0:
27
+ raise Exception("Training failed.")
28
 
29
  def do_inference(dataset_name, output_dir, num_tokens):
30
  widget_content = []
 
111
 
112
  # Proceed with training and inference
113
  if args.class_data_dir:
 
114
  do_preprocess(args.class_data_dir)
115
+ print("Pre-processing finished!")
116
  do_train(script_args)
117
  print("Training finished!")
118
  do_inference(args.dataset_name, args.output_dir, args.num_new_tokens_per_abstraction)