Project-MONAI / tutorials

MONAI Tutorials
https://monai.io/started.html
Apache License 2.0
1.85k stars 682 forks source link

FileNotFoundError in "acceleration/TensorRT_inference_acceleration.ipynb" #1667

Closed KumoLiu closed 7 months ago

KumoLiu commented 7 months ago
2024-03-16 04:11:18,952 - INFO - Setting logging properties based on config: ./endoscopic_tool_segmentation/configs/logging.conf.

monai.bundle.workflows ConfigWorkflow.__init__:workflow: Argument `workflow` has been deprecated since version 1.2. It will be removed in version 1.5. please use `workflow_type` instead.

Ending Cell 16-----------------------------------------
Traceback (most recent call last):
  File "/usr/local/bin/papermill", line 8, in <module>
    sys.exit(papermill())
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/papermill/cli.py", line 254, in papermill
    execute_notebook(
  File "/usr/local/lib/python3.10/dist-packages/papermill/execute.py", line 134, in execute_notebook
    raise_for_execution_errors(nb, output_path)
  File "/usr/local/lib/python3.10/dist-packages/papermill/execute.py", line 241, in raise_for_execution_errors
    raise error
papermill.exceptions.PapermillExecutionError: 
---------------------------------------------------------------------------
Exception encountered at "In [7]":
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
File /usr/local/lib/python3.10/dist-packages/monai/bundle/config_item.py:377, in ConfigExpression.evaluate(self, globals, locals)
    376 try:
--> 377     return eval(value[len(self.prefix) :], globals_, locals)
    378 except Exception as e:
File <string>:1
File /usr/local/lib/python3.10/dist-packages/monai/handlers/checkpoint_loader.py:126, in CheckpointLoader.__call__(self, engine)
    122 '
    123 Args:
    124     engine: Ignite Engine, it can be a trainer, validator or evaluator.
    125 '
--> 126 checkpoint = torch.load(self.load_path, map_location=self.map_location)
    128 k, _ = list(self.load_dict.items())[0]

File /usr/local/lib/python3.10/dist-packages/torch/serialization.py:997, in load(f, map_location, pickle_module, weights_only, mmap, **pickle_load_args)
    995     pickle_load_args['encoding'] = 'utf-8'
--> 997 with _open_file_like(f, 'rb') as opened_file:
    998     if _is_zipfile(opened_file):
    999         # The zipfile reader is going to advance the current file position.
   1000         # If we want to actually tail call to torch.jit.load, we need to
   1001         # reset back to the original position.

File /usr/local/lib/python3.10/dist-packages/torch/serialization.py:444, in _open_file_like(name_or_buffer, mode)
    443 if _is_path(name_or_buffer):
--> 444     return _open_file(name_or_buffer, mode)
    445 else:

File /usr/local/lib/python3.10/dist-packages/torch/serialization.py:425, in _open_file.__init__(self, name, mode)
    424 def __init__(self, name, mode):
--> 425     super().__init__(open(name, mode))

FileNotFoundError: [Errno 2] No such file or directory: './models/model.pt'

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
Cell In[7], line 14
      5 trt_fp16_model_path = os.path.join(bundle_path, "models", "model_trt_fp16.ts")
      7 workflow = monai.bundle.ConfigWorkflow(
      8     workflow="infer",
      9     config_file=inference_config,
     10     meta_file=meta_config,
     11     logging_file=os.path.join(bundle_path, "configs", "logging.conf"),
     12 )
---> 14 workflow.initialize()
     15 device = workflow.device
     16 spatial_shape = (1, 3, 736, 480)

File /usr/local/lib/python3.10/dist-packages/monai/bundle/workflows.py:296, in ConfigWorkflow.initialize(self)
    294 self.parser.parse(reset=True)
    295 self._is_initialized = True
--> 296 return self._run_expr(id=self.init_id)

File /usr/local/lib/python3.10/dist-packages/monai/bundle/workflows.py:344, in ConfigWorkflow._run_expr(self, id, **kwargs)
    343 def _run_expr(self, id: str, **kwargs: dict) -> Any:
--> 344     return self.parser.get_parsed_content(id, **kwargs) if id in self.parser else None

File /usr/local/lib/python3.10/dist-packages/monai/bundle/config_parser.py:290, in ConfigParser.get_parsed_content(self, id, **kwargs)
    288 elif not kwargs.get("lazy", True):
    289     self.parse(reset=not kwargs.get("lazy", True))
--> 290 return self.ref_resolver.get_resolved_content(id=id, **kwargs)

File /usr/local/lib/python3.10/dist-packages/monai/bundle/reference_resolver.py:193, in ReferenceResolver.get_resolved_content(self, id, **kwargs)
    181 def get_resolved_content(self, id: str, **kwargs: Any) -> ConfigExpression | str | Any | None:
    182     '
    183     Get the resolved ``ConfigItem`` by id.
    184 
   (...)
    191 
    192     '
--> 193     return self._resolve_one_item(id=id, **kwargs)

File /usr/local/lib/python3.10/dist-packages/monai/bundle/reference_resolver.py:163, in ReferenceResolver._resolve_one_item(self, id, waiting_list, **kwargs)
    161             continue
    162         # recursively resolve the reference first
--> 163         self._resolve_one_item(id=d, waiting_list=waiting_list, **kwargs)
    164         waiting_list.discard(d)
    166 # all references are resolved, then try to resolve current config item

File /usr/local/lib/python3.10/dist-packages/monai/bundle/reference_resolver.py:175, in ReferenceResolver._resolve_one_item(self, id, waiting_list, **kwargs)
    172 elif isinstance(item, ConfigExpression):
    173     run_eval = kwargs.get("eval_expr", True)
    174     self.resolved_content[id] = (
--> 175         item.evaluate(globals={f"{self._vars}": self.resolved_content}) if run_eval else item
    176     )
    177 else:
    178     self.resolved_content[id] = new_config

File /usr/local/lib/python3.10/dist-packages/monai/bundle/config_item.py:379, in ConfigExpression.evaluate(self, globals, locals)
    377         return eval(value[len(self.prefix) :], globals_, locals)
    378     except Exception as e:
--> 379         raise RuntimeError(f"Failed to evaluate {self}") from e
    380 warnings.warn(
    381     f"

pdb: value={value}
"
    382     f"See also Debugger commands documentation: https://docs.python.org/3/library/pdb.html
"
    383 )
    384 import pdb

RuntimeError: Failed to evaluate ConfigExpression: