You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to use center crop for fastflow, but after adding it the performance drop quite a lot.
I not sure is is the way I add transform got issue, can someone help me to check?
def _build_eval_transform(h: int, w: int) -> dict:
s = 0.875
pre_h = int(math.ceil(h / s))
pre_w = int(math.ceil(w / s))
return {
"class_path": "torchvision.transforms.v2.Compose",
"init_args": {"transforms": [
{"class_path": "torchvision.transforms.v2.Resize",
"init_args": {"size": [pre_h, pre_w], "antialias": True}},
{"class_path": "torchvision.transforms.v2.CenterCrop",
"init_args": {"size": [int(h), int(w)]}},
{"class_path": "torchvision.transforms.v2.Normalize",
"init_args": {"mean": [0.485, 0.456, 0.406],
"std": [0.229, 0.224, 0.225]}}
]}
}
def _patch_yaml(cfg_path: str, args) -> dict:
yaml = YAML()
with open(cfg_path, "r", encoding="utf-8") as fp:
cfg = yaml.load(fp)
trainer_cfg = cfg.setdefault("trainer", {})
data_args = cfg["data"]["init_args"]
model_args = cfg["model"].setdefault("init_args", {})
# ----------------- Device & accelerator -----------------
if args.device and args.device != "cpu" and torch.cuda.is_available():
trainer_cfg["accelerator"] = "gpu"
try:
torch.cuda.set_device(int(str(args.device).split(",")[0]))
except Exception:
pass
print(f"[INFO] Using GPU cuda:{args.device}")
else:
trainer_cfg["accelerator"] = "cpu"
trainer_cfg["devices"] = 1
args.device = None
print("[INFO] Using CPU")
trainer_cfg.setdefault("benchmark", True) # cudnn autotune
trainer_cfg.setdefault("precision", "16-mixed") # AMP (fast on GPU)
# ----------------- Trainer settings -----------------
if args.max_epochs:
trainer_cfg["max_epochs"] = args.max_epochs
# Early stopping patience (if config uses callbacks.init_args.patience)
if args.patience is not None:
callbacks = trainer_cfg.get("callbacks")
if isinstance(callbacks, dict) and "init_args" in callbacks:
callbacks["init_args"]["patience"] = args.patience
if args.output_ckpt_folder and args.output_ckpt_folder.lower() != "none":
cfg["default_root_dir"] = args.output_ckpt_folder
# ----------------- Data settings -----------------
data_args["image_size"] = list(args.image_size)
if args.num_workers is not None:
data_args["num_workers"] = int(args.num_workers)
else:
# reasonable default (you can tune)
data_args.setdefault("num_workers", max(2, (os.cpu_count() or 8) // 2))
if args.num_workers is not None:
data_args["num_workers"] = int(args.num_workers)
# ----------------- Transforms (train / eval) -----------------
h, w = list(args.image_size)
train_transform = _build_train_transform(h, w, args)
eval_transform = _build_eval_transform(h, w)
# Always overwrite here (since this entrypoint is explicitly in charge)
data_args["train_transform"] = train_transform
data_args["eval_transform"] = eval_transform
data_args["train_batch_size"] = int(args.batch_size)
data_args["eval_batch_size"] = int(args.batch_size)
scores_path = Path(cfg['default_root_dir']) / "val_scores_for_anomaly.txt"
if scores_path.exists():
scores_path.unlink(missing_ok=True) # py>=3.8
# ----------------- Write back -----------------
with open(cfg_path, "w", encoding="utf-8") as fp:
yaml.dump(cfg, fp)
return cfg
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I want to use center crop for fastflow, but after adding it the performance drop quite a lot.
I not sure is is the way I add transform got issue, can someone help me to check?
Beta Was this translation helpful? Give feedback.
All reactions