Soft link pathlib generated files

  • In depth training network, save the model, you want to maintain a file latest.t7, think the best model to create a soft link to latest.t7
  • This model is not an area, but also easy to follow script to load the best model

  • Initially see mmdetection is done so, find it a bit corresponding source code as follows:
def symlink(src, dst, overwrite=True, **kwargs):
    if os.path.lexists(dst) and overwrite:
        os.remove(dst)
    os.symlink(src, dst, **kwargs)
  • This method can indeed use, but use the os library, I want to use pathlib redrafting, in fact pathlib in just a few os's library package, or the nature of the call
  • Simply write a function as follows:
def symlink(src_path: Path, dst_path: Path):
    if not isinstance(src_path, Path):
        src_path = Path(src_path)

    if not isinstance(dst_path, Path):
        dst_path = Path(dst_path)

    if dst_path.is_symlink():
        dst_path.unlink()

    dst_path.symlink_to(src_path)

Guess you like

Origin www.cnblogs.com/shiwanghualuo/p/11846986.html