utils/monitor.py
class Singletone(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singletone, cls).__call__(*args, **kwargs)
return cls._instances[cls]
class Monitor(metaclass=Singletone):
def __init__(self, csv_path, save_io=False, save_wgt=False, save_qa=True):
self.csv_path = csv_path
self.save_io = save_io
self.save_wgt = save_wgt
self.save_qa = save_qa
def write(self, *val:str):
if self.save_qa:
with open(self.csv_path, 'a') as f:
f.write(','.join(list(val))+'\n')
main.py
from utils.monitor import Monitor
save_io: True
csv_path: ./rtl_verif/other_params.csv
# save to .csv file
S_y = torch.abs(S_x * S_w / S_a) # New Scale
Monitor().write(
'.'.join([self.name, 'S_y']),
str(S_y.numpy()[0])
)
# save to .npy file
save_io = Monitor().save_io
Q_conv = Q_1 * S_y1
if Monitor().save_io:
Q_conv_np = Q_conv.numpy(force=True)
save_path = f'rtl_verif/numpy_array/{self.name}_out.npy'
print(f'saving {save_path}')
np.save(save_path, Q_conv_np)
반응형
'SW programming > Python' 카테고리의 다른 글
[Python] register file의 address 값 - csv 파일에 저장하는 법 (0) | 2023.09.18 |
---|---|
[Python] Quantization - scaler 값 integer로 변환 (0) | 2023.09.18 |
[Python] .npy to .mem 파일 변환 (0) | 2023.09.18 |
[Python Anywhere] Selenium 모듈 적용하는 법 (0) | 2021.05.27 |
[Python 웹 크롤링] Selenium 과 BeautifulSoup의 조합 (2) | 2021.05.22 |
댓글