qninhdt commited on
Commit
4a0bcb8
β€’
1 Parent(s): 9ee2693
.gitignore CHANGED
@@ -1,2 +1,3 @@
1
  __pycache__
2
- datasets
 
 
1
  __pycache__
2
+ datasets
3
+ *.zip
scripts/build_cyclegan_dataset.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import click
3
+ import json
4
+ from tqdm import tqdm
5
+
6
+
7
+ @click.command()
8
+ @click.option("--swim_dir", type=str, default="datasets/swim_data")
9
+ @click.option("--output_dir", type=str, default="datasets/swim_data_cyclegan")
10
+ @click.option("--type", type=str, help="fog|rain|snow|night", required=True)
11
+ def build_cyclegan_dataset(swim_dir: str, output_dir: str, type: str):
12
+ # build the dataset with format
13
+ # swim_data_cyclegan
14
+ # β”œβ”€β”€ trainA
15
+ # β”‚ β”œβ”€β”€ 000000.jpg
16
+ # β”‚ β”œβ”€β”€ ...
17
+ # β”œβ”€β”€ trainB
18
+ # β”‚ β”œβ”€β”€ 000000.jpg
19
+ # β”‚ β”œβ”€β”€ ...
20
+ # |── testA
21
+ # β”‚ β”œβ”€β”€ 000000.jpg
22
+ # β”‚ β”œβ”€β”€ ...
23
+ # |── testB
24
+ # β”‚ β”œβ”€β”€ 000000.jpg
25
+ # β”‚ β”œβ”€β”€ ...
26
+ #
27
+ # note:
28
+ # trainA and trainB are extracted from swim_data train set
29
+ # testA and testB are extracted from swim_data val set
30
+ # A - clear
31
+ # B - fog|rain|snow|night
32
+
33
+ os.makedirs(output_dir, exist_ok=True)
34
+ os.makedirs(os.path.join(output_dir, "trainA"), exist_ok=True)
35
+ os.makedirs(os.path.join(output_dir, "trainB"), exist_ok=True)
36
+ os.makedirs(os.path.join(output_dir, "testA"), exist_ok=True)
37
+ os.makedirs(os.path.join(output_dir, "testB"), exist_ok=True)
38
+
39
+ with open(os.path.join(swim_dir, "train", "labels.json"), "r") as f:
40
+ train_labels = json.load(f)
41
+
42
+ with open(os.path.join(swim_dir, "val", "labels.json"), "r") as f:
43
+ val_labels = json.load(f)
44
+
45
+ for label in tqdm(train_labels, desc="train"):
46
+ if label["weather"] == type:
47
+ os.system(
48
+ f"cp {os.path.join(swim_dir, 'train', 'images', label['name'])} {os.path.join(output_dir, 'trainB', label['name'])}"
49
+ )
50
+ elif label["weather"] == "clear":
51
+ os.system(
52
+ f"cp {os.path.join(swim_dir, 'train', 'images', label['name'])} {os.path.join(output_dir, 'trainA', label['name'])}"
53
+ )
54
+
55
+ for label in tqdm(val_labels, desc="val"):
56
+ if label["weather"] == type:
57
+ os.system(
58
+ f"cp {os.path.join(swim_dir, 'val', 'images', label['name'])} {os.path.join(output_dir, 'testB', label['name'])}"
59
+ )
60
+ elif label["weather"] == "clear":
61
+ os.system(
62
+ f"cp {os.path.join(swim_dir, 'val', 'images', label['name'])} {os.path.join(output_dir, 'testA', label['name'])}"
63
+ )
64
+
65
+
66
+ if __name__ == "__main__":
67
+ build_cyclegan_dataset()
scripts/build_swim_dataset.py CHANGED
@@ -162,8 +162,8 @@ def build_swim_dataset(bdd100k_dir: str, acdc_dir: str, output_dir: str):
162
  timeofday_ = "daytime"
163
  weather_ = "clear"
164
  else:
165
- timeofday_ = "daytime" if weather == "night" else "night"
166
- weather_ = weather
167
 
168
  labels.append(
169
  {
@@ -228,8 +228,8 @@ def build_swim_dataset(bdd100k_dir: str, acdc_dir: str, output_dir: str):
228
  timeofday_ = "daytime"
229
  weather_ = "clear"
230
  else:
231
- timeofday_ = "daytime" if weather == "night" else "night"
232
- weather_ = weather
233
 
234
  labels.append(
235
  {
 
162
  timeofday_ = "daytime"
163
  weather_ = "clear"
164
  else:
165
+ timeofday_ = "night" if weather == "night" else "daytime"
166
+ weather_ = "clear" if weather == "night" else weather
167
 
168
  labels.append(
169
  {
 
228
  timeofday_ = "daytime"
229
  weather_ = "clear"
230
  else:
231
+ timeofday_ = "night" if weather == "night" else "daytime"
232
+ weather_ = "clear" if weather == "night" else weather
233
 
234
  labels.append(
235
  {