Download tools/make_samples.py from ymin98/WACA-UNet: direct link, hf CLI and curl.
- Browser
- Download file 4.17 kB
-
https://huggingface.co/spaces/ymin98/WACA-UNet/resolve/main/tools/make_samples.py
- Command line
-
hf download hf://spaces/ymin98/WACA-UNet/tools/make_samples.py
-
curl -L -o make_samples.py https://huggingface.co/spaces/ymin98/WACA-UNet/resolve/main/tools/make_samples.py
4.17 kB
| # tools/prepare_samples.py | |
| """ | |
| ์์ : | |
| cd waca_unet_space | |
| python tools/prepare_samples.py --root /data/ICCAD_2023/hidden-real-circuit-data \ | |
| --configs_path configs/began_iccad_fake \ | |
| --dataset iccad_hidden \ | |
| --indices 0 1 2 3 4 | |
| - build_dataset_iccad_hidden / build_dataset_iccad_real ์ ์ด์ฉํด์ | |
| (input, target, casename)์ ๊ฐ์ ธ์จ ๋ค, input๋ง samples/ ํด๋์ ์ ์ฅ. | |
| - input์ IRDropDataset์์ ๋ฐํํ๋ (C,H,W) ํ ์(์ ๊ทํ ์๋ฃ)๋ฅผ ๊ทธ๋๋ก npy๋ก ์ ์ฅ. | |
| """ | |
| import os | |
| import argparse | |
| import numpy as np | |
| import torch | |
| from config import get_config | |
| from ir_dataset import ( | |
| build_dataset_iccad_hidden, | |
| build_dataset_iccad_real, | |
| ) | |
| def parse_args(): | |
| p = argparse.ArgumentParser() | |
| p.add_argument( | |
| "--root", | |
| type=str, | |
| help="ICCAD hidden/real root path. ์: /data/ICCAD_2023/hidden-real-circuit-data or /data/ICCAD_2023/real-circuit-data", | |
| default='/data/ICCAD_2023/hidden-real-circuit-data', | |
| ) | |
| p.add_argument( | |
| "--dataset", | |
| type=str, | |
| choices=["iccad_hidden", "iccad_real"], | |
| default="iccad_real", | |
| ) | |
| p.add_argument( | |
| "--img_size", | |
| type=int, | |
| default=384, | |
| ) | |
| p.add_argument( | |
| "--in_ch", | |
| type=int, | |
| default=25, | |
| ) | |
| p.add_argument( | |
| "--configs_path", | |
| type=str, | |
| default="/workspace/IR_Drop_prior_study/XICCAD/configs/cfirst/began_iccad_fake/stats_1um.json", | |
| help="stats_1um.json ์ด ๋ค์ด์๋ ํด๋", | |
| ) | |
| p.add_argument( | |
| "--unit", | |
| type=str, | |
| default="1um", | |
| ) | |
| p.add_argument( | |
| "--indices", | |
| type=int, | |
| nargs="+", | |
| default=[0, 1, 2, 3, 4], | |
| help="์์ ์ํ๋ก ๋ฝ์ dataset ์ธ๋ฑ์ค๋ค", | |
| ) | |
| p.add_argument( | |
| "--out_dir", | |
| type=str, | |
| default="samples", | |
| help="npy๋ฅผ ์ ์ฅํ ๋๋ ํ ๋ฆฌ", | |
| ) | |
| return p.parse_args() | |
| def main(): | |
| args = parse_args() | |
| os.makedirs(args.out_dir, exist_ok=True) | |
| # ํ์ต ๋ ์ฐ๋ ํต๊ณ config ๋ก๋ (๋น์ ์ get_config ์๊ทธ๋์ฒ์ ๋ง๊ฒ ์กฐ์ ) | |
| norm_config = get_config( | |
| args.unit, | |
| configs_path=args.configs_path, | |
| dataset_name="began_iccad_fake", | |
| ) | |
| common_kwargs = dict( | |
| img_size=args.img_size, | |
| in_ch=args.in_ch, | |
| train=False, | |
| use_raw=False, # ํ์ต ๋์ ๋์ผํ๊ฒ z-score ๋ฑ์ผ๋ก ์ ๊ทํ๋ ์ ๋ ฅ ์ฌ์ฉ | |
| input_norm_type="z_score", | |
| target_norm_type="raw", | |
| target_layers=[], # ์ ์ฒด ์ข ํฉ IR-drop (์ด๋ฏธ npy์ ํตํฉ๋ ๊ฒฝ์ฐ) | |
| use_pdn_density=True, | |
| use_pad_distance=True, | |
| use_comprehensive_feature=True, | |
| norm_config=norm_config, | |
| return_case=True, # (x, y, casename) ๋ฐํ | |
| interpolation="lanczos", | |
| ) | |
| if args.dataset == "iccad_hidden": | |
| dataset = build_dataset_iccad_hidden( | |
| root_path=args.root, | |
| **common_kwargs, | |
| ) | |
| else: | |
| dataset = build_dataset_iccad_real( | |
| root_path=args.root, | |
| **common_kwargs, | |
| ) | |
| # build_dataset_* ๊ฐ (train,val) ํํ์ ๋ฐํํ๋ ๊ฒฝ์ฐ ๋์ | |
| if isinstance(dataset, (tuple, list)) and len(dataset) == 2: | |
| dataset = dataset[1] # val set์ ์์ ๋ก ์ฌ์ฉํ๊ฑฐ๋, ํ์์ ๋ฐ๋ผ ์์ | |
| print(f"Dataset length: {len(dataset)}") | |
| for idx in args.indices: | |
| if idx >= len(dataset): | |
| print(f"[WARN] index {idx} is out of range, skip.") | |
| continue | |
| sample = dataset[idx] | |
| if len(sample) == 3: | |
| x, y, casename = sample | |
| else: | |
| x, y = sample | |
| casename = f"idx{idx}" | |
| if isinstance(x, torch.Tensor): | |
| x_np = x.detach().cpu().numpy() | |
| else: | |
| x_np = np.asarray(x) | |
| out_name = f"{casename}_input.npy" | |
| out_path = os.path.join(args.out_dir, out_name) | |
| np.save(out_path, x_np) | |
| print(f"Saved: {out_path} (shape={x_np.shape})") | |
| print("Done.") | |
| if __name__ == "__main__": | |
| main() | |