Skip to content

Commit beb40aa

Browse files
Output comparison (#9)
Added features: Automation Script configs.yaml file format preservation and Results folder preservation * automate_execution currently works on config_automate file to generate RTL compatible results. * added in_single_folder flag to set the structure of the out_for_RTL folder. If True, all input files are saved in a single folder. * - automate_execution.py works on configs.yml now instead of a separate config_automate.yml. - added is_save flag in configs.yml * - verified results by matching .npy files, they match. - exception added if ValueError is encountered while loading np arrays. * - foldername(line 63) now specified by datetime obj - added compare_output file (Inprogress) - made chnages to handle new foldername in rename_to_RTL in utils.py * output of the default modules can now by saved using is_save flag in automate_execution script. * To test multiple modules, type of DUT changed from str to list. * added input_ext variable to specify raw file extension. * created Results folder in out_for_RTL. This folder will save the input and output arrays to ISP piepline, whether generted while executing isp_pipeline.py individually or using the auatomation script. * Added functions in utils.py to dump config file in a more readable format. * added .gitkeep file in results * added .gitkeep file in out_for _RTL --------- Co-authored-by: taimur-10xe <92528065+taimur-10xe@users.noreply.github.com>
1 parent 9f900a2 commit beb40aa

File tree

6 files changed

+90
-75
lines changed

6 files changed

+90
-75
lines changed

automate_execution.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,17 @@
124124
except IndexError:
125125
pass
126126

127-
# make directory called Results to save outputs of this run
128-
if not os.path.exists("./out_for_RTL/Results"):
129-
os.mkdir("./out_for_RTL/Results")
127+
# Empty the Results folder in temp folder
128+
shutil.copytree("./out_for_RTL/Results", "./out_for_RTL/temp")
129+
shutil.rmtree("./out_for_RTL/Results")
130+
os.mkdir("./out_for_RTL/Results")
130131

131132
# save the config file along with its results
133+
yaml.add_representer(list, utils.represent_list)
134+
132135
with open(f"./out_for_RTL/Results/configs_automate.yml", "w", encoding="utf-8") as file:
133-
yaml.safe_dump(config, file, sort_keys=False, default_flow_style=False)
136+
yaml.dump(config, file, sort_keys=False, Dumper=utils.CustomDumper, width=17000)
137+
134138

135139
# loop over images
136140
DIRECTORY_CONTENT = os.listdir(DATASET_PATH)
@@ -172,4 +176,6 @@
172176
# convert the saved numpy arrays to bin files as required by the RTL
173177
utils.get_RTL_input(path, in_single_folder, input_ext)
174178

175-
179+
# place back the contents of the Results folder
180+
shutil.copytree("./out_for_RTL/temp", "./out_for_RTL/Results")
181+
shutil.rmtree("./out_for_RTL/temp")

isp_pipeline.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@
101101
print(50 * "-" + "\nLoading RAW Image Done......\n")
102102
start = time.time()
103103

104-
# save input array if specified
105-
104+
# save pipeline input array
106105
filename = save_dir +"Inpipeline_crop_" + inFile.split(".")[0]
107106
np.save(filename, raw)
108107

@@ -391,8 +390,12 @@
391390
# save config
392391
with open("./out_frames/" + outFile + dt_string + ".yaml", "w", encoding="utf-8") as file:
393392
yaml.dump(c_yaml, file, sort_keys=False)
393+
394394
# save image
395395
plt.imsave("./out_frames/" + outFile + dt_string + ".png", out_img)
396396

397+
# save array
398+
np.save(save_dir +"Outpipeline_" + inFile.split(".")[0], out_img)
399+
397400
# Pipeline execution time
398401
print(f'\nPipeline Elapsed Time: {time.time() - start:.3f}s')

out_for_RTL/.gitkeep

Whitespace-only changes.

out_for_RTL/Results/.gitkeep

Whitespace-only changes.

util/test_func.py

Lines changed: 60 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -55,55 +55,56 @@
5555
# out_arr[:, :,2] = re_arranged[2,:,:]
5656
# print(np.array_equal(org_arr, out_arr))
5757
#======================================================
58-
from pathlib import Path
59-
foldername = "Results"
60-
in_path = "./out_for_RTL/"+ foldername+"/Input/"
61-
folders = os.listdir(in_path)
62-
single_folder = True
63-
64-
count = 0
65-
if single_folder:
66-
files = os.listdir(in_path)
67-
print("input")
68-
for file in files:
69-
if file[-4:]==".npy":
70-
count+=1
71-
f_path = Path(in_path).joinpath(file)
72-
try:
73-
np_arr = np.load(f_path, allow_pickle=False)
74-
except ValueError:
75-
print(file)
76-
# print(np_arr.shape)
77-
print(np_arr.dtype)
58+
# to debug pickle data error in np.load
59+
# from pathlib import Path
60+
# foldername = "Results"
61+
# in_path = "./out_for_RTL/"+ foldername+"/Input/"
62+
# folders = os.listdir(in_path)
63+
# single_folder = True
64+
65+
# count = 0
66+
# if single_folder:
67+
# files = os.listdir(in_path)
68+
# print("input")
69+
# for file in files:
70+
# if file[-4:]==".npy":
71+
# count+=1
72+
# f_path = Path(in_path).joinpath(file)
73+
# try:
74+
# np_arr = np.load(f_path, allow_pickle=False)
75+
# except ValueError:
76+
# print(file)
77+
# # print(np_arr.shape)
78+
# print(np_arr.dtype)
7879

79-
else:
80-
for folder in folders:
81-
f_path = Path(in_path).joinpath(folder)
82-
for file in os.listdir(f_path):
83-
if file[-4:]==".npy":
84-
count+=1
85-
raw_path = f_path.joinpath(file)
86-
# print(raw_path)
87-
try:
88-
np_arr = np.load(f_path, allow_pickle=False)
89-
except ValueError:
90-
print(file)
91-
np_arr = np.load(raw_path, allow_pickle=False)
92-
# print(np_arr.shape)
93-
94-
out_path = "./out_for_RTL/"+ foldername+"/Output/"
95-
files = os.listdir(out_path)
96-
print("output")
97-
for file in files:
98-
count+=1
99-
f_path = Path(out_path).joinpath(file)
100-
try:
101-
out_np_arr = np.load(f_path, allow_pickle=False)
102-
except ValueError:
103-
print(file)
104-
# print(np_arr.shape)
105-
print(out_np_arr.dtype)
106-
print(count)
80+
# else:
81+
# for folder in folders:
82+
# f_path = Path(in_path).joinpath(folder)
83+
# for file in os.listdir(f_path):
84+
# if file[-4:]==".npy":
85+
# count+=1
86+
# raw_path = f_path.joinpath(file)
87+
# # print(raw_path)
88+
# try:
89+
# np_arr = np.load(f_path, allow_pickle=False)
90+
# except ValueError:
91+
# print(file)
92+
# np_arr = np.load(raw_path, allow_pickle=False)
93+
# # print(np_arr.shape)
94+
95+
# out_path = "./out_for_RTL/"+ foldername+"/Output/"
96+
# files = os.listdir(out_path)
97+
# print("output")
98+
# for file in files:
99+
# count+=1
100+
# f_path = Path(out_path).joinpath(file)
101+
# try:
102+
# out_np_arr = np.load(f_path, allow_pickle=False)
103+
# except ValueError:
104+
# print(file)
105+
# # print(np_arr.shape)
106+
# print(out_np_arr.dtype)
107+
# print(count)
107108

108109
#========================================
109110
# Gt(ground truth) are the verified (during test run) .npy and in/ out files are the ones precessed
@@ -128,22 +129,14 @@
128129
# print(np.array_equal(gt_file[:,:,0], out_file[0,:,:]))
129130
# print(np.array_equal(gt_file[:,:,1], out_file[1,:,:]))
130131
# print(np.array_equal(gt_file[:,:,2], out_file[2,:,:]))
131-
132-
# print(np.array_equal(lst_ch[2], r_bin))
133-
#======================================================
134-
# test arrange_channel function
135-
path_rearr = "./out_for_RTL/Results/Output/rearranged_Out_gmc_ColorCheckerRaw_100DPs_ISO100_2592x1536_12bits_RGGB.npy"
136-
path_org = "./out_for_RTL/Results/Output/Out_gmc_ColorCheckerRaw_100DPs_ISO100_2592x1536_12bits_RGGB.npy"
137-
# get_RTL_input(path)
138-
# re_arranged = np.load(path_rearr)
139-
# org_arr = np.load(path_org)
140-
# out_arr = np.zeros(org_arr.shape)
141-
# out_arr[:, :,0] = re_arranged[0,:,:]
142-
# out_arr[:, :,1] = re_arranged[1,:,:]
143-
# out_arr[:, :,2] = re_arranged[2,:,:]
144-
# print(np.array_equal(org_arr, out_arr))
145-
#======================================================
146-
from pathlib import Path
147-
path_rearr = "./out_for_RTL/Results/"
148-
new_dir= Path(path_rearr).joinpath(Path("Mine/"))
149-
new_dir.mkdir(parents=True, exist_ok=False)
132+
#========================================
133+
import yaml
134+
import io
135+
from utils import CustomDumper, represent_list
136+
x = np.arange(100).tolist()
137+
yaml.add_representer(list, represent_list)
138+
139+
with open(f"./out_for_RTL/Results/configs_automate.yml", "w", encoding="utf-8") as file:
140+
yaml.dump(x, file, sort_keys=False, default_flow_style=False, Dumper=CustomDumper, width=200)
141+
print(yaml.dump(x, sort_keys=False, default_flow_style=False, Dumper=CustomDumper, width=2000))
142+
#========================================

util/utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import os
99
import random
10+
import yaml
1011
from fxpmath import Fxp
1112
import warnings
1213
import shutil
@@ -232,7 +233,7 @@ def restructure_dir(path, singlefolder, out_module_name):
232233
- Input to pipeline files
233234
"""
234235
files = [f_name for f_name in os.listdir(path) if ".npy" == f_name[-4:]]
235-
print(len(files))
236+
# print(len(files))
236237

237238
in_dir = Path(path).joinpath("Input")
238239
out_dir = Path(path).joinpath("Output")
@@ -314,3 +315,15 @@ def update_config(config_file, module, keys, values, is_save):
314315
config_file[module]["is_save"] = True
315316
else:
316317
config_file[module]["is_save"] = False
318+
319+
# utilities to save the config_automate exactly as config.yml
320+
class CustomDumper(yaml.Dumper):
321+
def increase_indent(self, flow=False, indentless=False):
322+
return super(CustomDumper, self).increase_indent(flow, False)
323+
def write_line_break(self, data=None):
324+
super().write_line_break(data)
325+
if len(self.indents) == 1:
326+
self.stream.write('\n')
327+
328+
def represent_list(self, data):
329+
return self.represent_sequence(u'tag:yaml.org,2002:seq', data, flow_style=True)

0 commit comments

Comments
 (0)