Skip to content

Commit

Permalink
Output comparison (#9)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
marianadeem-10xe and taimur-10xe authored Mar 20, 2023
1 parent 9f900a2 commit beb40aa
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 75 deletions.
16 changes: 11 additions & 5 deletions automate_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,17 @@
except IndexError:
pass

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

# save the config file along with its results
yaml.add_representer(list, utils.represent_list)

with open(f"./out_for_RTL/Results/configs_automate.yml", "w", encoding="utf-8") as file:
yaml.safe_dump(config, file, sort_keys=False, default_flow_style=False)
yaml.dump(config, file, sort_keys=False, Dumper=utils.CustomDumper, width=17000)


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


# place back the contents of the Results folder
shutil.copytree("./out_for_RTL/temp", "./out_for_RTL/Results")
shutil.rmtree("./out_for_RTL/temp")
7 changes: 5 additions & 2 deletions isp_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@
print(50 * "-" + "\nLoading RAW Image Done......\n")
start = time.time()

# save input array if specified

# save pipeline input array
filename = save_dir +"Inpipeline_crop_" + inFile.split(".")[0]
np.save(filename, raw)

Expand Down Expand Up @@ -391,8 +390,12 @@
# save config
with open("./out_frames/" + outFile + dt_string + ".yaml", "w", encoding="utf-8") as file:
yaml.dump(c_yaml, file, sort_keys=False)

# save image
plt.imsave("./out_frames/" + outFile + dt_string + ".png", out_img)

# save array
np.save(save_dir +"Outpipeline_" + inFile.split(".")[0], out_img)

# Pipeline execution time
print(f'\nPipeline Elapsed Time: {time.time() - start:.3f}s')
Empty file added out_for_RTL/.gitkeep
Empty file.
Empty file added out_for_RTL/Results/.gitkeep
Empty file.
127 changes: 60 additions & 67 deletions util/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,55 +55,56 @@
# out_arr[:, :,2] = re_arranged[2,:,:]
# print(np.array_equal(org_arr, out_arr))
#======================================================
from pathlib import Path
foldername = "Results"
in_path = "./out_for_RTL/"+ foldername+"/Input/"
folders = os.listdir(in_path)
single_folder = True

count = 0
if single_folder:
files = os.listdir(in_path)
print("input")
for file in files:
if file[-4:]==".npy":
count+=1
f_path = Path(in_path).joinpath(file)
try:
np_arr = np.load(f_path, allow_pickle=False)
except ValueError:
print(file)
# print(np_arr.shape)
print(np_arr.dtype)
# to debug pickle data error in np.load
# from pathlib import Path
# foldername = "Results"
# in_path = "./out_for_RTL/"+ foldername+"/Input/"
# folders = os.listdir(in_path)
# single_folder = True

# count = 0
# if single_folder:
# files = os.listdir(in_path)
# print("input")
# for file in files:
# if file[-4:]==".npy":
# count+=1
# f_path = Path(in_path).joinpath(file)
# try:
# np_arr = np.load(f_path, allow_pickle=False)
# except ValueError:
# print(file)
# # print(np_arr.shape)
# print(np_arr.dtype)

else:
for folder in folders:
f_path = Path(in_path).joinpath(folder)
for file in os.listdir(f_path):
if file[-4:]==".npy":
count+=1
raw_path = f_path.joinpath(file)
# print(raw_path)
try:
np_arr = np.load(f_path, allow_pickle=False)
except ValueError:
print(file)
np_arr = np.load(raw_path, allow_pickle=False)
# print(np_arr.shape)

out_path = "./out_for_RTL/"+ foldername+"/Output/"
files = os.listdir(out_path)
print("output")
for file in files:
count+=1
f_path = Path(out_path).joinpath(file)
try:
out_np_arr = np.load(f_path, allow_pickle=False)
except ValueError:
print(file)
# print(np_arr.shape)
print(out_np_arr.dtype)
print(count)
# else:
# for folder in folders:
# f_path = Path(in_path).joinpath(folder)
# for file in os.listdir(f_path):
# if file[-4:]==".npy":
# count+=1
# raw_path = f_path.joinpath(file)
# # print(raw_path)
# try:
# np_arr = np.load(f_path, allow_pickle=False)
# except ValueError:
# print(file)
# np_arr = np.load(raw_path, allow_pickle=False)
# # print(np_arr.shape)

# out_path = "./out_for_RTL/"+ foldername+"/Output/"
# files = os.listdir(out_path)
# print("output")
# for file in files:
# count+=1
# f_path = Path(out_path).joinpath(file)
# try:
# out_np_arr = np.load(f_path, allow_pickle=False)
# except ValueError:
# print(file)
# # print(np_arr.shape)
# print(out_np_arr.dtype)
# print(count)

#========================================
# Gt(ground truth) are the verified (during test run) .npy and in/ out files are the ones precessed
Expand All @@ -128,22 +129,14 @@
# print(np.array_equal(gt_file[:,:,0], out_file[0,:,:]))
# print(np.array_equal(gt_file[:,:,1], out_file[1,:,:]))
# print(np.array_equal(gt_file[:,:,2], out_file[2,:,:]))

# print(np.array_equal(lst_ch[2], r_bin))
#======================================================
# test arrange_channel function
path_rearr = "./out_for_RTL/Results/Output/rearranged_Out_gmc_ColorCheckerRaw_100DPs_ISO100_2592x1536_12bits_RGGB.npy"
path_org = "./out_for_RTL/Results/Output/Out_gmc_ColorCheckerRaw_100DPs_ISO100_2592x1536_12bits_RGGB.npy"
# get_RTL_input(path)
# re_arranged = np.load(path_rearr)
# org_arr = np.load(path_org)
# out_arr = np.zeros(org_arr.shape)
# out_arr[:, :,0] = re_arranged[0,:,:]
# out_arr[:, :,1] = re_arranged[1,:,:]
# out_arr[:, :,2] = re_arranged[2,:,:]
# print(np.array_equal(org_arr, out_arr))
#======================================================
from pathlib import Path
path_rearr = "./out_for_RTL/Results/"
new_dir= Path(path_rearr).joinpath(Path("Mine/"))
new_dir.mkdir(parents=True, exist_ok=False)
#========================================
import yaml
import io
from utils import CustomDumper, represent_list
x = np.arange(100).tolist()
yaml.add_representer(list, represent_list)

with open(f"./out_for_RTL/Results/configs_automate.yml", "w", encoding="utf-8") as file:
yaml.dump(x, file, sort_keys=False, default_flow_style=False, Dumper=CustomDumper, width=200)
print(yaml.dump(x, sort_keys=False, default_flow_style=False, Dumper=CustomDumper, width=2000))
#========================================
15 changes: 14 additions & 1 deletion util/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import os
import random
import yaml
from fxpmath import Fxp
import warnings
import shutil
Expand Down Expand Up @@ -232,7 +233,7 @@ def restructure_dir(path, singlefolder, out_module_name):
- Input to pipeline files
"""
files = [f_name for f_name in os.listdir(path) if ".npy" == f_name[-4:]]
print(len(files))
# print(len(files))

in_dir = Path(path).joinpath("Input")
out_dir = Path(path).joinpath("Output")
Expand Down Expand Up @@ -314,3 +315,15 @@ def update_config(config_file, module, keys, values, is_save):
config_file[module]["is_save"] = True
else:
config_file[module]["is_save"] = False

# utilities to save the config_automate exactly as config.yml
class CustomDumper(yaml.Dumper):
def increase_indent(self, flow=False, indentless=False):
return super(CustomDumper, self).increase_indent(flow, False)
def write_line_break(self, data=None):
super().write_line_break(data)
if len(self.indents) == 1:
self.stream.write('\n')

def represent_list(self, data):
return self.represent_sequence(u'tag:yaml.org,2002:seq', data, flow_style=True)

0 comments on commit beb40aa

Please sign in to comment.