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

Asked 2 months ago, Updated 2 months ago, 394 views

What's the difference between the two? You can read one, but you can't read the other.
Code 2 tried to code
Code 1 cuts out the part where the error occurred

Code 1 moves

import 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)
    save_steps: int=100# interval for saving model
    total_steps: int = 100000 # total number of steps to train

    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 "", line 285, in<module>
      File "", line 211, in main
        cfg = train.Config.from_json(args.train_cfg)
      File "C:\Users\PC_User\newAI2022y08y23d\project\ALBERT-Pytorch-master\", 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 09:05

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 09:25

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.