FileNotFoundError:没有这样的文件或目录。 '= / models / test'

时间:2020-06-25 11:56:11

标签: python pytorch

我遇到以下错误,我完全不知道出什么问题了。

带有p(dir_path)的完整路径应如下所示:/home/user/ulmfit4pl/plhater/models/test,而错误显示No such file or directory: '=/models/test'似乎dir_path在这种情况下不起作用。

完整追溯:

Loading /home/user/ulmfit4pl/plhater/models/fwd_nl-4-v1_best_clas_1.h5
Converting mutli classification in to binary classificaiton
Traceback (most recent call last):
  File "/home/user/ulmfit4pl/ulmfit/evaluate.py", line 129, in <module>
    if __name__ == '__main__': fire.Fire(evaluate)
  File "/opt/conda/envs/ulmfit4pl/lib/python3.6/site-packages/fire/core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/opt/conda/envs/ulmfit4pl/lib/python3.6/site-packages/fire/core.py", line 468, in _Fire
    target=component.__name__)
  File "/opt/conda/envs/ulmfit4pl/lib/python3.6/site-packages/fire/core.py", line 672, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/user/ulmfit4pl/ulmfit/evaluate.py", line 124, in evaluate
    (p / "models" / test_file ).mkdir(exist_ok=True)
  File "/opt/conda/envs/ulmfit4pl/lib/python3.6/pathlib.py", line 1248, in mkdir
    self._accessor.mkdir(self, mode)
  File "/opt/conda/envs/ulmfit4pl/lib/python3.6/pathlib.py", line 387, in wrapped
    return strfunc(str(pathobj), *args)
FileNotFoundError: [Errno 2] No such file or directory: '=/models/test'

此函数中出现问题:

def evaluate(dir_path, clas_id, test_file='test1', cuda_id=0, nl=4, classes=3, bs=120, squeeze_bin=False, backwards=False, dump_preds=None, labels=False):
    if not hasattr(torch._C, '_cuda_setDevice'):
        print('CUDA not available. Setting device=-1.')
        cuda_id = -1
    torch.cuda.set_device(cuda_id)

    p = Path(dir_path)
    spp = sp.SentencePieceProcessor()
    spp.Load('/home/user/ulmfit4pl/plhater/tmp/sp.model')
    vs = spp.GetPieceSize()  # len(itos)
    spp.SetEncodeExtraOptions("bos:eos")


    # In[14]:
    dps = np.array([0.4,0.5,0.05,0.3,0.4])
    bptt,em_sz,nh,nl = 70,400,1150,nl
    c=classes
    m = get_rnn_classifer(bptt, 20*70, c, vs, emb_sz=em_sz, n_hid=nh, n_layers=nl, pad_token=1,
              layers=[em_sz*3, 50, c], drops=[dps[4], 0.1],
              dropouti=dps[0], wdrop=dps[1], dropoute=dps[2], dropouth=dps[3])
    model_path = "/home/user/ulmfit4pl/plhater/models/fwd_nl-4-v1_best_clas_1.h5"
    load_model(m, model_path)
    print("Loading", model_path)
    m = to_gpu(m)
    direction="bwd" if backwards else "fwd"
    preds, metrics = evaluate_model(test_file, m, p/"tmp", spp, bs, squeeze_bin, backwards, labels)
    if dump_preds is not None:
        with open(dump_preds, 'w') as f:
            f.write('\n'.join([str(int(x>=0)) for x in preds[:, 1]]))
    (p / "models" / test_file ).mkdir(exist_ok=True)
    np.save(p/"models"/ test_file/ f"{direction}_{clas_id}_clas_1-results.npy", preds)

    with open(p / "models" / test_file / f"{direction}_{clas_id}_clas_1-results.json", 'w') as fp:
        json.dump(metrics, fp)
if __name__ == '__main__': fire.Fire(evaluate)

目录路径:

p = Path(dir_path)

dir_path = /home/user/ulmfit4pl/plhater

0 个答案:

没有答案