Error ①:
Traceback (most recent call last):
File "main.py", line 298, in <module>
main(args, tlogger)
File "main.py", line 228, in main
train_loader, val_loader, model, optimizer, schedule, scaler, amp_context, start_epoch = set_environment(args, tlogger)
ValueError: not enough values to unpack (expected 8, got 7)
This error occurs because the number of returned values from the set_environment() function does not match the number of expected values in the main program. In the main program, the unpacking statement is as follows:
train_loader, val_loader, model, optimizer, schedule, scaler, amp_context, start_epoch = set_environment(args, tlogger)
It expects set_environment() to return 8 values, but when train_loader is None (line 77), only 7 values are returned:
if train_loader is None:
return train_loader, val_loader, model, None, None, None, None
To fix this issue, add start_epoch to the return statement. The modified code is:
if train_loader is None:
return train_loader, val_loader, model, None, None, None, None, start_epoch
Error ②:
Traceback (most recent call last):
File "main.py", line 298, in <module>
main(args, tlogger)
File "main.py", line 254, in main
eval_and_save(args, model, val_loader)
File "/root/miniconda3/envs/PIM/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
TypeError: eval_and_save() missing 1 required positional argument: 'tlogger'
When train_loader is None, which means evaluation mode is used without training, the relevant code in the main program is:
if train_loader is not None:
tlogger.print("Start Training {} Epoch".format(epoch+1))
train(args, epoch, model, scaler, amp_context, optimizer, schedule, train_loader)
tlogger.print()
else:
tlogger.print("Training loader is None, skipping training.")
from eval import eval_and_save
eval_and_save(args, model, val_loader)
break
This error occurs because the call eval_and_save(args, model, val_loader) is missing the required parameter tlogger. Looking at the eval_and_save function in eval.py, it indeed lacks the tlogger parameter. Adding it as a parameter resolves the issue:
@torch.no_grad()
def eval_and_save(args, model, val_loader, tlogger):
tlogger.print("Start Evaluating")
acc, eval_name, eval_acces = evaluate(args, model, val_loader)
tlogger.print("....BEST_ACC: {} {}%".format(eval_name, acc))
### build records.txt
msg = "[Evaluation Results]\n"
msg += "Project: {}, Experiment: {}\n".format(args.project_name, args.exp_name)
msg += "Samples: {}\n".format(len(val_loader.dataset))
msg += "\n"
for name in eval_acces:
msg += " {} {}%\n".format(name, eval_acces[name])
msg += "\n"
msg += "BEST_ACC: {} {}% ".format(eval_name, acc)
with open(args.save_dir + "eval_results.txt", "w") as ftxt:
ftxt.write(msg)
The modified code in the main program becomes:
if train_loader is not None:
tlogger.print("Start Training {} Epoch".format(epoch+1))
train(args, epoch, model, scaler, amp_context, optimizer, schedule, train_loader)
tlogger.print()
else:
tlogger.print("Training loader is None, skipping training.")
from eval import eval_and_save
eval_and_save(args, model, val_loader, tlogger) # Add tlogger as a parameter
break
Error ①:
This error occurs because the number of returned values from the
set_environment()function does not match the number of expected values in the main program. In the main program, the unpacking statement is as follows:It expects
set_environment()to return 8 values, but whentrain_loaderisNone(line 77), only 7 values are returned:To fix this issue, add
start_epochto the return statement. The modified code is:Error ②:
When
train_loaderisNone, which means evaluation mode is used without training, the relevant code in the main program is:This error occurs because the call
eval_and_save(args, model, val_loader)is missing the required parametertlogger. Looking at theeval_and_savefunction ineval.py, it indeed lacks thetloggerparameter. Adding it as a parameter resolves the issue:The modified code in the main program becomes: