'checkpoint' object has no attribute 'dir'

Why did this error occur considering that the directory path was already provided?

Traceback (most recent call last):
File “main.py”, line 12, in
checkpoint = utility.checkpoint(args)
File “F:\DASR-main\utility.py”, line 71, in init
_make_dir(self.dir)
AttributeError: ‘checkpoint’ object has no attribute ‘dir’

class checkpoint():
    def __init__(self, args):
        self.args = args
        self.ok = True
        self.log = torch.Tensor()
        now = datetime.datetime.now().strftime('%Y-%m-%d-%H:%M:%S')

        if args.blur_type == 'iso_gaussian':
            self.dir = './experiment/' + args.save + '_x' + str(int(args.scale[0])) + '_' + args.mode + '_iso'
        elif args.blur_type == 'aniso_gaussian':
            self.dir = './experiment/' + args.save + '_x' + str(int(args.scale[0])) + '_' + args.mode + '_aniso'

        def _make_dir(path):
            if not os.path.exists(path): os.makedirs(path)

        _make_dir(self.dir)
        _make_dir(self.dir + '/model')
        _make_dir(self.dir + '/results')

It looks like args.blur_type is neither "iso_gaussian" nor "aniso_gaussian", so self.dir is not defined when the program reaches _make_dir(self.dir).

The blur type is already provided in the command:
python main.py --dir_data='F:/DASR-main/dataset' --model='blindsr' --scale='2' --**blur_type='iso_gaussian**' --noise=0.0 --sig_min=0.2 --sig_max=4.0

Before if args.blur_type == 'iso_gaussian':, could you print args.blur_type? (It could be good to check that the args are correctly being parsed and passed through to the checkpoint() object.)

Otherwise, I am not sure based on your provided code snippet why self.dir would not be defined as an attribute :confused:

1 Like