bert_chinese_pytorch icon indicating copy to clipboard operation
bert_chinese_pytorch copied to clipboard

如何使用已训练好的output_dir下的model,而不是每次都do_train?

Open lxgend opened this issue 6 years ago • 3 comments

直接把do_train参数取消,提示: Output directory (path) already exists and is not empty.

lxgend avatar Jan 08 '19 01:01 lxgend

用下面这行代码就可以读取模型了(前提是已经定义好model) model.load_state_dict(torch.load(model_save_pth)['state_dict'])

理论上来说,只要用 model = BertForSequenceClassification.from_pretrained(args.bert_model, cache_dir=PYTORCH_PRETRAINED_BERT_CACHE / 'distributed_{}'.format(args.local_rank)) 加载完模型后,跟个load就行

real-brilliant avatar Jan 08 '19 03:01 real-brilliant

用下面这行代码就可以读取模型了(前提是已经定义好model) model.load_state_dict(torch.load(model_save_pth)['state_dict'])

理论上来说,只要用 model = BertForSequenceClassification.from_pretrained(args.bert_model, cache_dir=PYTORCH_PRETRAINED_BERT_CACHE / 'distributed_{}'.format(args.local_rank)) 加载完模型后,跟个load就行

明白了,不局限于给定的cmd参数运行。

lxgend avatar Jan 09 '19 02:01 lxgend

@lxgend 请问你的预测网络是怎么写的哈

ahappycutedog avatar Jul 17 '19 08:07 ahappycutedog