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
Hi I am trying to use pyinstaller to convert this into an exe file.
However, I meet some problem in pytorch lightning where inside it got importlib which causes error in the conversion.
Can anyone help me to solve this?
import torch
from pytorch_lightning import Trainer, seed_everything
from anomalib.engine import Engine
import argparse
from anomalib.deploy import ExportType
import os
def train(args):
currpath = os.getcwd()
# Load the configuration
if args.config_path == None:
CONFIG_PATH = currpath + f"\\model\\{args.model}.yaml"
else:
CONFIG_PATH = args.config_path
engine, model, datamodule = Engine.from_config(CONFIG_PATH)
datamodule.category = args.category
# datamodule.trainer.max_epochs = args.max_epochs
if args.model == 'EfficientAD':
datamodule.train_batch_size = 1
else:
datamodule.train_batch_size = args.batch_size
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model.to(device)
engine.fit(model=model, datamodule=datamodule, ckpt_path = None)
path_list = engine.trainer.checkpoint_callback.best_model_path.split('\\')
export_root = "/".join([path_list[6:9][-1], datamodule.category, args.model, path_list[6:9][-2]])
engine.export(
model=model, # The model to be exported
export_type=ExportType.TORCH, # Export the model as ONNX format
export_root=export_root, # The directory where the model will be saved
datamodule=datamodule, # Data module (used to pass data-related information during export)
ckpt_path=engine.trainer.checkpoint_callback.best_model_path, # Path to the model checkpoint
)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Anomaly", add_help=True)
parser.add_argument("--model", default="patchcore", help="model")
parser.add_argument("--category", type=str, default="led", help="category")
parser.add_argument("--batch_size", type=int, required=True, default=1, help="batch size")
# parser.add_argument("--max_epochs", type=int, required=True, default=10, help="max_epochs")
parser.add_argument("--config_path", type=str, help="CONFIG_PATH")
args = parser.parse_args()
train(args)
The error from pytorch_lightning import Trainer, seed_everything File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module File "pytorch_lightning\__init__.py", line 25, in <module> File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module File "lightning_fabric\__init__.py", line 13, in <module> File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module File "lightning_fabric\__version__.py", line 8, in <module> FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\AppData\\Local\\Temp\\_MEI95922\\lightning_fabric\\version.info' [PYI-19980:ERROR] Failed to execute script 'training' due to unhandled exception!
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
-
Hi I am trying to use pyinstaller to convert this into an exe file.
However, I meet some problem in pytorch lightning where inside it got importlib which causes error in the conversion.
Can anyone help me to solve this?
The error
from pytorch_lightning import Trainer, seed_everything File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module File "pytorch_lightning\__init__.py", line 25, in <module> File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module File "lightning_fabric\__init__.py", line 13, in <module> File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module File "lightning_fabric\__version__.py", line 8, in <module> FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\AppData\\Local\\Temp\\_MEI95922\\lightning_fabric\\version.info' [PYI-19980:ERROR] Failed to execute script 'training' due to unhandled exception!
Beta Was this translation helpful? Give feedback.
All reactions