import argparse import torch import os from models.exaonepath import EXAONEPathV1p5Downstream from utils.constants import CLASS_NAMES from tokens import HF_TOKEN def infer(model, input_file): print("Processing", input_file, "...") probs = model(input_file) result_str = "Result -- " + " / ".join( [f"{name}: {probs[i].item():.4f}" for i, name in enumerate(CLASS_NAMES)] ) print(result_str + "\n") if __name__ == '__main__': parser = argparse.ArgumentParser(description="Inference") parser.add_argument('--svs_dir', type=str, default='./samples', help="") args = parser.parse_args() hf_token = HF_TOKEN model = EXAONEPathV1p5Downstream.from_pretrained("LGAI-EXAONE/EXAONE-Path-1.5", use_auth_token=hf_token) model.load_state_dict(torch.load('./pytorch_model.bin')) model.to(torch.device("cuda" if torch.cuda.is_available() else "cpu")) model.eval() model.feature_extractor = torch.compile(model.feature_extractor) model.agg_model = torch.compile(model.agg_model) for svs_name in os.listdir(args.svs_dir): infer(model, os.path.join(args.svs_dir, svs_name))