irfanICMLL / structure_knowledge_distillation

The official code for the paper 'Structured Knowledge Distillation for Semantic Segmentation'. (CVPR 2019 ORAL) and extension to other tasks.
BSD 2-Clause "Simplified" License
708 stars 103 forks source link

TypeError: add_() received an invalid combination of arguments #23

Closed w11m closed 4 years ago

w11m commented 4 years ago

I got the error message when finished one epoch training anyone knows why this happened?

Traceback (most recent call last):
  File "/structure_knowledge_distillation-master/train_and_eval.py", line 28, in <module>
    model.optimize_parameters()
  File "/structure_knowledge_distillation-master/networks/kd_model.py", line 171, in optimize_parameters
    self.G_solver.step()
  File "/usr/local/lib/python3.5/dist-packages/torch/optim/sgd.py", line 107, in step
    p.data.add_(-group['lr'], d_p)
TypeError: add_() received an invalid combination of arguments - got (complex, Tensor), but expected one of:
 * (Tensor other, Number alpha)
      didn't match because some of the arguments have invalid types: (!complex!, !Tensor!)
 * (Number other, Number alpha)
      didn't match because some of the arguments have invalid types: (!complex!, !Tensor!)

My ArgumentPaerser setting is below

parser = argparse.ArgumentParser(description='knowledge-distillation')
        parser.add_argument('--data_set', default='cityscape',type=str, metavar='', help='')
        parser.add_argument('--classes_num', default=19, type=int,metavar='N', help='class num of the dataset')
        parser.add_argument('--T_ckpt_path', default='./ckpt/Teacher_city.pth',type=str, metavar='teacher ckpt path', help='teacher ckpt path')
        parser.add_argument('--S_resume', default='True', type=str2bool, metavar='is or not use student', help='is or not use student ckpt')
        parser.add_argument('--S_ckpt_path', default='./dataset/resnet18-imagenet.pth',type=str, metavar='student ckpt path', help='student ckpt path')
        parser.add_argument('--D_resume', default=True, type=bool,metavar='is or not use discriminator', help='is or not use discriminator ckpt')
        parser.add_argument('--D_ckpt_path', default='',type=str, metavar='discriminator ckpt path', help='discriminator ckpt path')
        parser.add_argument("--batch-size", type=int, default=2, help="Number of images sent to the network in one step.")
        parser.add_argument('--start_epoch', default=0, type=int,metavar='start_epoch', help='start_epoch')
        parser.add_argument('--epoch_nums', default=2, type=int,metavar='epoch_nums', help='epoch_nums')
        parser.add_argument('--parallel', default='Flase', type=str, metavar='parallel', help='attribute of saved name')
        parser.add_argument("--data-dir", default='',type=str,  help="Path to the directory containing the PASCAL VOC dataset.")
        parser.add_argument("--data-list", type=str, default='./dataset/list/cityscapes/train.lst', help="Path to the file listing the images in the dataset.")
        parser.add_argument("--ignore-label", type=int, default=255, help="The index of the label to ignore during the training.")
        parser.add_argument("--input-size", type=str, default='512,512', help="Comma-separated string with height and width of images.")
        parser.add_argument("--is-training", action="store_true", help="Whether to updates the running means and variances during the training.")
        parser.add_argument("--momentum", type=float, default=0.9, help="Momentum component of the optimiser.")
        parser.add_argument("--num-steps", type=int, default=2, help="Number of training steps.")
        parser.add_argument("--power", type=float, default=0.9, help="Decay parameter to compute the learning rate.")
        parser.add_argument("--random-mirror", default='Flase',action="store_true", help="Whether to randomly mirror the inputs during the training.")
        parser.add_argument("--random-scale", default='Flase',action="store_true", help="Whether to randomly scale the inputs during the training.")
        parser.add_argument("--snapshot-dir", type=str, default='./snapshots/', help="Where to save snapshots of the model.")
        parser.add_argument("--weight-decay", type=float, default=5e-4, help="Regularisation parameter for L2-loss.")
        parser.add_argument("--gpu", type=str, default='0', help="choose gpu device.")
        parser.add_argument("--recurrence", type=int, default=1, help="choose the number of recurrence.")

        parser.add_argument("--last-step", type=int, default=0, help="last train step.")
        parser.add_argument("--is-student-load-imgnet", type=str2bool, default='True', help="is student load imgnet")
        parser.add_argument("--student-pretrain-model-imgnet",default='./dataset/resnet18-imagenet.pth', type=str, help="student pretrain model on imgnet")
        parser.add_argument("--pi", type=str2bool, default='True', help="is pixel wise loss using or not")
        parser.add_argument("--pa", type=str2bool, default='True', help="is pixel wise loss using or not")
        parser.add_argument("--ho", type=str2bool, default='False', help="is pixel wise loss using or not")
        parser.add_argument("--adv-loss-type", type=str, default='wgan-gp', help="adversarial loss setting")
        parser.add_argument("--imsize-for-adv", type=int, default=65, help="imsize for addv")
        parser.add_argument("--adv-conv-dim", type=int, default=64, help="conv dim in adv")
        parser.add_argument("--lambda-gp", type=float, default=10.0, help="lambda_gp")
        parser.add_argument("--lambda-d", type=float, default=0.1, help="lambda_d")
        parser.add_argument("--lambda-pi", type=float, default=10.0, help="lambda_pi")
        parser.add_argument('--lambda-pa', default=0.5, type=float, help='')
        parser.add_argument('--pool-scale', default=0.5, type=float, help='')
        parser.add_argument("--preprocess-GAN-mode", type=int, default=1, help="preprocess-GAN-mode should be tanh or bn")
        parser.add_argument("--lr-g", type=float, default=1e-2, help="learning rate for G")
        parser.add_argument("--lr-d", type=float, default=4e-4, help="learning rate for D")
        parser.add_argument("--best-mean-IU", type=float, default=0.0, help="learning rate for D")
w11m commented 4 years ago

i original set the num-setps 40000 and get the CS_scenes_39999_0.23502119687431486.pth then error happened

irfanICMLL commented 4 years ago

Please checkout this branch: d1ec858