ruotianluo / self-critical.pytorch

Unofficial pytorch implementation for Self-critical Sequence Training for Image Captioning. and others.
MIT License
991 stars 278 forks source link

"TypeError: can only concatenate str (not "float") to str" while training with transformer_nsc #245

Open PineappleWill opened 3 years ago

PineappleWill commented 3 years ago

Hi @ruotianluo , sorry to disturb you, but I got error as the title when I try to train a transformer model using nsc.

My command is python tools/train.py --cfg configs/transformer/transformer_nsc.yml --id transformer_nsc

error I got:

DataLoader loading json file: data/cocotalk.json vocab size is 9487 DataLoader loading h5 file: data/cocotalk_fc data/cocobu_att data/cocotalk_box data/cocotalk_label.h5 max sequence length in data is 16 read 123287 image features assigned 113287 images to split train assigned 5000 images to split val assigned 5000 images to split test Traceback (most recent call last): File "tools/train.py", line 295, in train(opt) File "tools/train.py", line 101, in train optimizer = utils.ReduceLROnPlateau(optimizer, File "/home/ordinary/self-critical.pytorch/captioning/utils/misc.py", line 204, in init self.scheduler = optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode, factor, patience, verbose, threshold, threshold_mode, cooldown, min_lr, eps) File "/home/ordinary/miniconda3/lib/python3.8/site-packages/torch/optim/lr_scheduler.py", line 612, in init self._init_is_better(mode=mode, threshold=threshold, File "/home/ordinary/miniconda3/lib/python3.8/site-packages/torch/optim/lr_scheduler.py", line 681, in _init_is_better raise ValueError('threshold mode ' + threshold_mode + ' is unknown!') TypeError: can only concatenate str (not "float") to str

ruotianluo commented 3 years ago

replace optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode, factor, patience, verbose, threshold, threshold_mode, cooldown, min_lr, eps) with optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode, factor, patience, threshold, threshold_mode, cooldown, min_lr, eps, verbose)

Another thing is I would suggest using transformer_nscl because reduce_on_plateau may not be optimal.

PineappleWill commented 3 years ago

Got it, thanks for your kind response.

replace optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode, factor, patience, verbose, threshold, threshold_mode, cooldown, min_lr, eps) with optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode, factor, patience, threshold, threshold_mode, cooldown, min_lr, eps, verbose)

Another thing is I would suggest using transformer_nscl because reduce_on_plateau may not be optimal.