-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
30 lines (23 loc) · 971 Bytes
/
utils.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
import csv
from glob import glob
from os.path import join
from typing import List
import yaml
from options import AnalysisOptions
from results import AnalysisResult
def list_images(path: str, filetypes: List[str]):
files = []
for filetype in filetypes:
files = files + sorted(glob(join(path, f"*.{filetype}")))
return files
def write_results(options: AnalysisOptions, results: List[AnalysisResult]):
# YAML
with open(join(options.output_directory, f"{options.input_stem}.results.yml"), 'w') as file:
yaml.dump({'features': results}, file, default_flow_style=False)
# CSV
with open(join(options.output_directory, f"{options.input_stem}.results.csv"), 'w') as file:
writer = csv.writer(file, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
if len(results) != 0:
writer.writerow(list(results[0].keys()))
for result in results:
writer.writerow(list(result.values()))