forked from CiaraStrawberry/svd-temporal-controlnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_json.py
44 lines (34 loc) · 1.6 KB
/
remove_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import json
# Read data from 'data.json' file
# with open('/fs/nexus-scratch/sjxu/svd-temporal-controlnet/relighting/training.json', 'r') as infile:
# data_list = json.load(infile)
data_list = [
json.loads(line) for line in open(f"/fs/nexus-scratch/sjxu/svd-temporal-controlnet/relighting/training.json", "r").read().splitlines()
]
input_file = "/fs/nexus-scratch/sjxu/svd-temporal-controlnet/relighting/training.json"
output_file = "/fs/nexus-scratch/sjxu/svd-temporal-controlnet/relighting/training_edit.json"
# Values to filter out
filter_values = {"D", "E", "F"}
# # Filter out entries with target_image or conditioning_image in filter_values
# filtered_data = [
# item for item in data_list
# if item["target_image"] not in filter_values and item["conditioning_image"] not in filter_values
# ]
# print(filtered_data)
# # Save the filtered data to a new JSON file
# with open('/fs/nexus-scratch/sjxu/svd-temporal-controlnet/relighting/training_edit.json', 'w') as outfile:
# json.dump(filtered_data, outfile, indent=4)
# print("Filtered data saved to 'filtered_data.json'")
# Read the file and filter the data
filtered_data = []
with open(input_file, 'r') as infile:
for line in infile:
item = json.loads(line)
if item["target_image"] not in filter_values and item["conditioning_image"] not in filter_values:
filtered_data.append(item)
# Write the filtered data to the output file
with open(output_file, 'w') as outfile:
for item in filtered_data:
json_line = json.dumps(item)
outfile.write(json_line + '\n')
print(f"Filtered data saved to '{output_file}'")