FileNotFoundError in json: What is the difference between these two?

Asked 1 years ago, Updated 1 years ago, 257 views

What's the difference between the two? You can read one, but you can't read the other.
Code 2 tried to code https://github.com/graykode/ALBERT-Pytorch
Code 1 cuts out the part where the error occurred

Code 1 moves

import json

json.load(open('config/pretrain.json'))
print ("aaaa")

Code 2 doesn't work

class Config (NamedTuple):
    """ Hyperparameters for training ""
    seed: int = 3431 # random seed
    batch_size —int=8
    lr —int=5e-5#learning rate
    n_epochs: int=10#the number of epoch
    # `warm up`period=warmup(0.1)*total_steps
    # linear increasing learning rate from zero to the specified value (5e-5)
    warmup:float=0.1
    save_steps: int=100# interval for saving model
    total_steps: int = 100000 # total number of steps to train

    @classmethod
    def from_json(cls, file):# load config from json file
        return cls(**json.load(open(file, "r"))))

Error Content I have verified that the file variable (directory) is the same as code 1

Traceback (most recent call last):
      File "pretrain.py", line 285, in<module>
        main(args=args)
      File "pretrain.py", line 211, in main
        cfg = train.Config.from_json(args.train_cfg)
      File "C:\Users\PC_User\newAI2022y08y23d\project\ALBERT-Pytorch-master\train.py", line 32, in from_json
        return cls(**json.load(open(file, "r"))))
    FileNotFoundError: [Errno2] No such file or directory: "'config/pretrain.json'"

python pytorch

2023-01-11 00:47

1 Answers

FileNotFoundError: [Errno2] No such file or directory: "'config/pretrain.json'"

If the error message is correct, it appears that there is an unnecessary ' around the filename.


2023-01-11 06:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.