Commit
·
53d1f76
1
Parent(s):
ecc48ff
Update script.py
Browse files
script.py
CHANGED
@@ -8,16 +8,15 @@ from huggingface_hub import HfApi
|
|
8 |
import torch
|
9 |
import re
|
10 |
import argparse
|
|
|
11 |
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
|
19 |
-
return parser.parse_args()
|
20 |
-
|
21 |
def do_train(script_args):
|
22 |
# Pass all arguments to trainer.py
|
23 |
print("Starting training...")
|
@@ -97,6 +96,7 @@ def main():
|
|
97 |
parser.add_argument('--output_dir', required=True)
|
98 |
parser.add_argument('--num_new_tokens_per_abstraction', type=int, default=0)
|
99 |
parser.add_argument('--train_text_encoder_ti', action='store_true')
|
|
|
100 |
|
101 |
# Parse known arguments
|
102 |
args, _ = parser.parse_known_args(script_args)
|
@@ -106,6 +106,9 @@ def main():
|
|
106 |
args.num_new_tokens_per_abstraction = 0
|
107 |
|
108 |
# Proceed with training and inference
|
|
|
|
|
|
|
109 |
do_train(script_args)
|
110 |
print("Training finished!")
|
111 |
do_inference(args.dataset_name, args.output_dir, args.num_new_tokens_per_abstraction)
|
|
|
8 |
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)
|
17 |
+
os.remove(zip_file_path)
|
18 |
+
print(os.listdir(zip_file_path))
|
19 |
|
|
|
|
|
20 |
def do_train(script_args):
|
21 |
# Pass all arguments to trainer.py
|
22 |
print("Starting training...")
|
|
|
96 |
parser.add_argument('--output_dir', required=True)
|
97 |
parser.add_argument('--num_new_tokens_per_abstraction', type=int, default=0)
|
98 |
parser.add_argument('--train_text_encoder_ti', action='store_true')
|
99 |
+
parser.add_argument('--class_data_dir', help="Name of the class images dataset")
|
100 |
|
101 |
# Parse known arguments
|
102 |
args, _ = parser.parse_known_args(script_args)
|
|
|
106 |
args.num_new_tokens_per_abstraction = 0
|
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)
|