본문 바로가기

SW programming/Python11

[Python] register file의 address 값 - csv 파일에 저장하는 법 import pandas as pd import numpy as np import torch net: nafnet_v0 save_wgt: True save_io: True rf_info: ./rtl_verif/rf_id.csv csv_path: ./rtl_verif/other_params.csv def __init__(self, cfg, index): self.set_register_file() def set_register_file(self): df = pd.read_csv(self.params.rf_info) for name, mod in self.net.named_modules(): cls_name = mod.__class__.__name__# Conv2d와 같은 상위 레이어 mod.name = n.. 2023. 9. 18.
[Python] DNN 안의 parameter를 .csv 파일에 저장하는 법 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 = s.. 2023. 9. 18.
[Python] Quantization - scaler 값 integer로 변환 Python코드로 Quantization - scaler 값 integer로 변환하기 Scaler = 0.0000296831131 Scaler = np.round(Scaler*(2**24)) # Scaler를 24bit로 표현 print(Scaler) 해당 값이 498로 출력된다. 근데 Scaler를 아래 변환기로 직접 계산해보면 496으로 오차가 발생한다. Scaler를 binary로 표현하면 21bit으로 가능하고, 현재 24bit으로 통일하여 맞추고 싶으므로 binary 값에 LSB 3bit을 0으로 채우면 decimal로 496이 나온다. decimal to binary 변환에서 오차가 발생하는 것으로 보인다. 2023. 9. 18.
[Python] .npy to .mem 파일 변환 Python코드로 .npy to .mem 파일 변환하는 방법 import numpy as np from fxpmath import Fxp layer_name = 'ending.resq' # load .npy file inp1 = np.load(f'./rtl_test/{layer_name}_inp0.npy') # Total data length: 16bit, fraction bit: 0bit, signed inp1_fxp = Fxp(inp1, n_word=16, n_frac=0, signed=True) # save to .mem file with open(f'memfile/{layer_name}_inp0_split0.mem', 'w') as f: for v in inp1_fxp.flatten().bin().. 2023. 9. 18.
[Python Anywhere] Selenium 모듈 적용하는 법 Error message 만약 Python anywhere에서 selenium 패키지(모듈)을 사용했는데 아래와 같은 error message가 출력된다면, 아래 가이드를 따라하면 된다. "Permission denied" OSError: [Errno 13] Permission denied Selenium 패키지가 제대로 설치하기 'pip3 install selenium'을 하는 것이 일반적이나 --user 명령어까지 사용해야 된다. 그리고 혹여나 과거 버전으로 설치되어 있을 수 있으니 --upgrade 명령어까지 추가해서 실행하는 것이 좋다. pip3 install --user --upgrade selenium 소스코드 안에서 Selenium 함수 활용하기 이제 설치는 완료되었고 내가 실행하고자 하는 .. 2021. 5. 27.
[Python 웹 크롤링] Selenium 과 BeautifulSoup의 조합 지난 포스팅 Requests 와 BeautifulSoup의 조합에 이어 2021.05.21 - [SW programming/Python] - [Python 웹 크롤링] Requests 와 BeautifulSoup 의 조합 이번 포스팅에서는 Selenium 과 BeautifulSoup의 조합에 대해 다뤄보도록 하겠습니다. Selenium 와 BeautifulSoup 의 조합 (부제. 자동으로 클릭 접속하여 html 정보 추출) 그렇다. Selenium은 웹 브라우저를 자동으로 제어할 수 있게 해주는 패키지 이다. 아주 아~주 유용하게 사용되는 아이다 :) 제어하고자 하는 웹 브라우저의 Driver를 설치해야 하며, 보통은 'Chrome'을 사용한다. (Chrome driver 설치법은 따로 검색해주세요.).. 2021. 5. 22.
[Python 웹 크롤링] Requests 와 BeautifulSoup 의 조합 웹 크롤링에서 가장 많이 사용하는 라이브러리를 두 번의 포스팅에 걸쳐 설명하고자 합니다. 1탄은 Requests 와 BeautifulSoup 의 조합 (부제. 특정 사이트 url에서 html 정보 추출) 2탄은 Selenium 과 BeautifulSoup 의 조합 (부제. 자동으로 클릭 접속하여 html 정보 추출) Requests 와 BeautifulSoup 의 조합 (부제. 특정 사이트 url에서 html 정보 추출) 이제 여름도 다가오는 데 네이버 쇼핑에서 잘 팔리는 선풍기 순으로 정보 좀 모아볼까? 하면 아래와 같이 네이버 쇼핑 홈페이지에서 선풍기 키워드로 검색된 특정 url로 들어가 html 정보를 추출하면 된다. Requests 와 BeautifulSoup 의 조합의 포인트는 고정된 url 에.. 2021. 5. 21.