Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fine-tuning in training #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tools/train_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,34 @@ def main(args):
"--image_path_val",
help="The path to the validation set image folder",
)
parser.add_argument("--lp_model", default="", help="The name of the layoutparser model")

args = parser.parse_args()
print("Command Line Args:", args)

if args.lp_model is not None:

try:
from layoutparser.models.detectron2.catalog import PathManager
except ImportError:
print("Please install the latest version of layoutparser to use LP Model weights for fine-tuning.")
print("\t pip install layoutparser")
exit()

assert args.lp_model.startswith("lp://"), "Please use Detectron2 models from https://layout-parser.github.io/platform/"

model_path = PathManager.get_local_path(args.lp_model.rstrip("/weight") + "/weight")
config_path = PathManager.get_local_path(args.lp_model.rstrip("/config") + "/config")

if "MODEL.WEIGHTS" in args.opts:
idx = args.opts.index("MODEL.WEIGHTS")
args.opts[idx+1] = model_path
else:
args.opts.extend(["MODEL.WEIGHTS", model_path])

args.config_file = config_path


# Dataset Registration is moved to the main function to support multi-gpu training
# See ref https://github.com/facebookresearch/detectron2/issues/253#issuecomment-554216517

Expand Down